[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250915-bulky-visionary-hamster-3a6c10@penduick>
Date: Mon, 15 Sep 2025 14:21:04 +0200
From: Maxime Ripard <mripard@...nel.org>
To: Luca Ceresoli <luca.ceresoli@...tlin.com>
Cc: Andrzej Hajda <andrzej.hajda@...el.com>,
Neil Armstrong <neil.armstrong@...aro.org>, Robert Foss <rfoss@...nel.org>,
Laurent Pinchart <Laurent.pinchart@...asonboard.com>, Jonas Karlman <jonas@...boo.se>,
Jernej Skrabec <jernej.skrabec@...il.com>, Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Thomas Zimmermann <tzimmermann@...e.de>, David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>, Miguel Ojeda <ojeda@...nel.org>,
Nathan Chancellor <nathan@...nel.org>, Nick Desaulniers <nick.desaulniers+lkml@...il.com>,
Bill Wendling <morbo@...gle.com>, Justin Stitt <justinstitt@...gle.com>,
Tomi Valkeinen <tomi.valkeinen@...asonboard.com>, Dmitry Baryshkov <dmitry.baryshkov@....qualcomm.com>,
Chaoyi Chen <chaoyi.chen@...k-chips.com>, Hui Pu <Hui.Pu@...ealthcare.com>,
Thomas Petazzoni <thomas.petazzoni@...tlin.com>, dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
llvm@...ts.linux.dev
Subject: Re: [PATCH v2 3/9] drm/bridge: add
drm_for_each_bridge_in_chain_scoped()
On Tue, Aug 19, 2025 at 06:01:37PM +0200, Luca Ceresoli wrote:
> Hi Maxime,
>
> On Tue, 19 Aug 2025 15:47:06 +0200
> Maxime Ripard <mripard@...nel.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.
>
> I tested this macro in both cases:
>
> * looping over the entire chain the final value of @bridge will be
> NULL and the cleanup action won't call drm_bridge_put()
> * breaking before the last element, @bridge is non-NULL and the
> cleanup action does call drm_bridge_put()
>
> See examples such as for_each_child_of_node_scoped() and other OF
> iterators which work in the same way (which is no coincidence, I used
> them as starting point for writing this patch).
Ack,
Reviewed-by: Maxime Ripard <mripard@...nel.org>
Maxime
Download attachment "signature.asc" of type "application/pgp-signature" (274 bytes)
Powered by blists - more mailing lists