Understanding time complexity of a while loop that will look over all vertices and edges
Because each edge contributes to two degrees, we have
$$\sum_v\mathrm{deg}(v)=2m.$$

The time taken by the whole loop is $O(m)$.

Your analysis is of course correct, but since you replace $\mathrm{deg}(v)$ with the upper bound $m$, you get a loose bound finally.

By the way this is BFS if you ignore the "color" action.