[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DECQREI2GFCG.27I1BBCKPJMFG@bootlin.com>
Date: Wed, 19 Nov 2025 15:29:43 +0100
From: "Luca Ceresoli" <luca.ceresoli@...tlin.com>
To: "Louis Chauvet" <louis.chauvet@...tlin.com>, "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>, "Maxime Ripard" <mripard@...nel.org>,
"Thomas Zimmermann" <tzimmermann@...e.de>, "David Airlie"
<airlied@...il.com>, "Simona Vetter" <simona@...ll.ch>, "Jonathan Corbet"
<corbet@....net>, "Alexey Brodkin" <abrodkin@...opsys.com>, "Phong LE"
<ple@...libre.com>, "Liu Ying" <victor.liu@....com>, "Shawn Guo"
<shawnguo@...nel.org>, "Sascha Hauer" <s.hauer@...gutronix.de>,
"Pengutronix Kernel Team" <kernel@...gutronix.de>, "Fabio Estevam"
<festevam@...il.com>, "Adrien Grassein" <adrien.grassein@...il.com>,
"Laurent Pinchart" <laurent.pinchart+renesas@...asonboard.com>, "Tomi
Valkeinen" <tomi.valkeinen+renesas@...asonboard.com>, "Kieran Bingham"
<kieran.bingham+renesas@...asonboard.com>, "Geert Uytterhoeven"
<geert+renesas@...der.be>, "Magnus Damm" <magnus.damm@...il.com>, "Kevin
Hilman" <khilman@...libre.com>, "Jerome Brunet" <jbrunet@...libre.com>,
"Martin Blumenstingl" <martin.blumenstingl@...glemail.com>, "Chun-Kuang Hu"
<chunkuang.hu@...nel.org>, "Philipp Zabel" <p.zabel@...gutronix.de>,
"Matthias Brugger" <matthias.bgg@...il.com>, "AngeloGioacchino Del Regno"
<angelogioacchino.delregno@...labora.com>, "Anitha Chrisanthus"
<anitha.chrisanthus@...el.com>, "Edmund Dea" <edmund.j.dea@...el.com>,
"Inki Dae" <inki.dae@...sung.com>, "Seung-Woo Kim"
<sw0312.kim@...sung.com>, "Kyungmin Park" <kyungmin.park@...sung.com>,
"Krzysztof Kozlowski" <krzk@...nel.org>, "Alim Akhtar"
<alim.akhtar@...sung.com>
Cc: "Hui Pu" <Hui.Pu@...ealthcare.com>, "Thomas Petazzoni"
<thomas.petazzoni@...tlin.com>, <dri-devel@...ts.freedesktop.org>,
<linux-kernel@...r.kernel.org>, <linux-doc@...r.kernel.org>,
<imx@...ts.linux.dev>, <linux-arm-kernel@...ts.infradead.org>,
<linux-renesas-soc@...r.kernel.org>, <linux-amlogic@...ts.infradead.org>,
<linux-mediatek@...ts.infradead.org>, <linux-samsung-soc@...r.kernel.org>
Subject: Re: [PATCH 01/26] drm/bridge: add drm_of_find_bridge()
Hi Louis,
On Wed Nov 19, 2025 at 3:22 PM CET, Louis Chauvet wrote:
>
>
> On 11/19/25 13:05, Luca Ceresoli wrote:
>> of_drm_find_bridge() does not increment the refcount for the returned
>> bridge, but that is required now. However converting it and all its users
>> is not realistically doable at once given the large amount of (direct and
>> indirect) callers and the complexity of some. Also, "of_drm_find_bridge is
>> oddly named according to our convention and it would make more sense to be
>> called drm_of_find_bridge()" (quoted from Link: below).
>>
>> Solve both issues by creating a new drm_of_find_bridge() that is identical
>> to of_drm_find_bridge() except it takes a reference. Then
>> of_drm_find_bridge() will be deprecated to be eventually removed.
>>
>> Suggested-by: Maxime Ripard <mripard@...nel.org>
>> Link: https://lore.kernel.org/dri-devel/20250319-stylish-lime-mongoose-0a18ad@houat/
>> Signed-off-by: Luca Ceresoli <luca.ceresoli@...tlin.com>
...
>> +struct drm_bridge *drm_of_find_bridge(struct device_node *np)
>> +{
>> + struct drm_bridge *bridge;
>> +
>> + mutex_lock(&bridge_lock);
>> +
>> + list_for_each_entry(bridge, &bridge_list, list) {
>> + if (bridge->of_node == np) {
>> + mutex_unlock(&bridge_lock);
>
> It seems a bit strange to unlock the mutex just before the
> drm_bridge_get, is it expected?
Ouch. No, it's not expected, it is a very silly mistake. Thanks for
noticing.
> If no, I think you can use scoped_guard(mutex, &bridge_lock) to avoid
> messing with mutex_unlock, IIRC, scoped_guard will unlock the mutex just
> after the return, so in your case, just after the drm_bridge_get.
>
>> + return drm_bridge_get(bridge);
>> + }
>> + }
My intent was to keep the function as similar as possible to the original
one, thus I just added a drm_bridge_get(), but that is of course wrong.
So these lines should instead have been:
if (bridge->of_node == np) {
drm_bridge_get(bridge);
mutex_unlock(&bridge_lock);
return bridge;
}
But indeed scoped_guard() is much cleaner and less error-prone, so I'm
probably going to use it in v2.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Powered by blists - more mailing lists