* [PATCH v4 01/11] drm/bridge: drm_bridge_get/put(): ignore ERR_PTR
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 13:53 ` Laurent Pinchart
2026-05-04 10:45 ` [PATCH v4 02/11] drm/bridge: add of_drm_get_bridge_by_endpoint() Luca Ceresoli
` (9 subsequent siblings)
10 siblings, 1 reply; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli,
Laurent Pinchart, Dmitry Baryshkov
Most functions returning a struct drm_bridge pointer currently return a
valid pointer or NULL, but this restricts their ability to return an error
code describing the error kind.
In preparation to have new APIs that can return a struct drm_bridge pointer
holding an ERR_PTR (and for those which already do) make drm_bridge_get()
and drm_bridge_put() ignore ERR_PTR values, just like they ignore NULL
pointers.
This will avoid annoying error checking in many places and the risk of
missing error checks.
Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Link: https://lore.kernel.org/all/20260318152533.GA633439@killaraus.ideasonboard.com/
Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Link: https://lore.kernel.org/all/omlnswxukeqgnatzdvooaashgkfcacjevkvbkm6xt33itgua2k@jcmzll2w6kdq/
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v4:
- removed incorrect change to drm_bridge_clear_and_put() kdoc
Patch added in v2
---
drivers/gpu/drm/drm_bridge.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index d4b3478258ec..6fb71de6d22a 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -282,7 +282,7 @@ static void __drm_bridge_free(struct kref *kref)
/**
* drm_bridge_get - Acquire a bridge reference
- * @bridge: DRM bridge; if NULL this function does nothing
+ * @bridge: DRM bridge; if NULL or an ERR_PTR this function does nothing
*
* This function increments the bridge's refcount.
*
@@ -291,7 +291,7 @@ static void __drm_bridge_free(struct kref *kref)
*/
struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge)
{
- if (bridge)
+ if (!IS_ERR_OR_NULL(bridge))
kref_get(&bridge->refcount);
return bridge;
@@ -300,7 +300,7 @@ EXPORT_SYMBOL(drm_bridge_get);
/**
* drm_bridge_put - Release a bridge reference
- * @bridge: DRM bridge; if NULL this function does nothing
+ * @bridge: DRM bridge; if NULL or an ERR_PTR this function does nothing
*
* This function decrements the bridge's reference count and frees the
* object if the reference count drops to zero.
@@ -310,7 +310,7 @@ EXPORT_SYMBOL(drm_bridge_get);
*/
void drm_bridge_put(struct drm_bridge *bridge)
{
- if (bridge)
+ if (!IS_ERR_OR_NULL(bridge))
kref_put(&bridge->refcount, __drm_bridge_free);
}
EXPORT_SYMBOL(drm_bridge_put);
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v4 01/11] drm/bridge: drm_bridge_get/put(): ignore ERR_PTR
2026-05-04 10:45 ` [PATCH v4 01/11] drm/bridge: drm_bridge_get/put(): ignore ERR_PTR Luca Ceresoli
@ 2026-05-04 13:53 ` Laurent Pinchart
2026-05-04 14:13 ` Luca Ceresoli
0 siblings, 1 reply; 19+ messages in thread
From: Laurent Pinchart @ 2026-05-04 13:53 UTC (permalink / raw)
To: Luca Ceresoli
Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Jonas Karlman,
Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek, Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel,
linux-kernel, linux-arm-msm, freedreno, linux-arm-kernel,
Dmitry Baryshkov
On Mon, May 04, 2026 at 12:45:04PM +0200, Luca Ceresoli wrote:
> Most functions returning a struct drm_bridge pointer currently return a
> valid pointer or NULL, but this restricts their ability to return an error
> code describing the error kind.
>
> In preparation to have new APIs that can return a struct drm_bridge pointer
> holding an ERR_PTR (and for those which already do) make drm_bridge_get()
> and drm_bridge_put() ignore ERR_PTR values, just like they ignore NULL
> pointers.
The change in drm_bridge_put() looks good to me. I'm less sure about
drm_bridge_get(), is there a valid use case to call get() on a bridge
that is not valid ? Doesn't it indicate a clear error in the caller ?
> This will avoid annoying error checking in many places and the risk of
> missing error checks.
>
> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Link: https://lore.kernel.org/all/20260318152533.GA633439@killaraus.ideasonboard.com/
> Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Link: https://lore.kernel.org/all/omlnswxukeqgnatzdvooaashgkfcacjevkvbkm6xt33itgua2k@jcmzll2w6kdq/
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
> ---
>
> Changes in v4:
> - removed incorrect change to drm_bridge_clear_and_put() kdoc
>
> Patch added in v2
> ---
> drivers/gpu/drm/drm_bridge.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> index d4b3478258ec..6fb71de6d22a 100644
> --- a/drivers/gpu/drm/drm_bridge.c
> +++ b/drivers/gpu/drm/drm_bridge.c
> @@ -282,7 +282,7 @@ static void __drm_bridge_free(struct kref *kref)
>
> /**
> * drm_bridge_get - Acquire a bridge reference
> - * @bridge: DRM bridge; if NULL this function does nothing
> + * @bridge: DRM bridge; if NULL or an ERR_PTR this function does nothing
> *
> * This function increments the bridge's refcount.
> *
> @@ -291,7 +291,7 @@ static void __drm_bridge_free(struct kref *kref)
> */
> struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge)
> {
> - if (bridge)
> + if (!IS_ERR_OR_NULL(bridge))
> kref_get(&bridge->refcount);
>
> return bridge;
> @@ -300,7 +300,7 @@ EXPORT_SYMBOL(drm_bridge_get);
>
> /**
> * drm_bridge_put - Release a bridge reference
> - * @bridge: DRM bridge; if NULL this function does nothing
> + * @bridge: DRM bridge; if NULL or an ERR_PTR this function does nothing
> *
> * This function decrements the bridge's reference count and frees the
> * object if the reference count drops to zero.
> @@ -310,7 +310,7 @@ EXPORT_SYMBOL(drm_bridge_get);
> */
> void drm_bridge_put(struct drm_bridge *bridge)
> {
> - if (bridge)
> + if (!IS_ERR_OR_NULL(bridge))
> kref_put(&bridge->refcount, __drm_bridge_free);
> }
> EXPORT_SYMBOL(drm_bridge_put);
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v4 01/11] drm/bridge: drm_bridge_get/put(): ignore ERR_PTR
2026-05-04 13:53 ` Laurent Pinchart
@ 2026-05-04 14:13 ` Luca Ceresoli
0 siblings, 0 replies; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 14:13 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Jonas Karlman,
Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek, Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel,
linux-kernel, linux-arm-msm, freedreno, linux-arm-kernel,
Dmitry Baryshkov
Hi Laurent,
On Mon May 4, 2026 at 3:53 PM CEST, Laurent Pinchart wrote:
> On Mon, May 04, 2026 at 12:45:04PM +0200, Luca Ceresoli wrote:
>> Most functions returning a struct drm_bridge pointer currently return a
>> valid pointer or NULL, but this restricts their ability to return an error
>> code describing the error kind.
>>
>> In preparation to have new APIs that can return a struct drm_bridge pointer
>> holding an ERR_PTR (and for those which already do) make drm_bridge_get()
>> and drm_bridge_put() ignore ERR_PTR values, just like they ignore NULL
>> pointers.
>
> The change in drm_bridge_put() looks good to me. I'm less sure about
> drm_bridge_get(), is there a valid use case to call get() on a bridge
> that is not valid ? Doesn't it indicate a clear error in the caller ?
Good point. Indeed I don't have a valid use case in mind.
I guess I can drop the drm_bridge_get() and send v5. Should there be a
valid use case it will emerge at some point and this can be rediscussed.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v4 02/11] drm/bridge: add of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 01/11] drm/bridge: drm_bridge_get/put(): ignore ERR_PTR Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 14:55 ` Laurent Pinchart
2026-05-04 10:45 ` [PATCH v4 03/11] drm/msm/hdmi: switch to of_drm_get_bridge_by_endpoint() Luca Ceresoli
` (8 subsequent siblings)
10 siblings, 1 reply; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli,
Dmitry Baryshkov
drm_of_find_panel_or_bridge() is widely used, but many callers pass NULL
into the @panel or the @bridge arguments, thus making a very partial usage
of this rather complex function.
Besides, the bridge returned in @bridge is not refcounted, thus making this
API unsafe when DRM bridge hotplug will be introduced.
Solve both issues for the cases of calls to drm_of_find_panel_or_bridge()
with a NULL @panel pointer by adding a new function that only looks for
bridges (and is thus much simpler) and increments the refcount of the
returned bridge.
The new function is identical to drm_of_find_panel_or_bridge() except it:
- handles bridge refcounting: uses of_drm_find_and_get_bridge() instead of
of_drm_find_bridge() internally to return a refcounted bridge
- is simpler to use: just takes no @panel parameter, returns the pointer
in the return value instead of a double pointer argument
- has a simpler implementation: it is equal to
drm_of_find_panel_or_bridge() after removing the code that becomes dead
when @panel == NULL
Also add this function to drm_bridge.c and not drm_of.c because it returns
bridges only.
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v4:
- update function declaration in non-OF case
Changes in v2:
- return the bridge in the return value, not a double pointer
---
drivers/gpu/drm/drm_bridge.c | 41 +++++++++++++++++++++++++++++++++++++++++
include/drm/drm_bridge.h | 7 +++++++
2 files changed, 48 insertions(+)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 6fb71de6d22a..01f9e0426648 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -1582,6 +1582,47 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np)
return bridge;
}
EXPORT_SYMBOL(of_drm_find_bridge);
+
+/**
+ * of_drm_get_bridge_by_endpoint - return DRM bridge connected to a port/endpoint
+ * @np: device tree node containing output ports
+ * @port: port in the device tree node, or -1 for the first port found
+ * @endpoint: endpoint in the device tree node, or -1 for the first endpoint found
+ *
+ * Given a DT node's port and endpoint number, find the connected node and
+ * return the associated drm_bridge device.
+ *
+ * The refcount of the returned bridge is incremented. Use drm_bridge_put()
+ * when done with it.
+ *
+ * Returns a pointer to the connected drm_bridge, or a negative error on failure
+ */
+struct drm_bridge *of_drm_get_bridge_by_endpoint(const struct device_node *np,
+ int port, int endpoint)
+{
+ struct drm_bridge *bridge;
+
+ /*
+ * of_graph_get_remote_node() produces a noisy error message if port
+ * node isn't found and the absence of the port is a legit case here,
+ * so at first we silently check whether graph presents in the
+ * device-tree node.
+ */
+ if (!of_graph_is_present(np))
+ return ERR_PTR(-ENODEV);
+
+ struct device_node *remote __free(device_node) =
+ of_graph_get_remote_node(np, port, endpoint);
+ if (!remote)
+ return ERR_PTR(-ENODEV);
+
+ bridge = of_drm_find_and_get_bridge(remote);
+ if (!bridge)
+ return ERR_PTR(-EPROBE_DEFER);
+
+ return bridge;
+}
+EXPORT_SYMBOL_GPL(of_drm_get_bridge_by_endpoint);
#endif
/**
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index d6cd0f5af045..31e11a360c42 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -1327,6 +1327,8 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
#ifdef CONFIG_OF
struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np);
struct drm_bridge *of_drm_find_bridge(struct device_node *np);
+struct drm_bridge *of_drm_get_bridge_by_endpoint(const struct device_node *np,
+ int port, int endpoint);
#else
static inline struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np)
{
@@ -1336,6 +1338,11 @@ static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)
{
return NULL;
}
+static inline struct drm_bridge *of_drm_get_bridge_by_endpoint(const struct device_node *np,
+ int port, int endpoint)
+{
+ return -ENODEV;
+}
#endif
static inline bool drm_bridge_is_last(struct drm_bridge *bridge)
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v4 02/11] drm/bridge: add of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 ` [PATCH v4 02/11] drm/bridge: add of_drm_get_bridge_by_endpoint() Luca Ceresoli
@ 2026-05-04 14:55 ` Laurent Pinchart
2026-05-04 15:03 ` Luca Ceresoli
0 siblings, 1 reply; 19+ messages in thread
From: Laurent Pinchart @ 2026-05-04 14:55 UTC (permalink / raw)
To: Luca Ceresoli
Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Jonas Karlman,
Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek, Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel,
linux-kernel, linux-arm-msm, freedreno, linux-arm-kernel,
Dmitry Baryshkov
On Mon, May 04, 2026 at 12:45:05PM +0200, Luca Ceresoli wrote:
> drm_of_find_panel_or_bridge() is widely used, but many callers pass NULL
> into the @panel or the @bridge arguments, thus making a very partial usage
> of this rather complex function.
>
> Besides, the bridge returned in @bridge is not refcounted, thus making this
> API unsafe when DRM bridge hotplug will be introduced.
>
> Solve both issues for the cases of calls to drm_of_find_panel_or_bridge()
> with a NULL @panel pointer by adding a new function that only looks for
> bridges (and is thus much simpler) and increments the refcount of the
> returned bridge.
>
> The new function is identical to drm_of_find_panel_or_bridge() except it:
>
> - handles bridge refcounting: uses of_drm_find_and_get_bridge() instead of
> of_drm_find_bridge() internally to return a refcounted bridge
> - is simpler to use: just takes no @panel parameter, returns the pointer
> in the return value instead of a double pointer argument
> - has a simpler implementation: it is equal to
> drm_of_find_panel_or_bridge() after removing the code that becomes dead
> when @panel == NULL
>
> Also add this function to drm_bridge.c and not drm_of.c because it returns
> bridges only.
>
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
> ---
> Changes in v4:
> - update function declaration in non-OF case
>
> Changes in v2:
> - return the bridge in the return value, not a double pointer
> ---
> drivers/gpu/drm/drm_bridge.c | 41 +++++++++++++++++++++++++++++++++++++++++
> include/drm/drm_bridge.h | 7 +++++++
> 2 files changed, 48 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> index 6fb71de6d22a..01f9e0426648 100644
> --- a/drivers/gpu/drm/drm_bridge.c
> +++ b/drivers/gpu/drm/drm_bridge.c
> @@ -1582,6 +1582,47 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np)
> return bridge;
> }
> EXPORT_SYMBOL(of_drm_find_bridge);
> +
> +/**
> + * of_drm_get_bridge_by_endpoint - return DRM bridge connected to a port/endpoint
> + * @np: device tree node containing output ports
> + * @port: port in the device tree node, or -1 for the first port found
> + * @endpoint: endpoint in the device tree node, or -1 for the first endpoint found
> + *
> + * Given a DT node's port and endpoint number, find the connected node and
> + * return the associated drm_bridge device.
> + *
> + * The refcount of the returned bridge is incremented. Use drm_bridge_put()
> + * when done with it.
> + *
> + * Returns a pointer to the connected drm_bridge, or a negative error on failure
> + */
> +struct drm_bridge *of_drm_get_bridge_by_endpoint(const struct device_node *np,
> + int port, int endpoint)
> +{
> + struct drm_bridge *bridge;
> +
> + /*
> + * of_graph_get_remote_node() produces a noisy error message if port
> + * node isn't found and the absence of the port is a legit case here,
> + * so at first we silently check whether graph presents in the
s/graph presents/graph is present/
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> + * device-tree node.
> + */
> + if (!of_graph_is_present(np))
> + return ERR_PTR(-ENODEV);
> +
> + struct device_node *remote __free(device_node) =
> + of_graph_get_remote_node(np, port, endpoint);
> + if (!remote)
> + return ERR_PTR(-ENODEV);
> +
> + bridge = of_drm_find_and_get_bridge(remote);
> + if (!bridge)
> + return ERR_PTR(-EPROBE_DEFER);
> +
> + return bridge;
> +}
> +EXPORT_SYMBOL_GPL(of_drm_get_bridge_by_endpoint);
> #endif
>
> /**
> diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
> index d6cd0f5af045..31e11a360c42 100644
> --- a/include/drm/drm_bridge.h
> +++ b/include/drm/drm_bridge.h
> @@ -1327,6 +1327,8 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
> #ifdef CONFIG_OF
> struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np);
> struct drm_bridge *of_drm_find_bridge(struct device_node *np);
> +struct drm_bridge *of_drm_get_bridge_by_endpoint(const struct device_node *np,
> + int port, int endpoint);
> #else
> static inline struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np)
> {
> @@ -1336,6 +1338,11 @@ static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)
> {
> return NULL;
> }
> +static inline struct drm_bridge *of_drm_get_bridge_by_endpoint(const struct device_node *np,
> + int port, int endpoint)
> +{
> + return -ENODEV;
> +}
> #endif
>
> static inline bool drm_bridge_is_last(struct drm_bridge *bridge)
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v4 02/11] drm/bridge: add of_drm_get_bridge_by_endpoint()
2026-05-04 14:55 ` Laurent Pinchart
@ 2026-05-04 15:03 ` Luca Ceresoli
0 siblings, 0 replies; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 15:03 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Jonas Karlman,
Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek, Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel,
linux-kernel, linux-arm-msm, freedreno, linux-arm-kernel,
Dmitry Baryshkov
Hi Laurent,
On Mon May 4, 2026 at 4:55 PM CEST, Laurent Pinchart wrote:
> On Mon, May 04, 2026 at 12:45:05PM +0200, Luca Ceresoli wrote:
>> drm_of_find_panel_or_bridge() is widely used, but many callers pass NULL
>> into the @panel or the @bridge arguments, thus making a very partial usage
>> of this rather complex function.
>>
>> Besides, the bridge returned in @bridge is not refcounted, thus making this
>> API unsafe when DRM bridge hotplug will be introduced.
>>
>> Solve both issues for the cases of calls to drm_of_find_panel_or_bridge()
>> with a NULL @panel pointer by adding a new function that only looks for
>> bridges (and is thus much simpler) and increments the refcount of the
>> returned bridge.
>>
>> The new function is identical to drm_of_find_panel_or_bridge() except it:
>>
>> - handles bridge refcounting: uses of_drm_find_and_get_bridge() instead of
>> of_drm_find_bridge() internally to return a refcounted bridge
>> - is simpler to use: just takes no @panel parameter, returns the pointer
>> in the return value instead of a double pointer argument
>> - has a simpler implementation: it is equal to
>> drm_of_find_panel_or_bridge() after removing the code that becomes dead
>> when @panel == NULL
>>
>> Also add this function to drm_bridge.c and not drm_of.c because it returns
>> bridges only.
>>
>> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
>> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
>> ---
>> Changes in v4:
>> - update function declaration in non-OF case
>>
>> Changes in v2:
>> - return the bridge in the return value, not a double pointer
>> ---
>> drivers/gpu/drm/drm_bridge.c | 41 +++++++++++++++++++++++++++++++++++++++++
>> include/drm/drm_bridge.h | 7 +++++++
>> 2 files changed, 48 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
>> index 6fb71de6d22a..01f9e0426648 100644
>> --- a/drivers/gpu/drm/drm_bridge.c
>> +++ b/drivers/gpu/drm/drm_bridge.c
>> @@ -1582,6 +1582,47 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np)
>> return bridge;
>> }
>> EXPORT_SYMBOL(of_drm_find_bridge);
>> +
>> +/**
>> + * of_drm_get_bridge_by_endpoint - return DRM bridge connected to a port/endpoint
>> + * @np: device tree node containing output ports
>> + * @port: port in the device tree node, or -1 for the first port found
>> + * @endpoint: endpoint in the device tree node, or -1 for the first endpoint found
>> + *
>> + * Given a DT node's port and endpoint number, find the connected node and
>> + * return the associated drm_bridge device.
>> + *
>> + * The refcount of the returned bridge is incremented. Use drm_bridge_put()
>> + * when done with it.
>> + *
>> + * Returns a pointer to the connected drm_bridge, or a negative error on failure
>> + */
>> +struct drm_bridge *of_drm_get_bridge_by_endpoint(const struct device_node *np,
>> + int port, int endpoint)
>> +{
>> + struct drm_bridge *bridge;
>> +
>> + /*
>> + * of_graph_get_remote_node() produces a noisy error message if port
>> + * node isn't found and the absence of the port is a legit case here,
>> + * so at first we silently check whether graph presents in the
>
> s/graph presents/graph is present/
Oh, wow. I copied this comment from elsewhere, meaning the same typo is
there too. I'm taking a note to fix those too.
> Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Thanks!
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v4 03/11] drm/msm/hdmi: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 01/11] drm/bridge: drm_bridge_get/put(): ignore ERR_PTR Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 02/11] drm/bridge: add of_drm_get_bridge_by_endpoint() Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 04/11] drm/hisilicon/kirin: " Luca Ceresoli
` (7 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli
This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
@panel parameter, thus using a reduced feature set of that function.
Replace this call with the simpler of_drm_get_bridge_by_endpoint().
Since of_drm_get_bridge_by_endpoint() increases the refcount of the
returned bridge, ensure it is put on removal.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v4:
- ensure next_bridge is put on later probe failures
Changes in v3:
- fix ERR_PTR deref when -ENODEV is returned
---
drivers/gpu/drm/msm/hdmi/hdmi.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/msm/hdmi/hdmi.c b/drivers/gpu/drm/msm/hdmi/hdmi.c
index d9491aac1a89..57e85ac38059 100644
--- a/drivers/gpu/drm/msm/hdmi/hdmi.c
+++ b/drivers/gpu/drm/msm/hdmi/hdmi.c
@@ -285,9 +285,14 @@ static int msm_hdmi_dev_probe(struct platform_device *pdev)
spin_lock_init(&hdmi->reg_lock);
mutex_init(&hdmi->state_mutex);
- ret = drm_of_find_panel_or_bridge(dev_of_node(dev), 1, 0, NULL, &hdmi->next_bridge);
- if (ret && ret != -ENODEV)
- return ret;
+ struct drm_bridge *next_bridge __free(drm_bridge_put) =
+ of_drm_get_bridge_by_endpoint(dev_of_node(dev), 1, 0);
+ if (IS_ERR(next_bridge)) {
+ if (PTR_ERR(next_bridge) == -ENODEV)
+ next_bridge = NULL;
+ else
+ return PTR_ERR(next_bridge);
+ }
hdmi->mmio = msm_ioremap(pdev, "core_physical");
if (IS_ERR(hdmi->mmio))
@@ -367,6 +372,8 @@ static int msm_hdmi_dev_probe(struct platform_device *pdev)
if (ret)
goto err_put_phy;
+ hdmi->next_bridge = no_free_ptr(next_bridge);
+
return 0;
err_put_phy:
@@ -381,6 +388,7 @@ static void msm_hdmi_dev_remove(struct platform_device *pdev)
component_del(&pdev->dev, &msm_hdmi_ops);
msm_hdmi_put_phy(hdmi);
+ drm_bridge_put(hdmi->next_bridge);
}
static int msm_hdmi_runtime_suspend(struct device *dev)
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v4 04/11] drm/hisilicon/kirin: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
` (2 preceding siblings ...)
2026-05-04 10:45 ` [PATCH v4 03/11] drm/msm/hdmi: switch to of_drm_get_bridge_by_endpoint() Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 05/11] drm/bridge: chrontel-ch7033: " Luca Ceresoli
` (6 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli
This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
@panel parameter, thus using a reduced feature set of that function.
Replace this call with the simpler of_drm_get_bridge_by_endpoint().
Since of_drm_get_bridge_by_endpoint() increases the refcount of the
returned bridge, ensure it is put on removal. Here the bridge pointer is
only stored in a temporary variable, so a cleanup action is enough.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c
index e80debdc4176..ab3cd309505a 100644
--- a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c
+++ b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c
@@ -778,17 +778,16 @@ static int dsi_host_init(struct device *dev, struct dw_dsi *dsi)
static int dsi_bridge_init(struct drm_device *dev, struct dw_dsi *dsi)
{
struct drm_encoder *encoder = &dsi->encoder;
- struct drm_bridge *bridge;
+ struct drm_bridge *bridge __free(drm_bridge_put) = NULL;
struct device_node *np = dsi->dev->of_node;
- int ret;
/*
* Get the endpoint node. In our case, dsi has one output port1
* to which the external HDMI bridge is connected.
*/
- ret = drm_of_find_panel_or_bridge(np, 1, 0, NULL, &bridge);
- if (ret)
- return ret;
+ bridge = of_drm_get_bridge_by_endpoint(np, 1, 0);
+ if (IS_ERR(bridge))
+ return PTR_ERR(bridge);
/* associate the bridge to dsi encoder */
return drm_bridge_attach(encoder, bridge, NULL, 0);
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v4 05/11] drm/bridge: chrontel-ch7033: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
` (3 preceding siblings ...)
2026-05-04 10:45 ` [PATCH v4 04/11] drm/hisilicon/kirin: " Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 06/11] drm/bridge: lontium-lt9611uxc: " Luca Ceresoli
` (5 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli,
Dmitry Baryshkov
This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
@panel parameter, thus using a reduced feature set of that function.
Replace this call with the simpler of_drm_get_bridge_by_endpoint().
Since of_drm_get_bridge_by_endpoint() increases the refcount of the
returned bridge, ensure it is put on removal. To achieve this, instead of
adding an explicit drm_bridge_put(), migrate to the bridge::next_bridge
pointer which is automatically put when the bridge is eventually freed.
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/bridge/chrontel-ch7033.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/drivers/gpu/drm/bridge/chrontel-ch7033.c b/drivers/gpu/drm/bridge/chrontel-ch7033.c
index 54d49d4882c8..a237c65ebd69 100644
--- a/drivers/gpu/drm/bridge/chrontel-ch7033.c
+++ b/drivers/gpu/drm/bridge/chrontel-ch7033.c
@@ -199,7 +199,6 @@ enum {
struct ch7033_priv {
struct regmap *regmap;
- struct drm_bridge *next_bridge;
struct drm_bridge bridge;
struct drm_connector connector;
};
@@ -215,7 +214,7 @@ static enum drm_connector_status ch7033_connector_detect(
{
struct ch7033_priv *priv = conn_to_ch7033_priv(connector);
- return drm_bridge_detect(priv->next_bridge, connector);
+ return drm_bridge_detect(priv->bridge.next_bridge, connector);
}
static const struct drm_connector_funcs ch7033_connector_funcs = {
@@ -233,7 +232,7 @@ static int ch7033_connector_get_modes(struct drm_connector *connector)
const struct drm_edid *drm_edid;
int ret;
- drm_edid = drm_bridge_edid_read(priv->next_bridge, connector);
+ drm_edid = drm_bridge_edid_read(priv->bridge.next_bridge, connector);
drm_edid_connector_update(connector, drm_edid);
if (drm_edid) {
ret = drm_edid_connector_add_modes(connector);
@@ -275,7 +274,7 @@ static int ch7033_bridge_attach(struct drm_bridge *bridge,
struct drm_connector *connector = &priv->connector;
int ret;
- ret = drm_bridge_attach(encoder, priv->next_bridge, bridge,
+ ret = drm_bridge_attach(encoder, priv->bridge.next_bridge, bridge,
DRM_BRIDGE_ATTACH_NO_CONNECTOR);
if (ret)
return ret;
@@ -283,15 +282,15 @@ static int ch7033_bridge_attach(struct drm_bridge *bridge,
if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
return 0;
- if (priv->next_bridge->ops & DRM_BRIDGE_OP_DETECT) {
+ if (priv->bridge.next_bridge->ops & DRM_BRIDGE_OP_DETECT) {
connector->polled = DRM_CONNECTOR_POLL_HPD;
} else {
connector->polled = DRM_CONNECTOR_POLL_CONNECT |
DRM_CONNECTOR_POLL_DISCONNECT;
}
- if (priv->next_bridge->ops & DRM_BRIDGE_OP_HPD) {
- drm_bridge_hpd_enable(priv->next_bridge, ch7033_hpd_event,
+ if (priv->bridge.next_bridge->ops & DRM_BRIDGE_OP_HPD) {
+ drm_bridge_hpd_enable(priv->bridge.next_bridge, ch7033_hpd_event,
priv);
}
@@ -299,8 +298,8 @@ static int ch7033_bridge_attach(struct drm_bridge *bridge,
&ch7033_connector_helper_funcs);
ret = drm_connector_init_with_ddc(bridge->dev, &priv->connector,
&ch7033_connector_funcs,
- priv->next_bridge->type,
- priv->next_bridge->ddc);
+ priv->bridge.next_bridge->type,
+ priv->bridge.next_bridge->ddc);
if (ret) {
DRM_ERROR("Failed to initialize connector\n");
return ret;
@@ -313,8 +312,8 @@ static void ch7033_bridge_detach(struct drm_bridge *bridge)
{
struct ch7033_priv *priv = bridge_to_ch7033_priv(bridge);
- if (priv->next_bridge->ops & DRM_BRIDGE_OP_HPD)
- drm_bridge_hpd_disable(priv->next_bridge);
+ if (priv->bridge.next_bridge->ops & DRM_BRIDGE_OP_HPD)
+ drm_bridge_hpd_disable(priv->bridge.next_bridge);
drm_connector_cleanup(&priv->connector);
}
@@ -543,10 +542,9 @@ static int ch7033_probe(struct i2c_client *client)
dev_set_drvdata(dev, priv);
- ret = drm_of_find_panel_or_bridge(dev->of_node, 1, -1, NULL,
- &priv->next_bridge);
- if (ret)
- return ret;
+ priv->bridge.next_bridge = of_drm_get_bridge_by_endpoint(dev->of_node, 1, -1);
+ if (IS_ERR(priv->bridge.next_bridge))
+ return PTR_ERR(priv->bridge.next_bridge);
priv->regmap = devm_regmap_init_i2c(client, &ch7033_regmap_config);
if (IS_ERR(priv->regmap)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v4 06/11] drm/bridge: lontium-lt9611uxc: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
` (4 preceding siblings ...)
2026-05-04 10:45 ` [PATCH v4 05/11] drm/bridge: chrontel-ch7033: " Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 07/11] drm/bridge: lt9611: " Luca Ceresoli
` (4 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli,
Dmitry Baryshkov
This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
@panel parameter, thus using a reduced feature set of that function.
Replace this call with the simpler of_drm_get_bridge_by_endpoint().
Since of_drm_get_bridge_by_endpoint() increases the refcount of the
returned bridge, ensure it is put on removal. To achieve this, instead of
adding an explicit drm_bridge_put(), migrate to the bridge::next_bridge
pointer which is automatically put when the bridge is eventually freed.
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/bridge/lontium-lt9611uxc.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/bridge/lontium-lt9611uxc.c b/drivers/gpu/drm/bridge/lontium-lt9611uxc.c
index 11aab07d88df..9427cc2358ae 100644
--- a/drivers/gpu/drm/bridge/lontium-lt9611uxc.c
+++ b/drivers/gpu/drm/bridge/lontium-lt9611uxc.c
@@ -35,7 +35,6 @@
struct lt9611uxc {
struct device *dev;
struct drm_bridge bridge;
- struct drm_bridge *next_bridge;
struct regmap *regmap;
/* Protects all accesses to registers by stopping the on-chip MCU */
@@ -284,7 +283,7 @@ static int lt9611uxc_bridge_attach(struct drm_bridge *bridge,
{
struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
- return drm_bridge_attach(encoder, lt9611uxc->next_bridge,
+ return drm_bridge_attach(encoder, lt9611uxc->bridge.next_bridge,
bridge, flags);
}
@@ -487,7 +486,11 @@ static int lt9611uxc_parse_dt(struct device *dev,
lt9611uxc->dsi1_node = of_graph_get_remote_node(dev->of_node, 1, -1);
- return drm_of_find_panel_or_bridge(dev->of_node, 2, -1, NULL, <9611uxc->next_bridge);
+ lt9611uxc->bridge.next_bridge = of_drm_get_bridge_by_endpoint(dev->of_node, 2, -1);
+ if (IS_ERR(lt9611uxc->bridge.next_bridge))
+ return PTR_ERR(lt9611uxc->bridge.next_bridge);
+
+ return 0;
}
static int lt9611uxc_gpio_init(struct lt9611uxc *lt9611uxc)
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v4 07/11] drm/bridge: lt9611: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
` (5 preceding siblings ...)
2026-05-04 10:45 ` [PATCH v4 06/11] drm/bridge: lontium-lt9611uxc: " Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 08/11] drm/bridge: adv7511: " Luca Ceresoli
` (3 subsequent siblings)
10 siblings, 0 replies; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli,
Dmitry Baryshkov
This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
@panel parameter, thus using a reduced feature set of that function.
Replace this call with the simpler of_drm_get_bridge_by_endpoint().
Since of_drm_get_bridge_by_endpoint() increases the refcount of the
returned bridge, ensure it is put on removal. To achieve this, instead of
adding an explicit drm_bridge_put(), migrate to the bridge::next_bridge
pointer which is automatically put when the bridge is eventually freed.
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/bridge/lontium-lt9611.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/bridge/lontium-lt9611.c b/drivers/gpu/drm/bridge/lontium-lt9611.c
index 4517aee83332..4b4418cc83bf 100644
--- a/drivers/gpu/drm/bridge/lontium-lt9611.c
+++ b/drivers/gpu/drm/bridge/lontium-lt9611.c
@@ -37,7 +37,6 @@
struct lt9611 {
struct device *dev;
struct drm_bridge bridge;
- struct drm_bridge *next_bridge;
struct regmap *regmap;
@@ -761,7 +760,7 @@ static int lt9611_bridge_attach(struct drm_bridge *bridge,
{
struct lt9611 *lt9611 = bridge_to_lt9611(bridge);
- return drm_bridge_attach(encoder, lt9611->next_bridge,
+ return drm_bridge_attach(encoder, lt9611->bridge.next_bridge,
bridge, flags);
}
@@ -1058,7 +1057,11 @@ static int lt9611_parse_dt(struct device *dev,
lt9611->ac_mode = of_property_read_bool(dev->of_node, "lt,ac-mode");
- return drm_of_find_panel_or_bridge(dev->of_node, 2, -1, NULL, <9611->next_bridge);
+ lt9611->bridge.next_bridge = of_drm_get_bridge_by_endpoint(dev->of_node, 2, -1);
+ if (IS_ERR(lt9611->bridge.next_bridge))
+ return PTR_ERR(lt9611->bridge.next_bridge);
+
+ return 0;
}
static int lt9611_gpio_init(struct lt9611 *lt9611)
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v4 08/11] drm/bridge: adv7511: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
` (6 preceding siblings ...)
2026-05-04 10:45 ` [PATCH v4 07/11] drm/bridge: lt9611: " Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 15:22 ` Laurent Pinchart
2026-05-04 10:45 ` [PATCH v4 09/11] drm/bridge: lt8713sx: " Luca Ceresoli
` (2 subsequent siblings)
10 siblings, 1 reply; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli,
Biju Das, Dmitry Baryshkov
This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
@panel parameter, thus using a reduced feature set of that function.
Replace this call with the simpler of_drm_get_bridge_by_endpoint().
Since of_drm_get_bridge_by_endpoint() increases the refcount of the
returned bridge, ensure it is put on removal. To achieve this, instead of
adding an explicit drm_bridge_put(), migrate to the bridge::next_bridge
pointer which is automatically put when the bridge is eventually freed.
Tested-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- fix ERR_PTR deref when -ENODEV is returned
---
drivers/gpu/drm/bridge/adv7511/adv7511.h | 1 -
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 15 +++++++++------
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511.h b/drivers/gpu/drm/bridge/adv7511/adv7511.h
index 8be7266fd4f4..12c95198d9a4 100644
--- a/drivers/gpu/drm/bridge/adv7511/adv7511.h
+++ b/drivers/gpu/drm/bridge/adv7511/adv7511.h
@@ -354,7 +354,6 @@ struct adv7511 {
enum drm_connector_status status;
bool powered;
- struct drm_bridge *next_bridge;
struct drm_display_mode curr_mode;
unsigned int f_tmds;
diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
index f318080f1139..8304978535e4 100644
--- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
+++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
@@ -849,8 +849,8 @@ static int adv7511_bridge_attach(struct drm_bridge *bridge,
struct adv7511 *adv = bridge_to_adv7511(bridge);
int ret = 0;
- if (adv->next_bridge) {
- ret = drm_bridge_attach(encoder, adv->next_bridge, bridge,
+ if (adv->bridge.next_bridge) {
+ ret = drm_bridge_attach(encoder, adv->bridge.next_bridge, bridge,
flags | DRM_BRIDGE_ATTACH_NO_CONNECTOR);
if (ret)
return ret;
@@ -1249,10 +1249,13 @@ static int adv7511_probe(struct i2c_client *i2c)
memset(&link_config, 0, sizeof(link_config));
- ret = drm_of_find_panel_or_bridge(dev->of_node, 1, -1, NULL,
- &adv7511->next_bridge);
- if (ret && ret != -ENODEV)
- return ret;
+ adv7511->bridge.next_bridge = of_drm_get_bridge_by_endpoint(dev->of_node, 1, -1);
+ if (IS_ERR(adv7511->bridge.next_bridge)) {
+ if (PTR_ERR(adv7511->bridge.next_bridge) == -ENODEV)
+ adv7511->bridge.next_bridge = NULL;
+ else
+ return PTR_ERR(adv7511->bridge.next_bridge);
+ }
if (adv7511->info->link_config)
ret = adv7511_parse_dt(dev->of_node, &link_config);
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v4 08/11] drm/bridge: adv7511: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 ` [PATCH v4 08/11] drm/bridge: adv7511: " Luca Ceresoli
@ 2026-05-04 15:22 ` Laurent Pinchart
0 siblings, 0 replies; 19+ messages in thread
From: Laurent Pinchart @ 2026-05-04 15:22 UTC (permalink / raw)
To: Luca Ceresoli
Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Jonas Karlman,
Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek, Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel,
linux-kernel, linux-arm-msm, freedreno, linux-arm-kernel,
Biju Das, Dmitry Baryshkov
Hi Luca,
Thank you for the patch.
On Mon, May 04, 2026 at 12:45:11PM +0200, Luca Ceresoli wrote:
> This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
> @panel parameter, thus using a reduced feature set of that function.
> Replace this call with the simpler of_drm_get_bridge_by_endpoint().
>
> Since of_drm_get_bridge_by_endpoint() increases the refcount of the
> returned bridge, ensure it is put on removal. To achieve this, instead of
> adding an explicit drm_bridge_put(), migrate to the bridge::next_bridge
> pointer which is automatically put when the bridge is eventually freed.
>
> Tested-by: Biju Das <biju.das.jz@bp.renesas.com>
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> ---
> Changes in v3:
> - fix ERR_PTR deref when -ENODEV is returned
> ---
> drivers/gpu/drm/bridge/adv7511/adv7511.h | 1 -
> drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 15 +++++++++------
> 2 files changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511.h b/drivers/gpu/drm/bridge/adv7511/adv7511.h
> index 8be7266fd4f4..12c95198d9a4 100644
> --- a/drivers/gpu/drm/bridge/adv7511/adv7511.h
> +++ b/drivers/gpu/drm/bridge/adv7511/adv7511.h
> @@ -354,7 +354,6 @@ struct adv7511 {
> enum drm_connector_status status;
> bool powered;
>
> - struct drm_bridge *next_bridge;
> struct drm_display_mode curr_mode;
>
> unsigned int f_tmds;
> diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
> index f318080f1139..8304978535e4 100644
> --- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
> +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
> @@ -849,8 +849,8 @@ static int adv7511_bridge_attach(struct drm_bridge *bridge,
> struct adv7511 *adv = bridge_to_adv7511(bridge);
> int ret = 0;
>
> - if (adv->next_bridge) {
> - ret = drm_bridge_attach(encoder, adv->next_bridge, bridge,
> + if (adv->bridge.next_bridge) {
> + ret = drm_bridge_attach(encoder, adv->bridge.next_bridge, bridge,
> flags | DRM_BRIDGE_ATTACH_NO_CONNECTOR);
> if (ret)
> return ret;
> @@ -1249,10 +1249,13 @@ static int adv7511_probe(struct i2c_client *i2c)
>
> memset(&link_config, 0, sizeof(link_config));
>
> - ret = drm_of_find_panel_or_bridge(dev->of_node, 1, -1, NULL,
> - &adv7511->next_bridge);
> - if (ret && ret != -ENODEV)
> - return ret;
> + adv7511->bridge.next_bridge = of_drm_get_bridge_by_endpoint(dev->of_node, 1, -1);
> + if (IS_ERR(adv7511->bridge.next_bridge)) {
> + if (PTR_ERR(adv7511->bridge.next_bridge) == -ENODEV)
> + adv7511->bridge.next_bridge = NULL;
> + else
> + return PTR_ERR(adv7511->bridge.next_bridge);
> + }
>
> if (adv7511->info->link_config)
> ret = adv7511_parse_dt(dev->of_node, &link_config);
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v4 09/11] drm/bridge: lt8713sx: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
` (7 preceding siblings ...)
2026-05-04 10:45 ` [PATCH v4 08/11] drm/bridge: adv7511: " Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 10/11] drm: zynqmp_dp: " Luca Ceresoli
2026-05-04 10:45 ` [PATCH v4 11/11] drm: of: forbid bridge-only calls to drm_of_find_panel_or_bridge() Luca Ceresoli
10 siblings, 0 replies; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli,
Dmitry Baryshkov
This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
@panel parameter, thus using a reduced feature set of that function.
Replace this call with the simpler of_drm_get_bridge_by_endpoint().
Since of_drm_get_bridge_by_endpoint() increases the refcount of the
returned bridge, ensure it is put on removal. To achieve this, instead of
adding an explicit drm_bridge_put(), migrate to the bridge::next_bridge
pointer which is automatically put when the bridge is eventually freed.
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/bridge/lontium-lt8713sx.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/bridge/lontium-lt8713sx.c b/drivers/gpu/drm/bridge/lontium-lt8713sx.c
index 18fac6a46db4..cee485adf5e5 100644
--- a/drivers/gpu/drm/bridge/lontium-lt8713sx.c
+++ b/drivers/gpu/drm/bridge/lontium-lt8713sx.c
@@ -32,7 +32,6 @@ DECLARE_CRC8_TABLE(lt8713sx_crc_table);
struct lt8713sx {
struct device *dev;
struct drm_bridge bridge;
- struct drm_bridge *next_bridge;
struct regmap *regmap;
/* Protects all accesses to registers by stopping the on-chip MCU */
@@ -458,7 +457,7 @@ static int lt8713sx_bridge_attach(struct drm_bridge *bridge,
struct lt8713sx *lt8713sx = container_of(bridge, struct lt8713sx, bridge);
return drm_bridge_attach(encoder,
- lt8713sx->next_bridge,
+ lt8713sx->bridge.next_bridge,
bridge, flags);
}
@@ -537,10 +536,9 @@ static int lt8713sx_probe(struct i2c_client *client)
if (IS_ERR(lt8713sx->regmap))
return dev_err_probe(dev, PTR_ERR(lt8713sx->regmap), "regmap i2c init failed\n");
- ret = drm_of_find_panel_or_bridge(lt8713sx->dev->of_node, 1, -1, NULL,
- <8713sx->next_bridge);
- if (ret < 0)
- return ret;
+ lt8713sx->bridge.next_bridge = of_drm_get_bridge_by_endpoint(lt8713sx->dev->of_node, 1, -1);
+ if (IS_ERR(lt8713sx->bridge.next_bridge))
+ return PTR_ERR(lt8713sx->bridge.next_bridge);
ret = lt8713sx_gpio_init(lt8713sx);
if (ret < 0)
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH v4 10/11] drm: zynqmp_dp: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
` (8 preceding siblings ...)
2026-05-04 10:45 ` [PATCH v4 09/11] drm/bridge: lt8713sx: " Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 15:24 ` Laurent Pinchart
2026-05-04 10:45 ` [PATCH v4 11/11] drm: of: forbid bridge-only calls to drm_of_find_panel_or_bridge() Luca Ceresoli
10 siblings, 1 reply; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli
This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
@panel parameter, thus using a reduced feature set of that function.
Replace this call with the simpler of_drm_get_bridge_by_endpoint().
Since of_drm_get_bridge_by_endpoint() increases the refcount of the
returned bridge, ensure it is put on removal. To achieve this, instead of
adding an explicit drm_bridge_put(), migrate to the bridge::next_bridge
pointer which is automatically put when the bridge is eventually freed.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v4:
- fix missing assignment
Changes in v3:
- fix ERR_PTR deref when -ENODEV is returned
---
drivers/gpu/drm/xlnx/zynqmp_dp.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c b/drivers/gpu/drm/xlnx/zynqmp_dp.c
index 379180fb3004..fd30491a6697 100644
--- a/drivers/gpu/drm/xlnx/zynqmp_dp.c
+++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c
@@ -353,7 +353,6 @@ struct zynqmp_dp_train_set_priv {
* @lock: Mutex protecting this struct and register access (but not AUX)
* @irq: irq
* @bridge: DRM bridge for the DP encoder
- * @next_bridge: The downstream bridge
* @test: Configuration for test mode
* @config: IP core configuration from DTS
* @aux: aux channel
@@ -385,7 +384,6 @@ struct zynqmp_dp {
struct completion aux_done;
struct mutex lock;
- struct drm_bridge *next_bridge;
struct device *dev;
struct zynqmp_dpsub *dpsub;
void __iomem *iomem;
@@ -1494,8 +1492,8 @@ static int zynqmp_dp_bridge_attach(struct drm_bridge *bridge,
return ret;
}
- if (dp->next_bridge) {
- ret = drm_bridge_attach(encoder, dp->next_bridge,
+ if (dp->bridge.next_bridge) {
+ ret = drm_bridge_attach(encoder, dp->bridge.next_bridge,
bridge, flags);
if (ret < 0)
goto error;
@@ -2461,10 +2459,15 @@ int zynqmp_dp_probe(struct zynqmp_dpsub *dpsub)
* Acquire the next bridge in the chain. Ignore errors caused by port@5
* not being connected for backward-compatibility with older DTs.
*/
- ret = drm_of_find_panel_or_bridge(dp->dev->of_node, 5, 0, NULL,
- &dp->next_bridge);
- if (ret < 0 && ret != -ENODEV)
- goto err_reset;
+ dp->bridge.next_bridge = of_drm_get_bridge_by_endpoint(dp->dev->of_node, 5, 0);
+ if (IS_ERR(dp->bridge.next_bridge)) {
+ if (PTR_ERR(dp->bridge.next_bridge) == -ENODEV) {
+ dp->bridge.next_bridge = NULL;
+ } else {
+ ret = PTR_ERR(dp->bridge.next_bridge);
+ goto err_reset;
+ }
+ }
/* Initialize the hardware. */
dp->config.misc0 &= ~ZYNQMP_DP_MAIN_STREAM_MISC0_SYNC_LOCK;
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v4 10/11] drm: zynqmp_dp: switch to of_drm_get_bridge_by_endpoint()
2026-05-04 10:45 ` [PATCH v4 10/11] drm: zynqmp_dp: " Luca Ceresoli
@ 2026-05-04 15:24 ` Laurent Pinchart
0 siblings, 0 replies; 19+ messages in thread
From: Laurent Pinchart @ 2026-05-04 15:24 UTC (permalink / raw)
To: Luca Ceresoli
Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Jonas Karlman,
Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek, Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel,
linux-kernel, linux-arm-msm, freedreno, linux-arm-kernel
Hi Luca,
Thank you for the patch.
On Mon, May 04, 2026 at 12:45:13PM +0200, Luca Ceresoli wrote:
> This driver calls drm_of_find_panel_or_bridge() with a NULL pointer in the
> @panel parameter, thus using a reduced feature set of that function.
> Replace this call with the simpler of_drm_get_bridge_by_endpoint().
>
> Since of_drm_get_bridge_by_endpoint() increases the refcount of the
> returned bridge, ensure it is put on removal. To achieve this, instead of
> adding an explicit drm_bridge_put(), migrate to the bridge::next_bridge
> pointer which is automatically put when the bridge is eventually freed.
>
> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
> ---
>
> Changes in v4:
> - fix missing assignment
>
> Changes in v3:
> - fix ERR_PTR deref when -ENODEV is returned
> ---
> drivers/gpu/drm/xlnx/zynqmp_dp.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/xlnx/zynqmp_dp.c b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> index 379180fb3004..fd30491a6697 100644
> --- a/drivers/gpu/drm/xlnx/zynqmp_dp.c
> +++ b/drivers/gpu/drm/xlnx/zynqmp_dp.c
> @@ -353,7 +353,6 @@ struct zynqmp_dp_train_set_priv {
> * @lock: Mutex protecting this struct and register access (but not AUX)
> * @irq: irq
> * @bridge: DRM bridge for the DP encoder
> - * @next_bridge: The downstream bridge
> * @test: Configuration for test mode
> * @config: IP core configuration from DTS
> * @aux: aux channel
> @@ -385,7 +384,6 @@ struct zynqmp_dp {
> struct completion aux_done;
> struct mutex lock;
>
> - struct drm_bridge *next_bridge;
> struct device *dev;
> struct zynqmp_dpsub *dpsub;
> void __iomem *iomem;
> @@ -1494,8 +1492,8 @@ static int zynqmp_dp_bridge_attach(struct drm_bridge *bridge,
> return ret;
> }
>
> - if (dp->next_bridge) {
> - ret = drm_bridge_attach(encoder, dp->next_bridge,
> + if (dp->bridge.next_bridge) {
> + ret = drm_bridge_attach(encoder, dp->bridge.next_bridge,
> bridge, flags);
> if (ret < 0)
> goto error;
> @@ -2461,10 +2459,15 @@ int zynqmp_dp_probe(struct zynqmp_dpsub *dpsub)
> * Acquire the next bridge in the chain. Ignore errors caused by port@5
> * not being connected for backward-compatibility with older DTs.
> */
> - ret = drm_of_find_panel_or_bridge(dp->dev->of_node, 5, 0, NULL,
> - &dp->next_bridge);
> - if (ret < 0 && ret != -ENODEV)
> - goto err_reset;
> + dp->bridge.next_bridge = of_drm_get_bridge_by_endpoint(dp->dev->of_node, 5, 0);
> + if (IS_ERR(dp->bridge.next_bridge)) {
> + if (PTR_ERR(dp->bridge.next_bridge) == -ENODEV) {
> + dp->bridge.next_bridge = NULL;
> + } else {
> + ret = PTR_ERR(dp->bridge.next_bridge);
> + goto err_reset;
> + }
I would find
if (PTR_ERR(dp->bridge.next_bridge) != -ENODEV) {
ret = PTR_ERR(dp->bridge.next_bridge);
goto err_reset;
}
dp->bridge.next_bridge = NULL;
easier to read. Up to you.
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> + }
>
> /* Initialize the hardware. */
> dp->config.misc0 &= ~ZYNQMP_DP_MAIN_STREAM_MISC0_SYNC_LOCK;
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v4 11/11] drm: of: forbid bridge-only calls to drm_of_find_panel_or_bridge()
2026-05-04 10:45 [PATCH v4 00/11] drm/bridge: handle refcounting for bridge-only callers of drm_of_find_panel_or_bridge() Luca Ceresoli
` (9 preceding siblings ...)
2026-05-04 10:45 ` [PATCH v4 10/11] drm: zynqmp_dp: " Luca Ceresoli
@ 2026-05-04 10:45 ` Luca Ceresoli
2026-05-04 15:27 ` Laurent Pinchart
10 siblings, 1 reply; 19+ messages in thread
From: Luca Ceresoli @ 2026-05-04 10:45 UTC (permalink / raw)
To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek
Cc: Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel, linux-kernel,
linux-arm-msm, freedreno, linux-arm-kernel, Luca Ceresoli,
Dmitry Baryshkov
Up to now drm_of_find_panel_or_bridge() can be called with a bridge pointer
only, a panel pointer only, or both a bridge and a panel pointers. The
logic to handle all the three cases is somewhat complex to read however.
Now all bridge-only callers have been converted to
of_drm_get_bridge_by_endpoint(), which is simpler and handles bridge
refcounting. So forbid new bridge-only users by mandating a non-NULL panel
pointer in the docs and in the sanity checks along with a warning.
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/drm_of.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
index ef6b09316963..d03ada82eac9 100644
--- a/drivers/gpu/drm/drm_of.c
+++ b/drivers/gpu/drm/drm_of.c
@@ -225,15 +225,15 @@ EXPORT_SYMBOL_GPL(drm_of_encoder_active_endpoint);
* @np: device tree node containing encoder output ports
* @port: port in the device tree node
* @endpoint: endpoint in the device tree node
- * @panel: pointer to hold returned drm_panel
+ * @panel: pointer to hold returned drm_panel, must not be NULL
* @bridge: pointer to hold returned drm_bridge
*
* Given a DT node's port and endpoint number, find the connected node and
- * return either the associated struct drm_panel or drm_bridge device. Either
- * @panel or @bridge must not be NULL.
+ * return either the associated struct drm_panel or drm_bridge device.
*
* This function is deprecated and should not be used in new drivers. Use
- * devm_drm_of_get_bridge() instead.
+ * of_drm_get_bridge_by_endpoint() instead when not looking for a panel, or
+ * devm_drm_of_get_bridge() otherwise.
*
* Returns zero if successful, or one of the standard error codes if it fails.
*/
@@ -245,10 +245,10 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
int ret = -EPROBE_DEFER;
struct device_node *remote;
- if (!panel && !bridge)
+ if (WARN_ON(!panel))
return -EINVAL;
- if (panel)
- *panel = NULL;
+
+ *panel = NULL;
/*
* of_graph_get_remote_node() produces a noisy error message if port
@@ -263,13 +263,11 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
if (!remote)
return -ENODEV;
- if (panel) {
- *panel = of_drm_find_panel(remote);
- if (!IS_ERR(*panel))
- ret = 0;
- else
- *panel = NULL;
- }
+ *panel = of_drm_find_panel(remote);
+ if (!IS_ERR(*panel))
+ ret = 0;
+ else
+ *panel = NULL;
if (bridge) {
if (ret) {
--
2.53.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v4 11/11] drm: of: forbid bridge-only calls to drm_of_find_panel_or_bridge()
2026-05-04 10:45 ` [PATCH v4 11/11] drm: of: forbid bridge-only calls to drm_of_find_panel_or_bridge() Luca Ceresoli
@ 2026-05-04 15:27 ` Laurent Pinchart
0 siblings, 0 replies; 19+ messages in thread
From: Laurent Pinchart @ 2026-05-04 15:27 UTC (permalink / raw)
To: Luca Ceresoli
Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Jonas Karlman,
Jernej Skrabec, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Rob Clark,
Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang, Sean Paul,
Marijn Suijten, Sumit Semwal, John Stultz, Tomi Valkeinen,
Michal Simek, Hui Pu, Ian Ray, Thomas Petazzoni, dri-devel,
linux-kernel, linux-arm-msm, freedreno, linux-arm-kernel,
Dmitry Baryshkov
On Mon, May 04, 2026 at 12:45:14PM +0200, Luca Ceresoli wrote:
> Up to now drm_of_find_panel_or_bridge() can be called with a bridge pointer
> only, a panel pointer only, or both a bridge and a panel pointers. The
> logic to handle all the three cases is somewhat complex to read however.
>
> Now all bridge-only callers have been converted to
> of_drm_get_bridge_by_endpoint(), which is simpler and handles bridge
> refcounting. So forbid new bridge-only users by mandating a non-NULL panel
> pointer in the docs and in the sanity checks along with a warning.
>
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> ---
> drivers/gpu/drm/drm_of.c | 26 ++++++++++++--------------
> 1 file changed, 12 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
> index ef6b09316963..d03ada82eac9 100644
> --- a/drivers/gpu/drm/drm_of.c
> +++ b/drivers/gpu/drm/drm_of.c
> @@ -225,15 +225,15 @@ EXPORT_SYMBOL_GPL(drm_of_encoder_active_endpoint);
> * @np: device tree node containing encoder output ports
> * @port: port in the device tree node
> * @endpoint: endpoint in the device tree node
> - * @panel: pointer to hold returned drm_panel
> + * @panel: pointer to hold returned drm_panel, must not be NULL
> * @bridge: pointer to hold returned drm_bridge
> *
> * Given a DT node's port and endpoint number, find the connected node and
> - * return either the associated struct drm_panel or drm_bridge device. Either
> - * @panel or @bridge must not be NULL.
> + * return either the associated struct drm_panel or drm_bridge device.
> *
> * This function is deprecated and should not be used in new drivers. Use
> - * devm_drm_of_get_bridge() instead.
> + * of_drm_get_bridge_by_endpoint() instead when not looking for a panel, or
> + * devm_drm_of_get_bridge() otherwise.
> *
> * Returns zero if successful, or one of the standard error codes if it fails.
> */
> @@ -245,10 +245,10 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
> int ret = -EPROBE_DEFER;
> struct device_node *remote;
>
> - if (!panel && !bridge)
> + if (WARN_ON(!panel))
> return -EINVAL;
> - if (panel)
> - *panel = NULL;
> +
> + *panel = NULL;
>
> /*
> * of_graph_get_remote_node() produces a noisy error message if port
> @@ -263,13 +263,11 @@ int drm_of_find_panel_or_bridge(const struct device_node *np,
> if (!remote)
> return -ENODEV;
>
> - if (panel) {
> - *panel = of_drm_find_panel(remote);
> - if (!IS_ERR(*panel))
> - ret = 0;
> - else
> - *panel = NULL;
> - }
> + *panel = of_drm_find_panel(remote);
> + if (!IS_ERR(*panel))
> + ret = 0;
> + else
> + *panel = NULL;
>
> if (bridge) {
> if (ret) {
>
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 19+ messages in thread