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-0db98a7fe...@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

Reply via email to