lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <DECXKE9A67HG.35AR5UZKKQ8A1@bootlin.com>
Date: Wed, 19 Nov 2025 20:49:42 +0100
From: "Luca Ceresoli" <luca.ceresoli@...tlin.com>
To: "Chaoyi Chen" <chaoyi.chen@...k-chips.com>, "Chaoyi Chen"
 <kernel@...kyi.com>, "Heikki Krogerus" <heikki.krogerus@...ux.intel.com>,
 "Greg Kroah-Hartman" <gregkh@...uxfoundation.org>, "Dmitry Baryshkov"
 <dmitry.baryshkov@....qualcomm.com>, "Peter Chen" <hzpeterchen@...il.com>,
 "Rob Herring" <robh@...nel.org>, "Krzysztof Kozlowski"
 <krzk+dt@...nel.org>, "Conor Dooley" <conor+dt@...nel.org>, "Vinod Koul"
 <vkoul@...nel.org>, "Kishon Vijay Abraham I" <kishon@...nel.org>, "Heiko
 Stuebner" <heiko@...ech.de>, "Sandy Huang" <hjc@...k-chips.com>, "Andy Yan"
 <andy.yan@...k-chips.com>, "Yubing Zhang" <yubing.zhang@...k-chips.com>,
 "Frank Wang" <frank.wang@...k-chips.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>, "Amit Sunil Dhamne"
 <amitsd@...gle.com>, "Dragan Simic" <dsimic@...jaro.org>, "Johan Jonker"
 <jbx6244@...il.com>, "Diederik de Haas" <didi.debian@...ow.org>, "Peter
 Robinson" <pbrobinson@...il.com>
Cc: <linux-usb@...r.kernel.org>, <devicetree@...r.kernel.org>,
 <linux-kernel@...r.kernel.org>, <linux-phy@...ts.infradead.org>,
 <linux-arm-kernel@...ts.infradead.org>,
 <linux-rockchip@...ts.infradead.org>, <dri-devel@...ts.freedesktop.org>
Subject: Re: [PATCH v9 08/10] drm/rockchip: cdn-dp: Add multiple bridges to
 support PHY port selection

Hello Chaoyi,

On Mon Nov 17, 2025 at 2:33 AM CET, Chaoyi Chen wrote:
...
>>>> +    /* One endpoint may correspond to one next bridge. */
>>>> +    for_each_of_graph_port_endpoint(port, dp_ep) {
>>>> +        struct device_node *next_bridge_node __free(device_node) =
>>>> +            of_graph_get_remote_port_parent(dp_ep);
>>>> +
>>>> +        bridge = of_drm_find_bridge(next_bridge_node);
>>>> +        if (!bridge) {
>>>> +            ret = -EPROBE_DEFER;
>>>> +            goto out;
>>>> +        }
>>>> +
>>>> +        dp->next_bridge_valid = true;
>>>> +        dp->next_bridge_list[count].bridge = bridge;
>>> You are storing a reference to a drm_bridge, so have to increment the
>>> refcount:
>>>
>>>         dp->next_bridge_list[count].bridge = drm_bridge_get(bridge);
>>>                                              ^^^^^^^^^^^^^^
>>>
>>> FYI there is a plan to replace of_drm_find_bridge() with a function that
>>> increases the bridge refcount before returning the bridge, but it's not
>>> there yet. When that will happen, the explicit drm_bridge_get() won't be
>>> needed anymore and this code can be updated accordingly.
>
> Out of curiosity, I checked the callers of of_drm_find_bridge(), and it
> seems that the vast majority of them do not pay attention to the increase
> or decrease of reference counts.

They do not call drm_bridge_put() to decrease the refcount, and that's
"correct" because of_drm_find_bridge() does not increase it. This was
totally correct in the past because DRM bridge refcounting did not exist.

Refcounting has been added to support hot-pluggable bridges. If you want
more info, this presentation I gave at ELCE 2025 is a good summary, with
links to relevant patches:

 * Video (start at 19:30): https://www.youtube.com/watch?v=msmBQBSyZZ4
 * Slides (start at slide 27):
   https://bootlin.com/pub/conferences/2025/elce/ceresoli-hotplug-status.pdf

> Does this mean that even if we add reference counting in
> of_drm_find_bridge(), we still need to modify the corresponding functions
> of their callers and decrease the reference count at the appropriate
> time?

Exactly. I have explored that approach but it turned out being not
reasonably doable due to the large number of (direct + indirect) callers of
of_drm_find_bridge() as well as the trickiness of those involvingthe
panel_bridge. So Maxime proposed a different approach [0]: deprecate
of_drm_find_bridge() and replace it with a function that increments the
refcount, then let the various callers move to the new function over time.

Earlier today I sent a series doing that, and converting lots of users
[1]. If/when that approach will be accepted, you can update your driver to
use the new drm_of_fund_bridge() and take care of putting the reference
when appropriate. But you don't need to do anything until then.

[0] https://lore.kernel.org/dri-devel/20250319-stylish-lime-mongoose-0a18ad@houat/
[1] https://lore.kernel.org/lkml/20251119-drm-bridge-alloc-getput-drm_of_find_bridge-v1-0-0db98a7fe474@bootlin.com/

> Thank you.

You're welcome. I hope it was a clear explanation.

Luca

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ