Re: [RFC PATCH 03/13] usb: remove the usage of the list iterator after the loop

From: Greg Kroah-Hartman
Date: Thu Feb 24 2022 - 06:26:14 EST


On Thu, Feb 24, 2022 at 11:46:40AM +0100, Cristiano Giuffrida wrote:
> I think the "problem" with this solution is that it doesn't prevent
> `tmp` from being used outside the loop still (and people getting it
> wrong again)? It would be good to have 'struct gr_request *tmp;' being
> visible only inside the loop (i.e., declared in the macro).

That is a larger change, one that we can hopefully make when changing to
introduce the temp variable in the loop_for_each() macro as Linus
described elsewhere in the thread.

But for now, it should be pretty obvious to not touch tmp again after
the loop is done. That should make it easier to check for stuff like
this as well in an automated fashion (i.e. the loop variable is only
touched inside the loop.)

thanks,

greg k-h