Hi Maxime,

On Tue, 19 Aug 2025 18:01:37 +0200
Luca Ceresoli <luca.ceres...@bootlin.com> wrote:

> Hi Maxime,
> 
> On Tue, 19 Aug 2025 15:47:06 +0200
> Maxime Ripard <mrip...@kernel.org> wrote:
> 
> > > +/**
> > > + * drm_for_each_bridge_in_chain_scoped - iterate over all bridges 
> > > attached
> > > + *                                       to an encoder
> > > + * @encoder: the encoder to iterate bridges on
> > > + * @bridge: a bridge pointer updated to point to the current bridge at 
> > > each
> > > + *           iteration
> > > + *
> > > + * Iterate over all bridges present in the bridge chain attached to 
> > > @encoder.
> > > + *
> > > + * Automatically gets/puts the bridge reference while iterating, and puts
> > > + * the reference even if returning or breaking in the middle of the loop.
> > > + */
> > > +#define drm_for_each_bridge_in_chain_scoped(encoder, bridge)             
> > > \
> > > + for (struct drm_bridge *bridge __free(drm_bridge_put) =         \
> > > +      drm_bridge_chain_get_first_bridge(encoder);                \    
> > 
> > So my understanding is that the initial value of bridge would be cleaned
> > up with drm_bridge_put...
> >   
> > > +      bridge;                                                    \
> > > +      bridge = drm_bridge_get_next_bridge_and_put(bridge))    
> > 
> > ... but also when iterating?
> > 
> > So if we have more than 0 values, we put two references?  
> 
> No, this is not the case. The __free action is executed only when
> exiting the entire for loop, not a single iteration.
> 
> This is consistent with the fact that the loop variable is persistent
> across iterations.

PS: here's the C language spec reference:

> 6.8.5.3 The for statement
> The statement
> for ( clause-1 ; expression-2 ; expression-3 ) statement
> behaves as follows:
> [...]
> If clause-1 is a declaration, the scope of any identifiers it declares
> is the remainder of the declaration and the entire loop 

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
https://rgambord.github.io/c99-doc/sections/6/8/5/3/index.html

Best regards,
Luca

-- 
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Reply via email to