* [PATCH v4 01/32] drm/display: hdmi-cec-helper: use drmm_ prefix for drmm action
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 02/32] drm/display: hdmi-cec-helper: add non-drmm API variant Luca Ceresoli
` (30 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
For bridge hotplug drmm allocations are not suitable because a connector
may have to be added and removed multiple times in the lifetime of a card.
In preparation to support hotpluggable HDMI bridges (and the
drm_bridge_connector) we need a non-drmm variant of the CEC adapter
(de)registration API, with an explicit unregister API.
To differentiate the new explicit unregister API from the existing drmm
cleanup action, use the drmm_ prefix for the latter.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
New patch in v3.
---
drivers/gpu/drm/display/drm_hdmi_cec_helper.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
index ef6dbaa59dee..b79c41703d53 100644
--- a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
+++ b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
@@ -64,7 +64,7 @@ static void drm_connector_hdmi_cec_adapter_phys_addr_set(struct drm_connector *c
cec_s_phys_addr(data->adapter, addr, false);
}
-static void drm_connector_hdmi_cec_adapter_unregister(struct drm_device *dev, void *res)
+static void drmm_connector_hdmi_cec_adapter_unregister(struct drm_device *dev, void *res)
{
struct drm_connector *connector = res;
struct drm_connector_hdmi_cec_data *data = connector->cec.data;
@@ -145,7 +145,7 @@ int drmm_connector_hdmi_cec_register(struct drm_connector *connector,
mutex_unlock(&connector->cec.mutex);
return drmm_add_action_or_reset(connector->dev,
- drm_connector_hdmi_cec_adapter_unregister,
+ drmm_connector_hdmi_cec_adapter_unregister,
connector);
err_delete_adapter:
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 02/32] drm/display: hdmi-cec-helper: add non-drmm API variant
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 01/32] drm/display: hdmi-cec-helper: use drmm_ prefix for drmm action Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:08 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 03/32] drm/display: hdmi-cec-notifier-helper: use drmm_ prefix for drmm action Luca Ceresoli
` (29 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
For bridge hotplug drmm allocations are not suitable because a connector
may have to be added and removed multiple times in the lifetime of a card.
In preparation to support hotpluggable HDMI bridges (and the
drm_bridge_connector) add a non-drmm variant of the CEC adapter
(de)registration API, with an explicit unregister API.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/display/drm_hdmi_cec_helper.c | 60 ++++++++++++++++++---------
include/drm/display/drm_hdmi_cec_helper.h | 6 +++
2 files changed, 47 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
index b79c41703d53..81b271659ad9 100644
--- a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
+++ b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
@@ -67,15 +67,8 @@ static void drm_connector_hdmi_cec_adapter_phys_addr_set(struct drm_connector *c
static void drmm_connector_hdmi_cec_adapter_unregister(struct drm_device *dev, void *res)
{
struct drm_connector *connector = res;
- struct drm_connector_hdmi_cec_data *data = connector->cec.data;
-
- cec_unregister_adapter(data->adapter);
-
- if (data->funcs->uninit)
- data->funcs->uninit(connector);
- kfree(data);
- connector->cec.data = NULL;
+ drm_connector_hdmi_cec_unregister(connector);
}
static struct drm_connector_cec_funcs drm_connector_hdmi_cec_adapter_funcs = {
@@ -83,11 +76,11 @@ static struct drm_connector_cec_funcs drm_connector_hdmi_cec_adapter_funcs = {
.phys_addr_set = drm_connector_hdmi_cec_adapter_phys_addr_set,
};
-int drmm_connector_hdmi_cec_register(struct drm_connector *connector,
- const struct drm_connector_hdmi_cec_funcs *funcs,
- const char *name,
- u8 available_las,
- struct device *dev)
+int drm_connector_hdmi_cec_register(struct drm_connector *connector,
+ const struct drm_connector_hdmi_cec_funcs *funcs,
+ const char *name,
+ u8 available_las,
+ struct device *dev)
{
struct drm_connector_hdmi_cec_data *data;
struct cec_connector_info conn_info;
@@ -125,9 +118,8 @@ int drmm_connector_hdmi_cec_register(struct drm_connector *connector,
goto err_delete_adapter;
/*
- * NOTE: the CEC adapter will be unregistered by drmm cleanup from
- * drm_managed_release(), which is called from drm_dev_release()
- * during device unbind.
+ * NOTE: the CEC adapter will be unregistered by
+ * cec_unregister_adapter().
*
* However, the CEC framework cleans up the CEC adapter only when the
* last user has closed its file descriptor, so we don't need to handle
@@ -144,9 +136,7 @@ int drmm_connector_hdmi_cec_register(struct drm_connector *connector,
mutex_unlock(&connector->cec.mutex);
- return drmm_add_action_or_reset(connector->dev,
- drmm_connector_hdmi_cec_adapter_unregister,
- connector);
+ return 0;
err_delete_adapter:
cec_delete_adapter(cec_adap);
@@ -160,6 +150,38 @@ int drmm_connector_hdmi_cec_register(struct drm_connector *connector,
return ret;
}
+EXPORT_SYMBOL(drm_connector_hdmi_cec_register);
+
+void drm_connector_hdmi_cec_unregister(struct drm_connector *connector)
+{
+ struct drm_connector_hdmi_cec_data *data = connector->cec.data;
+
+ cec_unregister_adapter(data->adapter);
+
+ if (data->funcs->uninit)
+ data->funcs->uninit(connector);
+
+ kfree(data);
+ connector->cec.data = NULL;
+}
+EXPORT_SYMBOL(drm_connector_hdmi_cec_unregister);
+
+int drmm_connector_hdmi_cec_register(struct drm_connector *connector,
+ const struct drm_connector_hdmi_cec_funcs *funcs,
+ const char *name,
+ u8 available_las,
+ struct device *dev)
+{
+ int ret;
+
+ ret = drm_connector_hdmi_cec_register(connector, funcs, name, available_las, dev);
+ if (ret)
+ return ret;
+
+ return drmm_add_action_or_reset(connector->dev,
+ drmm_connector_hdmi_cec_adapter_unregister,
+ connector);
+}
EXPORT_SYMBOL(drmm_connector_hdmi_cec_register);
void drm_connector_hdmi_cec_received_msg(struct drm_connector *connector,
diff --git a/include/drm/display/drm_hdmi_cec_helper.h b/include/drm/display/drm_hdmi_cec_helper.h
index fd8f4d2f02c1..7e76a163e3a5 100644
--- a/include/drm/display/drm_hdmi_cec_helper.h
+++ b/include/drm/display/drm_hdmi_cec_helper.h
@@ -39,6 +39,12 @@ struct drm_connector_hdmi_cec_funcs {
u32 signal_free_time, struct cec_msg *msg);
};
+int drm_connector_hdmi_cec_register(struct drm_connector *connector,
+ const struct drm_connector_hdmi_cec_funcs *funcs,
+ const char *name,
+ u8 available_las,
+ struct device *dev);
+void drm_connector_hdmi_cec_unregister(struct drm_connector *connector);
int drmm_connector_hdmi_cec_register(struct drm_connector *connector,
const struct drm_connector_hdmi_cec_funcs *funcs,
const char *name,
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 02/32] drm/display: hdmi-cec-helper: add non-drmm API variant
2026-11-25 17:50 ` [PATCH v4 02/32] drm/display: hdmi-cec-helper: add non-drmm API variant Luca Ceresoli
@ 2026-11-25 18:08 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:08 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/display: missing lock and clear in
drm_connector_hdmi_cec_unregister()
--
commit 6c19735a9b5d351aeeed042f0b7e6649c04d3e13
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/display: hdmi-cec-helper: add non-drmm API variant
This commit adds non-drmm drm_connector_hdmi_cec_register() and
drm_connector_hdmi_cec_unregister() helpers to support hotpluggable HDMI
bridges.
> diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
> index b79c41703d539..81b271659ad9c 100644
> --- a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
> +++ b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c
[ ... ]
> @@ -160,6 +150,38 @@ int drmm_connector_hdmi_cec_register(struct drm_connector *connector,
>
> return ret;
> }
> +EXPORT_SYMBOL(drm_connector_hdmi_cec_register);
> +
> +void drm_connector_hdmi_cec_unregister(struct drm_connector *connector)
> +{
> + struct drm_connector_hdmi_cec_data *data = connector->cec.data;
> +
> + cec_unregister_adapter(data->adapter);
> +
> + if (data->funcs->uninit)
> + data->funcs->uninit(connector);
> +
> + kfree(data);
> + connector->cec.data = NULL;
> +}
> +EXPORT_SYMBOL(drm_connector_hdmi_cec_unregister);
[Severity: High]
Does drm_connector_hdmi_cec_unregister() need to hold connector->cec.mutex
and clear connector->cec.funcs?
drm_connector_cec_phys_addr_invalidate() and
drm_connector_cec_phys_addr_set() serialize on connector->cec.mutex and
check only connector->cec.funcs before invoking the callback, which then
dereferences connector->cec.data->adapter. Because
drm_connector_hdmi_cec_unregister() frees data without holding
connector->cec.mutex and leaves connector->cec.funcs populated while
connector->cec.data is NULL, a concurrent or subsequent hotplug path such
as drm_atomic_helper_connector_hdmi_hotplug() can trigger a use-after-free
or NULL pointer dereference on data.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=2
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 03/32] drm/display: hdmi-cec-notifier-helper: use drmm_ prefix for drmm action
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 01/32] drm/display: hdmi-cec-helper: use drmm_ prefix for drmm action Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 02/32] drm/display: hdmi-cec-helper: add non-drmm API variant Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 04/32] drm/display: hdmi-cec-notifier-helper: add non-drmm API variant Luca Ceresoli
` (28 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
For bridge hotplug drmm allocations are not suitable because a connector
may have to be added and removed multiple times in the lifetime of a card.
In preparation to support hotpluggable HDMI bridges (and the
drm_bridge_connector) we need a non-drmm variant of the CEC notifier
(de)registration API, with an explicit unregister API.
To differentiate the new explicit unregister API from the existing drmm
cleanup action, use the drmm_ prefix for the latter.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
New patch in v3.
---
drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
index 31b8e4a93e24..47662bdc5d08 100644
--- a/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
+++ b/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
@@ -25,7 +25,7 @@ static void drm_connector_hdmi_cec_notifier_phys_addr_set(struct drm_connector *
cec_notifier_set_phys_addr(connector->cec.data, addr);
}
-static void drm_connector_hdmi_cec_notifier_unregister(struct drm_device *dev, void *res)
+static void drmm_connector_hdmi_cec_notifier_unregister(struct drm_device *dev, void *res)
{
struct drm_connector *connector = res;
@@ -59,7 +59,7 @@ int drmm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
mutex_unlock(&connector->cec.mutex);
return drmm_add_action_or_reset(connector->dev,
- drm_connector_hdmi_cec_notifier_unregister,
+ drmm_connector_hdmi_cec_notifier_unregister,
connector);
}
EXPORT_SYMBOL(drmm_connector_hdmi_cec_notifier_register);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 04/32] drm/display: hdmi-cec-notifier-helper: add non-drmm API variant
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (2 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 03/32] drm/display: hdmi-cec-notifier-helper: use drmm_ prefix for drmm action Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:07 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 05/32] drm/connector: split drmm_connector_hdmi_init() in 3 parts Luca Ceresoli
` (27 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
For bridge hotplug drmm allocations are not suitable because a connector
may have to be added and removed multiple times in the lifetime of a card.
In preparation to support hotpluggable HDMI bridges (and the
drm_bridge_connector) add a non-drmm variant of the CEC notifier
(de)registration API, with an explicit unregister API.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
New patch in v3.
---
.../gpu/drm/display/drm_hdmi_cec_notifier_helper.c | 30 ++++++++++++++++++----
include/drm/display/drm_hdmi_cec_helper.h | 15 +++++++++++
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
index 47662bdc5d08..2f30844fcdad 100644
--- a/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
+++ b/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
@@ -29,8 +29,7 @@ static void drmm_connector_hdmi_cec_notifier_unregister(struct drm_device *dev,
{
struct drm_connector *connector = res;
- cec_notifier_conn_unregister(connector->cec.data);
- connector->cec.data = NULL;
+ drm_connector_hdmi_cec_notifier_unregister(connector);
}
static const struct drm_connector_cec_funcs drm_connector_cec_notifier_funcs = {
@@ -38,9 +37,9 @@ static const struct drm_connector_cec_funcs drm_connector_cec_notifier_funcs = {
.phys_addr_set = drm_connector_hdmi_cec_notifier_phys_addr_set,
};
-int drmm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
- const char *port_name,
- struct device *dev)
+int drm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
+ const char *port_name,
+ struct device *dev)
{
struct cec_connector_info conn_info;
struct cec_notifier *notifier;
@@ -58,6 +57,27 @@ int drmm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
mutex_unlock(&connector->cec.mutex);
+ return 0;
+}
+EXPORT_SYMBOL(drm_connector_hdmi_cec_notifier_register);
+
+void drm_connector_hdmi_cec_notifier_unregister(struct drm_connector *connector)
+{
+ cec_notifier_conn_unregister(connector->cec.data);
+ connector->cec.data = NULL;
+}
+EXPORT_SYMBOL(drm_connector_hdmi_cec_notifier_unregister);
+
+int drmm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
+ const char *port_name,
+ struct device *dev)
+{
+ int ret;
+
+ ret = drm_connector_hdmi_cec_notifier_register(connector, port_name, dev);
+ if (ret)
+ return ret;
+
return drmm_add_action_or_reset(connector->dev,
drmm_connector_hdmi_cec_notifier_unregister,
connector);
diff --git a/include/drm/display/drm_hdmi_cec_helper.h b/include/drm/display/drm_hdmi_cec_helper.h
index 7e76a163e3a5..8d648532eeb7 100644
--- a/include/drm/display/drm_hdmi_cec_helper.h
+++ b/include/drm/display/drm_hdmi_cec_helper.h
@@ -63,10 +63,25 @@ void drm_connector_hdmi_cec_transmit_attempt_done(struct drm_connector *connecto
u8 status);
#if IS_ENABLED(CONFIG_DRM_DISPLAY_HDMI_CEC_NOTIFIER_HELPER)
+int drm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
+ const char *port_name,
+ struct device *dev);
+void drm_connector_hdmi_cec_notifier_unregister(struct drm_connector *connector);
int drmm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
const char *port_name,
struct device *dev);
#else
+static inline int drm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
+ const char *port_name,
+ struct device *dev)
+{
+ return 0;
+}
+
+static inline void drm_connector_hdmi_cec_notifier_unregister(struct drm_connector *connector)
+{
+}
+
static inline int drmm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
const char *port_name,
struct device *dev)
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 04/32] drm/display: hdmi-cec-notifier-helper: add non-drmm API variant
2026-11-25 17:50 ` [PATCH v4 04/32] drm/display: hdmi-cec-notifier-helper: add non-drmm API variant Luca Ceresoli
@ 2026-11-25 18:07 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:07 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/display: missing cec.mutex in
drm_connector_hdmi_cec_notifier_unregister()
--
commit 524d66733b09456c82258b5e235e9f87be3e61c7
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/display: hdmi-cec-notifier-helper: add non-drmm API variant
This commit adds non-drmm register and unregister helpers for the HDMI CEC
notifier so that hotpluggable HDMI bridges can dynamically register and
unregister their CEC notifiers.
> diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
> index 47662bdc5d08f..2f30844fcdad9 100644
> --- a/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
> +++ b/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
[ ... ]
> @@ -58,6 +57,27 @@ int drmm_connector_hdmi_cec_notifier_register(struct drm_connector *connector,
>
> mutex_unlock(&connector->cec.mutex);
>
> + return 0;
> +}
> +EXPORT_SYMBOL(drm_connector_hdmi_cec_notifier_register);
> +
> +void drm_connector_hdmi_cec_notifier_unregister(struct drm_connector *connector)
> +{
> + cec_notifier_conn_unregister(connector->cec.data);
> + connector->cec.data = NULL;
> +}
> +EXPORT_SYMBOL(drm_connector_hdmi_cec_notifier_unregister);
[Severity: Medium]
Should drm_connector_hdmi_cec_notifier_unregister() take
connector->cec.mutex and also clear connector->cec.funcs?
drm_connector_hdmi_cec_notifier_register() sets connector->cec.data and
connector->cec.funcs under connector->cec.mutex, and
drm_connector_cec_phys_addr_set() and
drm_connector_cec_phys_addr_invalidate() hold the same mutex while calling
those callbacks. When a hotpluggable bridge unregisters its notifier at
runtime while connector detection runs concurrently, the lack of locking
allows a use-after-free on struct cec_notifier:
CPU0 CPU1
drm_connector_hdmi_cec_notifier_unregister()
cec_notifier_conn_unregister(connector->cec.data)
cec_notifier_put(n) [frees n]
drm_connector_cec_phys_addr_set()
mutex_lock(&connector->cec.mutex)
...->phys_addr_set()
cec_notifier_set_phys_addr(
connector->cec.data, ...)
mutex_lock(&n->lock)
<-- use-after-free
connector->cec.data = NULL;
Leaving connector->cec.funcs non-NULL also allows subsequent physical
address updates on the connector to keep invoking the notifier callbacks
with a NULL connector->cec.data pointer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=4
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 05/32] drm/connector: split drmm_connector_hdmi_init() in 3 parts
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (3 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 04/32] drm/display: hdmi-cec-notifier-helper: add non-drmm API variant Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 06/32] drm/connector: add drm_connector_hdmi_dynamic_init() Luca Ceresoli
` (26 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
In preparation for adding hotpluggable bridges we need connectors to be
created dynamically, both regular connectors and HDMI ones.
For non-HDMI connectors drm_connector_init() already has a dynamic
variant, but there is none for HDMI. Creating one would be easy by creating
a mostly-identical copy of drmm_connector_hdmi_init(), but it is a long
function so there would be a lot of duplicated code.
drmm_connector_hdmi_init() currently has 3 sections:
1. sanity checks
2. call drmm_connector_init()
3. initialize HDMI-specific fields not initialized at step 2
For the dynamic variant, sectons 1 and 3 would be an exact copy, while
section 2 needs to be different.
To avoid code duplication, split parts 1 and 3 to subfunctions. The next
commit will introduce the dynamic variant.
No functional changes. Just moving code around.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v2:
- expanded commit message to clarify rationale
- rebased on current drm-misc-next, which required a full rewrite after
the signature of drmm_connector_hdmi_init() changed in commit
400c9ede1ea4 ("drm/connector: Add drmm_connector_hdmi_init() with new
signature")
- renamed drm_connector_hdmi_init() to drm_connector_hdmi_initialize() as
or it would look like an HDMI version of drm_connector_init()
---
drivers/gpu/drm/drm_connector.c | 88 +++++++++++++++++++++++++----------------
1 file changed, 55 insertions(+), 33 deletions(-)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index da0b16f25ac4..20120b6a05d5 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -542,37 +542,11 @@ int drmm_connector_init(struct drm_device *dev,
}
EXPORT_SYMBOL(drmm_connector_init);
-/**
- * drmm_connector_hdmi_init - Init a preallocated HDMI connector
- * @dev: DRM device
- * @connector: A pointer to the HDMI connector to init
- * @funcs: callbacks for this connector
- * @hdmi_funcs: HDMI-related callbacks and capabilities for this connector
- * @connector_type: user visible type of the connector
- * @ddc: optional pointer to the associated ddc adapter
- *
- * Initialises a preallocated HDMI connector. Connectors can be
- * subclassed as part of driver connector objects.
- *
- * Cleanup is automatically handled with a call to
- * drm_connector_cleanup() in a DRM-managed action.
- *
- * The connector structure should be allocated with drmm_kzalloc().
- *
- * The @drm_connector_funcs.destroy hook must be NULL.
- *
- * Returns:
- * Zero on success, error code on failure.
- */
-int drmm_connector_hdmi_init(struct drm_device *dev,
- struct drm_connector *connector,
- const struct drm_connector_funcs *funcs,
- const struct drm_connector_hdmi_funcs *hdmi_funcs,
- int connector_type,
- struct i2c_adapter *ddc)
+static int drm_connector_hdmi_sanity_checks(struct drm_device *dev,
+ struct drm_connector *connector,
+ const struct drm_connector_hdmi_funcs *hdmi_funcs,
+ int connector_type)
{
- int ret;
-
if (!hdmi_funcs)
return -EINVAL;
@@ -613,9 +587,15 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
connector_type == DRM_MODE_CONNECTOR_HDMIB))
return -EINVAL;
- ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);
- if (ret)
- return ret;
+ return 0;
+}
+
+/* Initialize HDMI-specific resources of a connector */
+static int drm_connector_hdmi_initialize(struct drm_device *dev,
+ struct drm_connector *connector,
+ const struct drm_connector_hdmi_funcs *hdmi_funcs)
+{
+ int ret;
/* TODO: remove after conversion to new drmm_connector_hdmi_init() */
connector->hdmi.supported_formats = hdmi_funcs->supported_formats;
@@ -680,6 +660,48 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
return 0;
}
+
+/**
+ * drmm_connector_hdmi_init - Init a preallocated HDMI connector
+ * @dev: DRM device
+ * @connector: A pointer to the HDMI connector to init
+ * @funcs: callbacks for this connector
+ * @hdmi_funcs: HDMI-related callbacks and capabilities for this connector
+ * @connector_type: user visible type of the connector
+ * @ddc: optional pointer to the associated ddc adapter
+ *
+ * Initialises a preallocated HDMI connector. Connectors can be
+ * subclassed as part of driver connector objects.
+ *
+ * Cleanup is automatically handled with a call to
+ * drm_connector_cleanup() in a DRM-managed action.
+ *
+ * The connector structure should be allocated with drmm_kzalloc().
+ *
+ * The @drm_connector_funcs.destroy hook must be NULL.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drmm_connector_hdmi_init(struct drm_device *dev,
+ struct drm_connector *connector,
+ const struct drm_connector_funcs *funcs,
+ const struct drm_connector_hdmi_funcs *hdmi_funcs,
+ int connector_type,
+ struct i2c_adapter *ddc)
+{
+ int ret;
+
+ ret = drm_connector_hdmi_sanity_checks(dev, connector, hdmi_funcs, connector_type);
+ if (ret)
+ return ret;
+
+ ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);
+ if (ret)
+ return ret;
+
+ return drm_connector_hdmi_initialize(dev, connector, hdmi_funcs);
+}
EXPORT_SYMBOL(drmm_connector_hdmi_init);
/**
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 06/32] drm/connector: add drm_connector_hdmi_dynamic_init()
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (4 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 05/32] drm/connector: split drmm_connector_hdmi_init() in 3 parts Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:10 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 07/32] drm/display: bridge-connector: split allocation code from initialization code Luca Ceresoli
` (25 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
In preparation for adding hotpluggable bridges into the
drm_bridge_connector, we need connectors to be created dynamically, both
regular connectors and HDMI ones. drm_connector_init() already has a
dynamic variant, add one for HDMI connectors too.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- fix error management dead code
- fix kerneldoc
Changes in v2:
- rebased on current drm-misc-next: now drm_connector_hdmi_init() can fail,
so call drm_connector_cleanup(connector) if that happens
---
drivers/gpu/drm/drm_connector.c | 43 +++++++++++++++++++++++++++++++++++++++++
include/drm/drm_connector.h | 6 ++++++
2 files changed, 49 insertions(+)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 20120b6a05d5..021f2e120fdc 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -704,6 +704,49 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
}
EXPORT_SYMBOL(drmm_connector_hdmi_init);
+/**
+ * drm_connector_hdmi_dynamic_init - Init a preallocated dynamic HDMI connector
+ * @dev: DRM device
+ * @connector: A pointer to the HDMI connector to init
+ * @funcs: callbacks for this connector
+ * @hdmi_funcs: HDMI-related callbacks and capabilities for this connector
+ * @connector_type: user visible type of the connector
+ * @ddc: optional pointer to the associated ddc adapter
+ *
+ * Initialises a preallocated dynamic HDMI connector. Connectors can be
+ * subclassed as part of driver connector objects.
+ *
+ * See drm_connector_dynamic_init(), the same constraints apply here. This
+ * is just the HDMI version.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drm_connector_hdmi_dynamic_init(struct drm_device *dev,
+ struct drm_connector *connector,
+ const struct drm_connector_funcs *funcs,
+ const struct drm_connector_hdmi_funcs *hdmi_funcs,
+ int connector_type,
+ struct i2c_adapter *ddc)
+{
+ int ret;
+
+ ret = drm_connector_hdmi_sanity_checks(dev, connector, hdmi_funcs, connector_type);
+ if (ret)
+ return ret;
+
+ ret = drm_connector_dynamic_init(dev, connector, funcs, connector_type, ddc);
+ if (ret)
+ return ret;
+
+ ret = drm_connector_hdmi_initialize(dev, connector, hdmi_funcs);
+ if (ret)
+ drm_connector_cleanup(connector);
+
+ return ret;
+}
+EXPORT_SYMBOL(drm_connector_hdmi_dynamic_init);
+
/**
* drmm_connector_hdmi_ini2 - Init a preallocated HDMI connector
* @dev: DRM device
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index 07218ab26c9e..47de3b6d7218 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -2743,6 +2743,12 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
const struct drm_connector_hdmi_funcs *hdmi_funcs,
int connector_type,
struct i2c_adapter *ddc);
+int drm_connector_hdmi_dynamic_init(struct drm_device *dev,
+ struct drm_connector *connector,
+ const struct drm_connector_funcs *funcs,
+ const struct drm_connector_hdmi_funcs *hdmi_funcs,
+ int connector_type,
+ struct i2c_adapter *ddc);
int drmm_connector_hdmi_ini2(struct drm_device *dev,
struct drm_connector *connector,
const char *vendor, const char *product,
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 06/32] drm/connector: add drm_connector_hdmi_dynamic_init()
2026-11-25 17:50 ` [PATCH v4 06/32] drm/connector: add drm_connector_hdmi_dynamic_init() Luca Ceresoli
@ 2026-11-25 18:10 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:10 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/connector: dynamic HDMI init creates non-refcounted
drm_property post-reg
--
commit 3a8f2d8e52f1964bd9a6d73f9170a7532ea70354
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/connector: add drm_connector_hdmi_dynamic_init()
This commit adds drm_connector_hdmi_dynamic_init() to initialize dynamically
created HDMI connectors for hotpluggable bridges.
> diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> index 20120b6a05d52..021f2e120fdc7 100644
> --- a/drivers/gpu/drm/drm_connector.c
> +++ b/drivers/gpu/drm/drm_connector.c
> @@ -704,6 +704,49 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
> }
> EXPORT_SYMBOL(drmm_connector_hdmi_init);
>
> +/**
> + * drm_connector_hdmi_dynamic_init - Init a preallocated dynamic HDMI connector
> + * @dev: DRM device
> + * @connector: A pointer to the HDMI connector to init
> + * @funcs: callbacks for this connector
> + * @hdmi_funcs: HDMI-related callbacks and capabilities for this connector
> + * @connector_type: user visible type of the connector
> + * @ddc: optional pointer to the associated ddc adapter
> + *
> + * Initialises a preallocated dynamic HDMI connector. Connectors can be
> + * subclassed as part of driver connector objects.
> + *
> + * See drm_connector_dynamic_init(), the same constraints apply here. This
> + * is just the HDMI version.
> + *
> + * Returns:
> + * Zero on success, error code on failure.
> + */
> +int drm_connector_hdmi_dynamic_init(struct drm_device *dev,
> + struct drm_connector *connector,
> + const struct drm_connector_funcs *funcs,
> + const struct drm_connector_hdmi_funcs *hdmi_funcs,
> + int connector_type,
> + struct i2c_adapter *ddc)
> +{
> + int ret;
> +
> + ret = drm_connector_hdmi_sanity_checks(dev, connector, hdmi_funcs, connector_type);
> + if (ret)
> + return ret;
> +
> + ret = drm_connector_dynamic_init(dev, connector, funcs, connector_type, ddc);
> + if (ret)
> + return ret;
> +
> + ret = drm_connector_hdmi_initialize(dev, connector, hdmi_funcs);
> + if (ret)
> + drm_connector_cleanup(connector);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL(drm_connector_hdmi_dynamic_init);
[Severity: High]
Can drm_connector_hdmi_initialize() be called safely after drm_dev_register()
has registered the DRM device?
On a fresh connector, drm_connector_hdmi_initialize() calls
drm_connector_attach_max_bpc_property() and
drm_connector_attach_color_format_property(), which create new drm_property
objects via drm_property_create_range() and drm_property_create_enum().
Because DRM properties are non-refcounted mode objects (obj_free_cb is NULL),
calling drm_property_create() -> drm_mode_object_add() when dev->registered is
true triggers:
drivers/gpu/drm/drm_mode_object.c:__drm_mode_object_add() {
WARN_ON(!dev->driver->load && dev->registered && !obj_free_cb);
}
In addition, drm_property_create() adds the property to
dev->mode_config.property_list without locking and publishes it in
dev->mode_config.object_idr before initializing its fields and enum_list,
allowing a concurrent drm_mode_getproperty_ioctl() to observe an
uninitialized property. Finally, drm_connector_cleanup() does not destroy
connector->max_bpc_property or connector->color_format_property, so those
properties and their mode object IDs are leaked if
drm_connector_attach_color_format_property() fails or each time an HDMI
connector is hot-unplugged and re-plugged.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=6
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 07/32] drm/display: bridge-connector: split allocation code from initialization code
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (5 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 06/32] drm/connector: add drm_connector_hdmi_dynamic_init() Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 08/32] drm/display: bridge-connector: hoist error management to common code Luca Ceresoli
` (24 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Currently drm_bridge_connector_init() does two things:
* allocate and initialize the drm_bridge_connector
(which embeds a drm_connector) using drmm
* initialize and register the embedded drm_connector
For bridge hotplug drmm allocations are not suitable because a connector
may have to be added and removed multiple times in the lifetime of a card.
In preparation to support that, split out from drm_bridge_connector_init()
the code to allocate the drm_bridge_connector, so new (de)allocation code
can reuse all the initialization code.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- Slightly tweak commit title
---
drivers/gpu/drm/display/drm_bridge_connector.c | 62 ++++++++++++++++----------
1 file changed, 38 insertions(+), 24 deletions(-)
diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c
index 2202e6044444..19cacae617dc 100644
--- a/drivers/gpu/drm/display/drm_bridge_connector.c
+++ b/drivers/gpu/drm/display/drm_bridge_connector.c
@@ -837,27 +837,11 @@ static void drm_bridge_connector_put_bridges(struct drm_device *dev, void *data)
drm_bridge_put(bridge_connector->bridge_hdmi_cec);
}
-/**
- * drm_bridge_connector_init - Initialise a connector for a chain of bridges
- * @drm: the DRM device
- * @encoder: the encoder where the bridge chain starts
- *
- * Create a new &drm_bridge_connector for the @drm device. The connector is
- * allocated, initialised, registered with the @drm device and attached to
- * @encoder.
- *
- * The connector is associated with a chain of bridges that starts at
- * the @encoder. All bridges in the chain shall report bridge operation flags
- * (&drm_bridge->ops) and bridge output type (&drm_bridge->type), and none of
- * them may create a DRM connector directly.
- *
- * Returns a pointer to the new connector on success, or a negative error
- * pointer otherwise.
- */
-struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
- struct drm_encoder *encoder)
+static struct drm_connector *
+drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
+ struct drm_device *drm,
+ struct drm_encoder *encoder)
{
- struct drm_bridge_connector *bridge_connector;
struct drm_connector *connector;
struct i2c_adapter *ddc = NULL;
struct drm_bridge *panel_bridge __free(drm_bridge_put) = NULL;
@@ -865,10 +849,6 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
int connector_type;
int ret;
- bridge_connector = drmm_kzalloc(drm, sizeof(*bridge_connector), GFP_KERNEL);
- if (!bridge_connector)
- return ERR_PTR(-ENOMEM);
-
ret = drmm_add_action(drm, drm_bridge_connector_put_bridges, bridge_connector);
if (ret)
return ERR_PTR(ret);
@@ -1154,4 +1134,38 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
return connector;
}
+
+/**
+ * drm_bridge_connector_init - Initialise a connector for a chain of bridges
+ * @drm: the DRM device
+ * @encoder: the encoder where the bridge chain starts
+ *
+ * Create a new &drm_bridge_connector for the @drm device. The connector is
+ * allocated, initialised, registered with the @drm device and attached to
+ * @encoder.
+ *
+ * The connector is associated with a chain of bridges that starts at
+ * the @encoder. All bridges in the chain shall report bridge operation flags
+ * (&drm_bridge->ops) and bridge output type (&drm_bridge->type), and none of
+ * them may create a DRM connector directly.
+ *
+ * Returns a pointer to the new connector on success, or a negative error
+ * pointer otherwise.
+ */
+struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
+ struct drm_encoder *encoder)
+{
+ struct drm_bridge_connector *bridge_connector;
+ struct drm_connector *connector;
+
+ bridge_connector = drmm_kzalloc(drm, sizeof(*bridge_connector), GFP_KERNEL);
+ if (!bridge_connector)
+ return ERR_PTR(-ENOMEM);
+
+ connector = drm_bridge_connector_initialize(bridge_connector, drm, encoder);
+ if (IS_ERR(connector))
+ return connector;
+
+ return connector;
+}
EXPORT_SYMBOL_GPL(drm_bridge_connector_init);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 08/32] drm/display: bridge-connector: hoist error management to common code
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (6 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 07/32] drm/display: bridge-connector: split allocation code from initialization code Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:03 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 09/32] drm/display: bridge-connector: use a dynamic connector Luca Ceresoli
` (23 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
In prepataion to add more error management code common to the HDMI and
non-HDMI branches, move error management to be common to both cases.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/display/drm_bridge_connector.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c
index 19cacae617dc..f4a71801e8a3 100644
--- a/drivers/gpu/drm/display/drm_bridge_connector.c
+++ b/drivers/gpu/drm/display/drm_bridge_connector.c
@@ -1057,15 +1057,13 @@ drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
&drm_bridge_connector_funcs,
&bridge_connector->hdmi_funcs,
connector_type, ddc);
- if (ret)
- return ERR_PTR(ret);
} else {
ret = drmm_connector_init(drm, connector,
&drm_bridge_connector_funcs,
connector_type, ddc);
- if (ret)
- return ERR_PTR(ret);
}
+ if (ret)
+ return ret;
if (bridge_connector->bridge_hdmi_audio ||
bridge_connector->bridge_dp_audio) {
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 08/32] drm/display: bridge-connector: hoist error management to common code
2026-11-25 17:50 ` [PATCH v4 08/32] drm/display: bridge-connector: hoist error management to common code Luca Ceresoli
@ 2026-11-25 18:03 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:03 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/bridge-connector: int return in
drm_bridge_connector_initialize()
--
commit a701ba5bb1c19c7b9fcfc98010ada24b2c5ec042
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/display: bridge-connector: hoist error management to common code
This commit moves the error check for drmm_connector_hdmi_init() and
drmm_connector_init() out of the if/else branches in
drm_bridge_connector_initialize().
> diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c
> index 19cacae617dce..f4a71801e8a3b 100644
> --- a/drivers/gpu/drm/display/drm_bridge_connector.c
> +++ b/drivers/gpu/drm/display/drm_bridge_connector.c
> @@ -1057,15 +1057,13 @@ drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
> &drm_bridge_connector_funcs,
> &bridge_connector->hdmi_funcs,
> connector_type, ddc);
> - if (ret)
> - return ERR_PTR(ret);
> } else {
> ret = drmm_connector_init(drm, connector,
> &drm_bridge_connector_funcs,
> connector_type, ddc);
> - if (ret)
> - return ERR_PTR(ret);
> }
> + if (ret)
> + return ret;
[Severity: High]
Should this return ERR_PTR(ret) instead of ret?
drm_bridge_connector_initialize() returns a struct drm_connector *, so
returning an int fails to build with -Werror=int-conversion (and breaks
git bisect before commit "drm/display: bridge-connector: use a dynamic
connector" restores ERR_PTR(ret) later in the series).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=8
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 09/32] drm/display: bridge-connector: use a dynamic connector
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (7 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 08/32] drm/display: bridge-connector: hoist error management to common code Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:21 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 10/32] drm/display: bridge-connector: add APIs to add/remove the connector dynamically Luca Ceresoli
` (22 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Currently the drm_bridge_connector uses drmm functions to add the
drm_connector. For bridge hotplug drmm allocations are not suitable because
a connector may have to be added and removed multiple times in the lifetime
of a card.
In preparation for bridge hotplug, use the dynamic variants of
drm_connector[_hdmi]_init() and the non-drmm versions of
drmm_connector_hdmi_cec[_notifier]_register() so the drm_connector can be
removed without removing the whole card.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v4:
- Add fwnode_handle_put(connector->fwnode) to fix OF node leak if the OF
node is removed by a DT overlay
Changes in v3:
- convert CEC code to non-drmm too
- fix connector state error management
- put the connector on error paths after the dynamic_init() step
- fix drmm-allocation leak on drm_bridge_connector_init() error path
---
drivers/gpu/drm/display/drm_bridge_connector.c | 149 ++++++++++++++++++-------
1 file changed, 110 insertions(+), 39 deletions(-)
diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c
index f4a71801e8a3..d81cfc7aa295 100644
--- a/drivers/gpu/drm/display/drm_bridge_connector.c
+++ b/drivers/gpu/drm/display/drm_bridge_connector.c
@@ -132,11 +132,27 @@ struct drm_bridge_connector {
* bridge connector.
*/
struct drm_connector_hdmi_funcs hdmi_funcs;
+ /** @has_cec_adapter: true if a CEC adapter is registered */
+ bool has_cec_adapter;
+ /** @has_cec_notifier true if a CEC notifier is registered */
+ bool has_cec_notifier;
};
#define to_drm_bridge_connector(x) \
container_of(x, struct drm_bridge_connector, base)
+static void drm_bridge_connector_put_bridges(struct drm_bridge_connector *bridge_connector)
+{
+ drm_bridge_put(bridge_connector->bridge_edid);
+ drm_bridge_put(bridge_connector->bridge_hpd);
+ drm_bridge_put(bridge_connector->bridge_detect);
+ drm_bridge_put(bridge_connector->bridge_modes);
+ drm_bridge_put(bridge_connector->bridge_hdmi);
+ drm_bridge_put(bridge_connector->bridge_hdmi_audio);
+ drm_bridge_put(bridge_connector->bridge_dp_audio);
+ drm_bridge_put(bridge_connector->bridge_hdmi_cec);
+}
+
/* -----------------------------------------------------------------------------
* Bridge Connector Hot-Plug Handling
*/
@@ -267,6 +283,14 @@ drm_bridge_connector_color_format(const struct drm_connector_state *conn_state)
return conn_state->color_format;
}
+static void drm_bridge_connector_dynconn_destroy(struct drm_connector *connector)
+{
+ struct drm_bridge_connector *bridge_connector = to_drm_bridge_connector(connector);
+
+ drm_connector_cleanup(connector);
+ drm_bridge_connector_put_bridges(bridge_connector);
+}
+
static const struct drm_connector_funcs drm_bridge_connector_funcs = {
.fill_modes = drm_helper_probe_single_connector_modes,
.atomic_create_state = drm_bridge_connector_create_state,
@@ -275,6 +299,7 @@ static const struct drm_connector_funcs drm_bridge_connector_funcs = {
.debugfs_init = drm_bridge_connector_debugfs_init,
.oob_hotplug_event = drm_bridge_connector_oob_hotplug_event,
.color_format = drm_bridge_connector_color_format,
+ .destroy = drm_bridge_connector_dynconn_destroy,
};
/* -----------------------------------------------------------------------------
@@ -823,20 +848,6 @@ static const struct drm_connector_hdmi_cec_funcs drm_bridge_connector_hdmi_cec_f
* Bridge Connector Initialisation
*/
-static void drm_bridge_connector_put_bridges(struct drm_device *dev, void *data)
-{
- struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)data;
-
- drm_bridge_put(bridge_connector->bridge_edid);
- drm_bridge_put(bridge_connector->bridge_hpd);
- drm_bridge_put(bridge_connector->bridge_detect);
- drm_bridge_put(bridge_connector->bridge_modes);
- drm_bridge_put(bridge_connector->bridge_hdmi);
- drm_bridge_put(bridge_connector->bridge_hdmi_audio);
- drm_bridge_put(bridge_connector->bridge_dp_audio);
- drm_bridge_put(bridge_connector->bridge_hdmi_cec);
-}
-
static struct drm_connector *
drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
struct drm_device *drm,
@@ -849,10 +860,6 @@ drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
int connector_type;
int ret;
- ret = drmm_add_action(drm, drm_bridge_connector_put_bridges, bridge_connector);
- if (ret)
- return ERR_PTR(ret);
-
bridge_connector->encoder = encoder;
/*
@@ -1053,17 +1060,21 @@ drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
drm_bridge_connector_scrambler_disable;
}
- ret = drmm_connector_hdmi_init(drm, connector,
- &drm_bridge_connector_funcs,
- &bridge_connector->hdmi_funcs,
- connector_type, ddc);
+ ret = drm_connector_hdmi_dynamic_init(drm, connector,
+ &drm_bridge_connector_funcs,
+ &bridge_connector->hdmi_funcs,
+ connector_type, ddc);
} else {
- ret = drmm_connector_init(drm, connector,
- &drm_bridge_connector_funcs,
- connector_type, ddc);
+ ret = drm_connector_dynamic_init(drm, connector,
+ &drm_bridge_connector_funcs,
+ connector_type, ddc);
+ }
+ if (ret) {
+ drm_bridge_connector_put_bridges(bridge_connector);
+ return ERR_PTR(ret);
}
- if (ret)
- return ret;
+
+ /* From now on the connector is referenced and has to be put */
if (bridge_connector->bridge_hdmi_audio ||
bridge_connector->bridge_dp_audio) {
@@ -1084,35 +1095,48 @@ drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
bridge->hdmi_audio_spdif_playback,
bridge->hdmi_audio_dai_port);
if (ret)
- return ERR_PTR(ret);
+ goto err_put_connector;
}
if (bridge_connector->bridge_hdmi_cec &&
bridge_connector->bridge_hdmi_cec->ops & DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER) {
struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec;
- ret = drmm_connector_hdmi_cec_notifier_register(connector,
- NULL,
- bridge->hdmi_cec_dev);
+ ret = drm_connector_hdmi_cec_notifier_register(connector,
+ NULL,
+ bridge->hdmi_cec_dev);
if (ret)
- return ERR_PTR(ret);
+ goto err_put_connector;
+
+ bridge_connector->has_cec_notifier = true;
}
if (bridge_connector->bridge_hdmi_cec &&
bridge_connector->bridge_hdmi_cec->ops & DRM_BRIDGE_OP_HDMI_CEC_ADAPTER) {
struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec;
- ret = drmm_connector_hdmi_cec_register(connector,
- &drm_bridge_connector_hdmi_cec_funcs,
- bridge->hdmi_cec_adapter_name,
- bridge->hdmi_cec_available_las,
- bridge->hdmi_cec_dev);
+ ret = drm_connector_hdmi_cec_register(connector,
+ &drm_bridge_connector_hdmi_cec_funcs,
+ bridge->hdmi_cec_adapter_name,
+ bridge->hdmi_cec_available_las,
+ bridge->hdmi_cec_dev);
if (ret)
- return ERR_PTR(ret);
+ goto err_unregister_cec_notifier;
+
+ bridge_connector->has_cec_adapter = true;
}
drm_connector_helper_add(connector, &drm_bridge_connector_helper_funcs);
+ if (!connector->state) {
+ struct drm_connector_state *state = drm_bridge_connector_create_state(connector);
+ if (IS_ERR(state)) {
+ ret = PTR_ERR(state);
+ goto err_unregister_cec_adapter;
+ }
+ connector->state = state;
+ }
+
if (bridge_connector->bridge_hpd)
connector->polled = DRM_CONNECTOR_POLL_HPD;
else if (bridge_connector->bridge_detect)
@@ -1128,9 +1152,51 @@ drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
ret = drm_connector_attach_encoder(connector, encoder);
if (ret)
- return ERR_PTR(ret);
+ goto err_unregister_cec_adapter;
+
+ ret = drm_connector_dynamic_register(connector);
+ if (ret)
+ goto err_unregister_cec_adapter;
return connector;
+
+err_unregister_cec_adapter:
+ if (bridge_connector->has_cec_adapter)
+ drm_connector_hdmi_cec_unregister(connector);
+err_unregister_cec_notifier:
+ if (bridge_connector->has_cec_notifier)
+ drm_connector_hdmi_cec_notifier_unregister(connector);
+err_put_connector:
+ drm_connector_put(connector);
+
+ return ERR_PTR(ret);
+}
+
+static void drm_bridge_connector_fini(struct drm_bridge_connector *bridge_connector)
+{
+ struct drm_connector *connector = &bridge_connector->base;
+
+ drm_connector_unregister(connector);
+ if (bridge_connector->has_cec_adapter)
+ drm_connector_hdmi_cec_unregister(connector);
+ if (bridge_connector->has_cec_notifier)
+ drm_connector_hdmi_cec_notifier_unregister(connector);
+
+#ifdef CONFIG_OF
+ if (connector->fwnode) {
+ fwnode_handle_put(connector->fwnode);
+ connector->fwnode = NULL;
+ }
+#endif
+
+ drm_connector_put(connector);
+}
+
+static void drmm_bridge_connector_fini(struct drm_device *dev, void *res)
+{
+ struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)res;
+
+ drm_bridge_connector_fini(bridge_connector);
}
/**
@@ -1155,6 +1221,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
{
struct drm_bridge_connector *bridge_connector;
struct drm_connector *connector;
+ int ret;
bridge_connector = drmm_kzalloc(drm, sizeof(*bridge_connector), GFP_KERNEL);
if (!bridge_connector)
@@ -1164,6 +1231,10 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
if (IS_ERR(connector))
return connector;
+ ret = drmm_add_action_or_reset(drm, drmm_bridge_connector_fini, bridge_connector);
+ if (ret)
+ return ERR_PTR(ret);
+
return connector;
}
EXPORT_SYMBOL_GPL(drm_bridge_connector_init);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 09/32] drm/display: bridge-connector: use a dynamic connector
2026-11-25 17:50 ` [PATCH v4 09/32] drm/display: bridge-connector: use a dynamic connector Luca Ceresoli
@ 2026-11-25 18:21 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:21 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/display: bridge-connector: double teardown in
drmm_bridge_connector_fini()
- [Medium] drm/display: bridge-connector: reference leaks in
drm_bridge_connector_initialize()
- [Low] drm/display: bridge-connector: missing colon in
@has_cec_notifier kernel-doc
--
commit 17489de6cf9da07d5d4da90bca09f1c4add46b17
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/display: bridge-connector: use a dynamic connector
This commit switches drm_bridge_connector initialization from drmm-managed
connector and CEC helpers to dynamic connector initialization and explicit
teardown in preparation for bridge hotplug.
> diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c
> index f4a71801e8a3b..d81cfc7aa295b 100644
> --- a/drivers/gpu/drm/display/drm_bridge_connector.c
> +++ b/drivers/gpu/drm/display/drm_bridge_connector.c
> @@ -132,11 +132,27 @@ struct drm_bridge_connector {
> * bridge connector.
> */
> struct drm_connector_hdmi_funcs hdmi_funcs;
> + /** @has_cec_adapter: true if a CEC adapter is registered */
> + bool has_cec_adapter;
> + /** @has_cec_notifier true if a CEC notifier is registered */
> + bool has_cec_notifier;
> };
[Severity: Low]
A colon is missing after @has_cec_notifier, which triggers a kernel-doc
warning for struct drm_bridge_connector.
[ ... ]
> @@ -849,10 +860,6 @@ drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
> int connector_type;
> int ret;
>
> - ret = drmm_add_action(drm, drm_bridge_connector_put_bridges, bridge_connector);
> - if (ret)
> - return ERR_PTR(ret);
> -
> bridge_connector->encoder = encoder;
>
> /*
> @@ -1053,17 +1060,21 @@ drm_bridge_connector_initialize(struct drm_bridge_connector *bridge_connector,
> drm_bridge_connector_scrambler_disable;
> }
>
> - ret = drmm_connector_hdmi_init(drm, connector,
> - &drm_bridge_connector_funcs,
> - &bridge_connector->hdmi_funcs,
> - connector_type, ddc);
> + ret = drm_connector_hdmi_dynamic_init(drm, connector,
> + &drm_bridge_connector_funcs,
> + &bridge_connector->hdmi_funcs,
> + connector_type, ddc);
> } else {
> - ret = drmm_connector_init(drm, connector,
> - &drm_bridge_connector_funcs,
> - connector_type, ddc);
> + ret = drm_connector_dynamic_init(drm, connector,
> + &drm_bridge_connector_funcs,
> + connector_type, ddc);
> + }
> + if (ret) {
> + drm_bridge_connector_put_bridges(bridge_connector);
> + return ERR_PTR(ret);
> }
> - if (ret)
> - return ret;
> +
> + /* From now on the connector is referenced and has to be put */
[Severity: Medium]
Does removing the upfront drmm_add_action() leak bridge_connector->bridge_*
and connector->fwnode references when drm_bridge_connector_initialize()
fails earlier?
During drm_for_each_bridge_in_chain(), the loop acquires references with
drm_bridge_get() and fwnode_handle_get(), but any early return inside the
loop or at the connector_type == DRM_MODE_CONNECTOR_Unknown check returns
directly without calling drm_bridge_connector_put_bridges() or
fwnode_handle_put(connector->fwnode). In addition, if
drm_connector_dynamic_init() fails (or drm_connector_hdmi_dynamic_init()
fails before reaching drm_connector_cleanup()), the error block above puts
the bridges but still leaks connector->fwnode.
[ ... ]
> +static void drm_bridge_connector_fini(struct drm_bridge_connector *bridge_connector)
> +{
> + struct drm_connector *connector = &bridge_connector->base;
> +
> + drm_connector_unregister(connector);
> + if (bridge_connector->has_cec_adapter)
> + drm_connector_hdmi_cec_unregister(connector);
> + if (bridge_connector->has_cec_notifier)
> + drm_connector_hdmi_cec_notifier_unregister(connector);
> +
> +#ifdef CONFIG_OF
> + if (connector->fwnode) {
> + fwnode_handle_put(connector->fwnode);
> + connector->fwnode = NULL;
> + }
> +#endif
> +
> + drm_connector_put(connector);
> +}
> +
> +static void drmm_bridge_connector_fini(struct drm_device *dev, void *res)
> +{
> + struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)res;
> +
> + drm_bridge_connector_fini(bridge_connector);
> }
>
> /**
> @@ -1155,6 +1221,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
> {
> struct drm_bridge_connector *bridge_connector;
> struct drm_connector *connector;
> + int ret;
>
> bridge_connector = drmm_kzalloc(drm, sizeof(*bridge_connector), GFP_KERNEL);
> if (!bridge_connector)
> @@ -1164,6 +1231,10 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
> if (IS_ERR(connector))
> return connector;
>
> + ret = drmm_add_action_or_reset(drm, drmm_bridge_connector_fini, bridge_connector);
> + if (ret)
> + return ERR_PTR(ret);
> +
> return connector;
> }
[Severity: High]
Can drmm_bridge_connector_fini() tear down a connector that has already
been destroyed by drm_mode_config_cleanup()?
Drivers such as omapdrm, tegra, exynos, imx/dcss and kmb create connectors
with drm_bridge_connector_init() and explicitly call
drm_mode_config_cleanup() before drm_dev_put(). Because the connector is
on dev->mode_config.connector_list with a single reference,
drm_mode_config_cleanup() drops that reference and flushes
connector_free_work, running drm_bridge_connector_dynconn_destroy() ->
drm_connector_cleanup(), which destroys connector->mutex and zeroes
*connector (including connector->cec.data). When drm_dev_put() then runs
drmm_bridge_connector_fini(), drm_connector_unregister() locks the
destroyed connector->mutex and drm_connector_hdmi_cec_unregister()
dereferences NULL connector->cec.data; once commit "drm/display:
bridge-connector: add APIs to add/remove the connector dynamically" adds
kfree(bridge_connector) to drm_bridge_connector_dynconn_destroy(),
drmm_bridge_connector_fini() also becomes a use-after-free on
bridge_connector.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=9
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 10/32] drm/display: bridge-connector: add APIs to add/remove the connector dynamically
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (8 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 09/32] drm/display: bridge-connector: use a dynamic connector Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:14 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 11/32] drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter Luca Ceresoli
` (21 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
drm_bridge_connector_init() adds a drmm-allocated connector. For bridge
hotplug drmm allocations are not suitable because a connector may have to
be added and removed multiple times in the lifetime of a card.
In preparation for bridge hotplug, add APIs to add and remove a connector
using regular non-managed allocations.
For the dynamic connector, this requires the kfree() the allocated struct
drm_bridge_connector in the destroy func. However that func will be called
even when using the pre-existing drmm API, leading to a double free
(kfree() in the destroy callback + drmm).
One option to avoid this issue is introducing two mostly identical
drm_connector_funcs instances, one with .destroy and one without. But that
would be an annoying code duplication. Instead take a different approach:
always allocate using non-drmm kzalloc_obj(), so that deallocation always
happen in destroy->kfree().
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Uhm, maybe the change from drmm_kzalloc to kzalloc_obj and addition of
kfree to the destroy callback should eb a separate commit?
---
drivers/gpu/drm/display/drm_bridge_connector.c | 24 +++++++++++++++++++++++-
include/drm/drm_bridge_connector.h | 4 ++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c
index d81cfc7aa295..07385f87b2e8 100644
--- a/drivers/gpu/drm/display/drm_bridge_connector.c
+++ b/drivers/gpu/drm/display/drm_bridge_connector.c
@@ -289,6 +289,7 @@ static void drm_bridge_connector_dynconn_destroy(struct drm_connector *connector
drm_connector_cleanup(connector);
drm_bridge_connector_put_bridges(bridge_connector);
+ kfree(bridge_connector);
}
static const struct drm_connector_funcs drm_bridge_connector_funcs = {
@@ -1223,7 +1224,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
struct drm_connector *connector;
int ret;
- bridge_connector = drmm_kzalloc(drm, sizeof(*bridge_connector), GFP_KERNEL);
+ bridge_connector = kzalloc_obj(*bridge_connector);
if (!bridge_connector)
return ERR_PTR(-ENOMEM);
@@ -1238,3 +1239,24 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
return connector;
}
EXPORT_SYMBOL_GPL(drm_bridge_connector_init);
+
+struct drm_connector *drm_bridge_connector_dynamic_add(struct drm_device *drm,
+ struct drm_encoder *encoder)
+{
+ struct drm_bridge_connector *bridge_connector;
+
+ bridge_connector = kzalloc_obj(*bridge_connector);
+ if (!bridge_connector)
+ return ERR_PTR(-ENOMEM);
+
+ return drm_bridge_connector_initialize(bridge_connector, drm, encoder);
+}
+EXPORT_SYMBOL_GPL(drm_bridge_connector_dynamic_add);
+
+void drm_bridge_connector_dynamic_remove(struct drm_connector *connector)
+{
+ struct drm_bridge_connector *bridge_connector = to_drm_bridge_connector(connector);
+
+ drm_bridge_connector_fini(bridge_connector);
+}
+EXPORT_SYMBOL_GPL(drm_bridge_connector_dynamic_remove);
diff --git a/include/drm/drm_bridge_connector.h b/include/drm/drm_bridge_connector.h
index 69630815fb09..de6ec91dbfab 100644
--- a/include/drm/drm_bridge_connector.h
+++ b/include/drm/drm_bridge_connector.h
@@ -9,8 +9,12 @@
struct drm_connector;
struct drm_device;
struct drm_encoder;
+struct drm_bridge_connector;
struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
struct drm_encoder *encoder);
+struct drm_connector *drm_bridge_connector_dynamic_add(struct drm_device *drm,
+ struct drm_encoder *encoder);
+void drm_bridge_connector_dynamic_remove(struct drm_connector *connector);
#endif /* __DRM_BRIDGE_CONNECTOR_H__ */
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 10/32] drm/display: bridge-connector: add APIs to add/remove the connector dynamically
2026-11-25 17:50 ` [PATCH v4 10/32] drm/display: bridge-connector: add APIs to add/remove the connector dynamically Luca Ceresoli
@ 2026-11-25 18:14 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:14 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/display: bridge_connector UAF when mode_config cleanup
precedes drmm
- [Medium] drm/display: bridge_connector memory leak on early init
failure
- [Medium] drm/display: bridge and fwnode ref leaks in
drm_bridge_connector_initialize()
- [Low] drm/display: missing kernel-doc, unused forward decl, and
duplicated init
--
commit a02e04d142ea4a8a0fe3098841fdb782ae21bfc9
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/display: bridge-connector: add APIs to add/remove the connector dynamically
This commit switches drm_bridge_connector allocation from drmm_kzalloc() to
kzalloc_obj() freed in the connector destroy callback, and adds
drm_bridge_connector_dynamic_add() and drm_bridge_connector_dynamic_remove().
> diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c
> index d81cfc7aa295b..07385f87b2e8d 100644
> --- a/drivers/gpu/drm/display/drm_bridge_connector.c
> +++ b/drivers/gpu/drm/display/drm_bridge_connector.c
> @@ -289,6 +289,7 @@ static void drm_bridge_connector_dynconn_destroy(struct drm_connector *connector
>
> drm_connector_cleanup(connector);
> drm_bridge_connector_put_bridges(bridge_connector);
> + kfree(bridge_connector);
> }
>
> static const struct drm_connector_funcs drm_bridge_connector_funcs = {
[Severity: High]
Can freeing bridge_connector in drm_bridge_connector_dynconn_destroy() cause
a use-after-free in drmm_bridge_connector_fini() when a driver using
drm_bridge_connector_init() runs drm_mode_config_cleanup() before
drm_dev_put()?
drm_bridge_connector_init() registers drmm_bridge_connector_fini() with a raw
bridge_connector pointer without taking an extra connector reference.
Drivers such as omapdrm (in omapdrm_cleanup()) and imx/dcss (in
dcss_kms_detach()) call drm_mode_config_cleanup() before drm_dev_put().
drm_mode_config_cleanup() drops the connector's sole reference and flushes
connector_free_work, invoking drm_bridge_connector_dynconn_destroy() and
freeing bridge_connector. When drm_dev_put() later runs drmm actions,
drmm_bridge_connector_fini() calls drm_bridge_connector_fini() on the freed
bridge_connector, locking the destroyed connector->mutex and calling
drm_connector_put() on freed memory.
Conversely, when drmm_mode_config_init() is used so that
drmm_bridge_connector_fini() runs before drm_mode_config_cleanup(), if the
connector is still bound to an active CRTC (refcount 2),
drmm_bridge_connector_fini() only drops the refcount to 1.
drm_mode_config_cleanup() then drops the remaining reference from 1 to 0,
and drm_connector_cleanup() -> __drm_atomic_helper_connector_destroy_state()
calls drm_connector_put(state->connector) on a connector whose refcount is
already 0.
> @@ -1223,7 +1224,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
> struct drm_connector *connector;
> int ret;
>
> - bridge_connector = drmm_kzalloc(drm, sizeof(*bridge_connector), GFP_KERNEL);
> + bridge_connector = kzalloc_obj(*bridge_connector);
> if (!bridge_connector)
> return ERR_PTR(-ENOMEM);
>
> @@ -1238,3 +1239,24 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
> return connector;
> }
> EXPORT_SYMBOL_GPL(drm_bridge_connector_init);
[Severity: Medium]
Does switching from drmm_kzalloc() to kzalloc_obj() leak bridge_connector in
both drm_bridge_connector_init() and drm_bridge_connector_dynamic_add() when
drm_bridge_connector_initialize() fails before connector initialization
succeeds?
kfree(bridge_connector) is only called in
drm_bridge_connector_dynconn_destroy() via drm_connector_put(). If
drm_bridge_connector_initialize() returns an error during bridge chain
inspection, when connector_type is DRM_MODE_CONNECTOR_Unknown, or when
drm_connector_hdmi_dynamic_init() / drm_connector_dynamic_init() fails:
drivers/gpu/drm/display/drm_bridge_connector.c:drm_bridge_connector_initialize() {
...
if (ret) {
drm_bridge_connector_put_bridges(bridge_connector);
return ERR_PTR(ret);
}
...
}
drm_connector_put() is never called on those paths, so bridge_connector is
never freed.
> +
> +struct drm_connector *drm_bridge_connector_dynamic_add(struct drm_device *drm,
> + struct drm_encoder *encoder)
> +{
> + struct drm_bridge_connector *bridge_connector;
> +
> + bridge_connector = kzalloc_obj(*bridge_connector);
> + if (!bridge_connector)
> + return ERR_PTR(-ENOMEM);
> +
> + return drm_bridge_connector_initialize(bridge_connector, drm, encoder);
> +}
> +EXPORT_SYMBOL_GPL(drm_bridge_connector_dynamic_add);
[Severity: Medium]
Does drm_bridge_connector_initialize() also leak bridge and fwnode references
on its early error paths?
During the drm_for_each_bridge_in_chain() loop,
drm_bridge_connector_initialize() takes references with drm_bridge_get() and
fwnode_handle_get(), but returns ERR_PTR() directly on validation errors or
when connector_type == DRM_MODE_CONNECTOR_Unknown without calling
drm_bridge_connector_put_bridges() or fwnode_handle_put(connector->fwnode):
drivers/gpu/drm/display/drm_bridge_connector.c:drm_bridge_connector_initialize() {
...
if (bridge->ops & DRM_BRIDGE_OP_HDMI_CEC_ADAPTER) {
if (bridge_connector->bridge_hdmi_cec)
return ERR_PTR(-EBUSY);
bridge_connector->bridge_hdmi_cec = drm_bridge_get(bridge);
if (!bridge->funcs->hdmi_cec_enable ||
!bridge->funcs->hdmi_cec_log_addr ||
!bridge->funcs->hdmi_cec_transmit)
return ERR_PTR(-EINVAL);
}
...
#ifdef CONFIG_OF
if (drm_bridge_is_last(bridge) && bridge->of_node)
connector->fwnode = fwnode_handle_get(of_fwnode_handle(bridge->of_node));
#endif
...
}
if (connector_type == DRM_MODE_CONNECTOR_Unknown)
return ERR_PTR(-EINVAL);
...
}
In addition, if drm_connector_dynamic_init() or
drm_connector_hdmi_dynamic_init() fails before drm_connector_cleanup() can
run, the error block calls drm_bridge_connector_put_bridges() but still leaks
connector->fwnode.
> diff --git a/include/drm/drm_bridge_connector.h b/include/drm/drm_bridge_connector.h
> index 69630815fb093..de6ec91dbfabd 100644
> --- a/include/drm/drm_bridge_connector.h
> +++ b/include/drm/drm_bridge_connector.h
> @@ -9,8 +9,12 @@
> struct drm_connector;
> struct drm_device;
> struct drm_encoder;
> +struct drm_bridge_connector;
>
> struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
> struct drm_encoder *encoder);
> +struct drm_connector *drm_bridge_connector_dynamic_add(struct drm_device *drm,
> + struct drm_encoder *encoder);
> +void drm_bridge_connector_dynamic_remove(struct drm_connector *connector);
>
> #endif /* __DRM_BRIDGE_CONNECTOR_H__ */
[Severity: Low]
This isn't a bug, but struct drm_bridge_connector is internal to
drm_bridge_connector.c and unused in this header. Also,
Documentation/gpu/drm-kms-helpers.rst pulls in drm_bridge_connector.c with
the :export: directive, so the newly exported
drm_bridge_connector_dynamic_add() and drm_bridge_connector_dynamic_remove()
functions should have kernel-doc comments, and drm_bridge_connector_init()
could call drm_bridge_connector_dynamic_add() (or move the allocation into
drm_bridge_connector_initialize()) to avoid duplicating the allocation and
initialization sequence.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=10
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 11/32] drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (9 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 10/32] drm/display: bridge-connector: add APIs to add/remove the connector dynamically Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:59 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 12/32] drm/bridge: initialize chain_node list head on allocation Luca Ceresoli
` (20 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
The @np argument does not need to be modified. Similarly to what
of_drm_get_bridge_by_endpoint() already does, make it const. This allows
passing a const pointer.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
New patch in v3, needed for the v3 code of "drm: drm_hotplug_helper: new
helper to implement bridge hotplug"
---
drivers/gpu/drm/drm_bridge.c | 2 +-
include/drm/drm_bridge.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 3cd6757dffb8..76242165292f 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -1663,7 +1663,7 @@ EXPORT_SYMBOL_GPL(drm_bridge_hpd_notify);
* RETURNS:
* drm_bridge control struct on success, NULL on failure
*/
-struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np)
+struct drm_bridge *of_drm_find_and_get_bridge(const struct device_node *np)
{
struct drm_bridge *bridge;
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index 12ca7f6fb524..d6ef020c4cc9 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -1274,7 +1274,7 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
enum drm_bridge_attach_flags flags);
#ifdef CONFIG_OF
-struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np);
+struct drm_bridge *of_drm_find_and_get_bridge(const 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);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 11/32] drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter
2026-11-25 17:50 ` [PATCH v4 11/32] drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter Luca Ceresoli
@ 2026-11-25 17:59 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 17:59 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/bridge: non-const np in !CONFIG_OF
of_drm_find_and_get_bridge() stub
--
commit 7679a18d386b4f07d4526f35667dbb513f3a913d
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter
This commit changes the device_node parameter of
of_drm_find_and_get_bridge() to const so callers can pass a const pointer.
> diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
> index 12ca7f6fb5243..d6ef020c4cc9b 100644
> --- a/include/drm/drm_bridge.h
> +++ b/include/drm/drm_bridge.h
> @@ -1274,7 +1274,7 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
> enum drm_bridge_attach_flags flags);
>
> #ifdef CONFIG_OF
> -struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np);
> +struct drm_bridge *of_drm_find_and_get_bridge(const 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);
[Severity: Low]
Should the !CONFIG_OF stub of of_drm_find_and_get_bridge() in the #else
branch right below also take a const struct device_node *np?
include/drm/drm_bridge.h:
#else
static inline struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np)
{
return NULL;
}
Without const on the stub, passing a const struct device_node * in a
!CONFIG_OF build fails to compile with a discarded-qualifiers error.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=11
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 12/32] drm/bridge: initialize chain_node list head on allocation
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (10 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 11/32] drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 13/32] drm/bridge: initialize chain_node list head on detach and attach errors Luca Ceresoli
` (19 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
In preparation to add a check to detect whether a bridge is not yet
attached, ensure the chain_node list_head is always empty [as in
list_empty()] since it is allocated, until it is attached.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/drm_bridge.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 76242165292f..14ed4ac52e71 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -419,6 +419,7 @@ void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,
return ERR_PTR(-ENOMEM);
bridge = container + offset;
+ INIT_LIST_HEAD(&bridge->chain_node);
INIT_LIST_HEAD(&bridge->list);
bridge->container = container;
bridge->funcs = funcs;
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 13/32] drm/bridge: initialize chain_node list head on detach and attach errors
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (11 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 12/32] drm/bridge: initialize chain_node list head on allocation Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug Luca Ceresoli
` (18 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
When a bridge is detached it is removed from the encoder bridge_chain list,
but the bridge::chain_node list head is not cleared. This is going to be
problematic with the upcoming hotplug bridge support because if a bridge is
detached from the encoder chain but not yet removed, when later detaching
it the encoder code may think it is still attached, thus trying to detach
it twice.
Avoid this by clearing the list head on detach, so there's a clear and
simple way to know when a bridge is not attached anymore.
Do the same in the error management code in drm_bridge_attach(), so that
chain_node is always empty [as in list_empty()] when it is not
(yet|anymore) in the bridge chain.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/drm_bridge.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 14ed4ac52e71..310f03bdb744 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -679,7 +679,7 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
bridge->dev = NULL;
bridge->encoder = NULL;
mutex_lock(&encoder->bridge_chain_mutex);
- list_del(&bridge->chain_node);
+ list_del_init(&bridge->chain_node);
mutex_unlock(&encoder->bridge_chain_mutex);
if (ret != -EPROBE_DEFER)
@@ -709,7 +709,7 @@ void drm_bridge_detach(struct drm_bridge *bridge)
if (bridge->funcs->detach)
bridge->funcs->detach(bridge);
- list_del(&bridge->chain_node);
+ list_del_init(&bridge->chain_node);
bridge->dev = NULL;
drm_bridge_put(bridge);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (12 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 13/32] drm/bridge: initialize chain_node list head on detach and attach errors Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:16 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 15/32] drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list Luca Ceresoli
` (17 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
To support hot-unplug of this bridge we need to protect access to device
resources in case device removal happens concurrently to other code.
Some care is needed for the case when drm_bridge_unplug() happens before
ti_sn_bridge_atomic_post_disable(), so the latter cannot release supplier
resources taken by ti_sn_bridge_atomic_pre_enable(): runtime PM (and in
turn regulators) and refclk.
To ensure those resources are released exactly once on device removal:
* move the code to release them to a dedicated function
* register that function when the resources are taken in
ti_sn_bridge_atomic_pre_enable()
* if ti_sn_bridge_atomic_post_disable() happens before drm_bridge_unplug()
(typical non-hot-unplug case):
* ti_sn_bridge_atomic_post_disable() can enter the critical section
(drm_bridge_enter() returns 0) -> it releases and executes the
devres action
* if ti_sn_bridge_atomic_post_disable() happens after drm_bridge_unplug()
(typical hot-unplug case):
* ti_sn_bridge_remove() -> drm_bridge_unplug() defuses
ti_sn_bridge_atomic_post_disable() so it cannot execute the devres
action
* the devres action is executed just after ti_sn_bridge_remove()
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v4:
- protect from register access in ti_sn_bridge_detect() and
ti_sn_bridge_edid_read() too
New patch in v3
This commit basically replicates the same change done on the ti-sn65dsi83
driver, now upstream:
https://lore.kernel.org/all/20251112-drm-bridge-atomic-vs-remove-v3-2-85db717ce094@bootlin.com/
---
drivers/gpu/drm/bridge/ti-sn65dsi86.c | 74 +++++++++++++++++++++++++++++++----
1 file changed, 67 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
index 48b83df9aed6..38318113a534 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
@@ -827,9 +827,15 @@ static void ti_sn_bridge_atomic_disable(struct drm_bridge *bridge,
struct drm_atomic_commit *state)
{
struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
+ int idx;
+
+ if (!drm_bridge_enter(bridge, &idx))
+ return;
/* disable video stream */
regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE, 0);
+
+ drm_bridge_exit(idx);
}
static void ti_sn_bridge_set_dsi_rate(struct ti_sn65dsi86 *pdata,
@@ -1099,11 +1105,16 @@ static void ti_sn_bridge_atomic_enable(struct drm_bridge *bridge,
int ret = -EINVAL;
int max_dp_lanes;
unsigned int bpp;
+ int idx;
+
+ if (!drm_bridge_enter(bridge, &idx))
+ return;
connector = drm_atomic_get_new_connector_for_encoder(state,
bridge->encoder);
if (!connector) {
dev_err_ratelimited(pdata->dev, "Could not get the connector\n");
+ drm_bridge_exit(idx);
return;
}
@@ -1167,6 +1178,7 @@ static void ti_sn_bridge_atomic_enable(struct drm_bridge *bridge,
}
if (ret) {
DRM_DEV_ERROR(pdata->dev, "%s (%d)\n", last_err_str, ret);
+ drm_bridge_exit(idx);
return;
}
@@ -1176,26 +1188,57 @@ static void ti_sn_bridge_atomic_enable(struct drm_bridge *bridge,
/* enable video stream */
regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE,
VSTREAM_ENABLE);
+
+ drm_bridge_exit(idx);
+}
+
+/*
+ * Release resources taken by ti_sn_bridge_atomic_pre_enable().
+ *
+ * Invoked by ti_sn_bridge_atomic_post_disable() normally, or by devres
+ * after ti_sn_bridge_remove() in case this happens befora
+ * atomic_post_disable.
+ */
+static void ti_sn_bridge_release_resources(void *data)
+{
+ struct ti_sn65dsi86 *pdata = (struct ti_sn65dsi86 *)data;
+
+ if (!pdata->refclk)
+ ti_sn65dsi86_disable_comms(pdata);
+
+ pm_runtime_put_sync(pdata->dev);
}
static void ti_sn_bridge_atomic_pre_enable(struct drm_bridge *bridge,
struct drm_atomic_commit *state)
{
struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
+ int idx;
+
+ if (!drm_bridge_enter(bridge, &idx))
+ return;
pm_runtime_get_sync(pdata->dev);
if (!pdata->refclk)
ti_sn65dsi86_enable_comms(pdata, state);
+ devm_add_action(pdata->dev, ti_sn_bridge_release_resources, pdata);
+
/* td7: min 100 us after enable before DSI data */
usleep_range(100, 110);
+
+ drm_bridge_exit(idx);
}
static void ti_sn_bridge_atomic_post_disable(struct drm_bridge *bridge,
struct drm_atomic_commit *state)
{
struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
+ int idx;
+
+ if (!drm_bridge_enter(bridge, &idx))
+ return;
/* semi auto link training mode OFF */
regmap_write(pdata->regmap, SN_ML_TX_MODE_REG, 0);
@@ -1204,17 +1247,21 @@ static void ti_sn_bridge_atomic_post_disable(struct drm_bridge *bridge,
/* disable DP PLL */
regmap_write(pdata->regmap, SN_PLL_ENABLE_REG, 0);
- if (!pdata->refclk)
- ti_sn65dsi86_disable_comms(pdata);
+ devm_release_action(pdata->dev, ti_sn_bridge_release_resources, pdata);
- pm_runtime_put_sync(pdata->dev);
+ drm_bridge_exit(idx);
}
static enum drm_connector_status
ti_sn_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector)
{
struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
+ enum drm_connector_status status = connector_status_disconnected;
int val = 0;
+ int idx;
+
+ if (!drm_bridge_enter(bridge, &idx))
+ return status;
/*
* Runtime reference is grabbed in ti_sn_bridge_hpd_enable()
@@ -1225,16 +1272,29 @@ ti_sn_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector)
regmap_read(pdata->regmap, SN_HPD_DISABLE_REG, &val);
- return val & HPD_DEBOUNCED_STATE ? connector_status_connected
- : connector_status_disconnected;
+ status = val & HPD_DEBOUNCED_STATE ? connector_status_connected
+ : connector_status_disconnected;
+
+ drm_bridge_exit(idx);
+
+ return status;
}
static const struct drm_edid *ti_sn_bridge_edid_read(struct drm_bridge *bridge,
struct drm_connector *connector)
{
struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
+ const struct drm_edid *edid;
+ int idx;
- return drm_edid_read_ddc(connector, &pdata->aux.ddc);
+ if (!drm_bridge_enter(bridge, &idx))
+ return NULL;
+
+ edid = drm_edid_read_ddc(connector, &pdata->aux.ddc);
+
+ drm_bridge_exit(idx);
+
+ return edid;
}
static void ti_sn65dsi86_debugfs_init(struct drm_bridge *bridge, struct dentry *root)
@@ -1475,7 +1535,7 @@ static void ti_sn_bridge_remove(struct auxiliary_device *adev)
if (!pdata)
return;
- drm_bridge_remove(&pdata->bridge);
+ drm_bridge_unplug(&pdata->bridge);
of_node_put(pdata->host_node);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug
2026-11-25 17:50 ` [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug Luca Ceresoli
@ 2026-11-25 18:16 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:16 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/bridge: ti-sn65dsi86: release action registered on wrong
device
- [High] drm/bridge: ti-sn65dsi86: unprotected HPD and debugfs callbacks
on unplug
- [Medium] drm/bridge: unchecked devm_add_action() in
ti_sn_bridge_atomic_pre_enable()
--
commit c57970c3929d58f60b46d5db47153169c16eb129
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/bridge: ti-sn65dsi86: protect device resources on unplug
This commit wraps hardware accesses in bridge callbacks with
drm_bridge_enter() and drm_bridge_exit(), uses a devres action to release
resources acquired in ti_sn_bridge_atomic_pre_enable(), and switches
ti_sn_bridge_remove() to drm_bridge_unplug().
> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> index 48b83df9aed61..38318113a534f 100644
> --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
[ ... ]
> @@ -1176,26 +1188,57 @@ static void ti_sn_bridge_atomic_enable(struct drm_bridge *bridge,
[ ... ]
> +static void ti_sn_bridge_release_resources(void *data)
> +{
> + struct ti_sn65dsi86 *pdata = (struct ti_sn65dsi86 *)data;
> +
> + if (!pdata->refclk)
> + ti_sn65dsi86_disable_comms(pdata);
> +
> + pm_runtime_put_sync(pdata->dev);
> +}
>
> static void ti_sn_bridge_atomic_pre_enable(struct drm_bridge *bridge,
> struct drm_atomic_commit *state)
> {
> struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
> + int idx;
> +
> + if (!drm_bridge_enter(bridge, &idx))
> + return;
>
> pm_runtime_get_sync(pdata->dev);
>
> if (!pdata->refclk)
> ti_sn65dsi86_enable_comms(pdata, state);
>
> + devm_add_action(pdata->dev, ti_sn_bridge_release_resources, pdata);
[Severity: Medium]
Does an allocation failure in devm_add_action() leak the runtime PM
reference and comms state?
If devm_add_action() fails with -ENOMEM, ti_sn_bridge_release_resources()
is never queued, so a later ti_sn_bridge_atomic_post_disable() hits
WARN_ON(IS_ERR(dr)) in devm_release_action() and skips releasing the
resources. Using devm_add_action_or_reset() would run
ti_sn_bridge_release_resources() immediately on failure.
> +
> /* td7: min 100 us after enable before DSI data */
> usleep_range(100, 110);
> +
> + drm_bridge_exit(idx);
> }
>
> static void ti_sn_bridge_atomic_post_disable(struct drm_bridge *bridge,
> struct drm_atomic_commit *state)
> {
> struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
> + int idx;
> +
> + if (!drm_bridge_enter(bridge, &idx))
> + return;
>
> /* semi auto link training mode OFF */
> regmap_write(pdata->regmap, SN_ML_TX_MODE_REG, 0);
> @@ -1204,17 +1247,21 @@ static void ti_sn_bridge_atomic_post_disable(struct drm_bridge *bridge,
> /* disable DP PLL */
> regmap_write(pdata->regmap, SN_PLL_ENABLE_REG, 0);
>
> - if (!pdata->refclk)
> - ti_sn65dsi86_disable_comms(pdata);
> + devm_release_action(pdata->dev, ti_sn_bridge_release_resources, pdata);
[Severity: High]
Should ti_sn_bridge_release_resources() be registered on
&pdata->bridge_aux->dev instead of pdata->dev?
During probe, ti_sn_aux_probe() creates pdata->bridge_aux via
ti_sn65dsi86_add_aux_device() -> __devm_auxiliary_device_create(), which
queues auxiliary_device_destroy() on pdata->dev. When
ti_sn_bridge_atomic_pre_enable() later registers
ti_sn_bridge_release_resources() on pdata->dev at modeset time, that action
is queued after auxiliary_device_destroy().
Because devres_release_all(pdata->dev) runs actions in reverse order on
parent I2C device unbind, ti_sn_bridge_release_resources() drops the
runtime PM reference and powers down the bridge before
auxiliary_device_destroy() invokes ti_sn_bridge_remove() ->
drm_bridge_unplug(&pdata->bridge). Bridge callbacks can then still enter
drm_bridge_enter() while the chip is powered off, and a concurrent
ti_sn_bridge_atomic_post_disable() hits WARN_ON(IS_ERR(dr)) in
devm_release_action() once devres_release_all(pdata->dev) has detached the
action list.
Conversely, if the bridge auxiliary device is unbound directly (for example
during ti_sn65dsi86_exit(), which unregisters ti_sn_bridge_driver before
the I2C driver), ti_sn_bridge_remove() calls drm_bridge_unplug() while
ti_sn_bridge_release_resources() stays attached to pdata->dev, preventing
a subsequent ti_sn_bridge_atomic_post_disable() from releasing the runtime
PM reference.
[ ... ]
> @@ -1475,7 +1535,7 @@ static void ti_sn_bridge_remove(struct auxiliary_device *adev)
> if (!pdata)
> return;
>
> - drm_bridge_remove(&pdata->bridge);
> + drm_bridge_unplug(&pdata->bridge);
[Severity: High]
Are ti_sn_bridge_hpd_enable(), ti_sn_bridge_hpd_disable() and status_show()
still exposed to device resource accesses or runtime PM leaks on unplug?
In DisplayPort mode with an IRQ, ti_sn_bridge_hpd_enable() takes a runtime
PM reference with pm_runtime_get_sync(pdata->dev) and accesses
pdata->regmap until ti_sn_bridge_hpd_disable() runs:
drivers/gpu/drm/bridge/ti-sn65dsi86.c:ti_sn_bridge_hpd_enable() {
...
pm_runtime_get_sync(pdata->dev);
...
if (client->irq) {
ret = regmap_set_bits(pdata->regmap, SN_IRQ_EVENTS_EN_REG,
HPD_REMOVAL_EN | HPD_INSERTION_EN);
...
}
Neither HPD callback checks drm_bridge_enter(), and
ti_sn_bridge_hpd_enable() does not register a devres cleanup action for its
runtime PM reference. If the bridge is unplugged while HPD is enabled, the
runtime PM reference is leaked across device unbind (keeping regulators and
refclk enabled), or a subsequent HPD disable accesses pdata->regmap after
drm_bridge_unplug() completes.
Similarly, status_show() in connector debugfs calls
pm_runtime_get_sync(pdata->dev) and regmap_read(pdata->regmap, ...) without
drm_bridge_enter() and drm_bridge_exit() protection.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=14
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 15/32] drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (13 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:12 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable Luca Ceresoli
` (16 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Currently drm_bridge_detach() expects that the bridge private_obj is not
locked by a drm_modeset_acquire_ctx, and it warns in case that happens:
drm_bridge_detach()
-> drm_atomic_private_obj_fini()
-> list_del(&obj->head) // removes priv_obj from
// dev->mode_config.privobj_list
-> obj->funcs->atomic_destroy_state()
-> drm_modeset_lock_fini(&obj->lock)
-> WARN_ON(!list_empty(&lock->head)) // warn if priv_obj->lock
// is still in ctx->locked
The expectation is not respected when introducing bridge hot-plugging. In
such case the warning triggers if the bridge is being removed concurrently
to an operation that locks the private object using a
drm_modeset_acquire_ctx, such as in this execution scenario:
CPU0:
drm_mode_obj_get_properties_ioctl() // userspace request
-> DRM_MODESET_LOCK_ALL_BEGIN()
. -> drm_for_each_privobj() // loop on dev->mode_config.privobj_list
. - lock the privobj mutex
. - add priv_obj->lock to ctx->locked
. (list of locks to be released later)
.
. CPU1:
. drm_bridge_detach() // bridge hot-unplug
. -> WARN triggers!
.
-> DRM_MODESET_LOCK_ALL_END()
-> for each lock in ctx->locked
- remove priv_obj->lock from ctx->locked
- unlock the privobj mutex
Fix this by using DRM_MODESET_LOCK_ALL_BEGIN/END() around the list removal
in drm_atomic_private_obj_fini() to ensure the two threads above
(CPU0/CPU1) cannot happen concurrently.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v4:
- fixed conflicts after commit 6386ba453468 ("drm/atomic: Fix private obj
error handling")
Notes:
* This patch was sent separately in the past [0]
* The issue is still happening with hotplug without this patch
* The issue has also been reported by sashiko when reviewing v2 [1]
[0] https://lore.kernel.org/dri-devel/20260324-drm-bridge-atomic-vs-remove-private_obj-v3-1-64deefe84044@bootlin.com/
[1] https://lore.kernel.org/all/20261001130542.A40D11F00898@smtp.kernel.org/
---
drivers/gpu/drm/drm_atomic.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 1c3fe07b327e..096f85419b36 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1106,6 +1106,9 @@ EXPORT_SYMBOL(drm_atomic_private_obj_init);
void
drm_atomic_private_obj_fini(struct drm_private_obj *obj)
{
+ struct drm_modeset_acquire_ctx ctx;
+ int ret = 0;
+
/*
* Some callers ignore drm_atomic_private_obj_init() failures
* and unconditionally register a teardown action that calls
@@ -1117,7 +1120,10 @@ drm_atomic_private_obj_fini(struct drm_private_obj *obj)
if (list_empty(&obj->head))
return;
+ DRM_MODESET_LOCK_ALL_BEGIN(obj->dev, ctx, 0, ret);
list_del_init(&obj->head);
+ DRM_MODESET_LOCK_ALL_END(obj->dev, ctx, ret);
+
obj->funcs->atomic_destroy_state(obj, obj->state);
drm_modeset_lock_fini(&obj->lock);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 15/32] drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list
2026-11-25 17:50 ` [PATCH v4 15/32] drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list Luca Ceresoli
@ 2026-11-25 18:12 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:12 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/atomic: race on obj->lock after unlock in
drm_atomic_private_obj_fini()
--
commit 3a87086f7fda1b1abd7935fa8244d82c32bc24a2
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list
This commit wraps the list_del_init(&obj->head) call in
drm_atomic_private_obj_fini() with DRM_MODESET_LOCK_ALL_BEGIN() and
DRM_MODESET_LOCK_ALL_END() to serialize private object removal against
concurrent modeset locking.
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 1c3fe07b327ec..096f85419b369 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1106,6 +1106,9 @@ EXPORT_SYMBOL(drm_atomic_private_obj_init);
> void
> drm_atomic_private_obj_fini(struct drm_private_obj *obj)
> {
> + struct drm_modeset_acquire_ctx ctx;
> + int ret = 0;
> +
> /*
> * Some callers ignore drm_atomic_private_obj_init() failures
> * and unconditionally register a teardown action that calls
> @@ -1117,7 +1120,10 @@ drm_atomic_private_obj_fini(struct drm_private_obj *obj)
> if (list_empty(&obj->head))
> return;
>
> + DRM_MODESET_LOCK_ALL_BEGIN(obj->dev, ctx, 0, ret);
> list_del_init(&obj->head);
> + DRM_MODESET_LOCK_ALL_END(obj->dev, ctx, ret);
> +
> obj->funcs->atomic_destroy_state(obj, obj->state);
> drm_modeset_lock_fini(&obj->lock);
> }
[Severity: High]
Can a thread that already observed obj before list_del_init(&obj->head)
acquire obj->lock as soon as DRM_MODESET_LOCK_ALL_END() drops it, racing
with atomic_destroy_state() and drm_modeset_lock_fini()?
For example, if drm_modeset_lock_all_ctx() hits -EDEADLK on obj->lock
(because another atomic operation holds obj->lock), modeset_lock() saves
&obj->lock in ctx->contended and drm_modeset_backoff() drops all held
locks, including connection_mutex, before slow-locking contended:
CPU0 CPU1
drm_mode_obj_get_properties_ioctl()
DRM_MODESET_LOCK_ALL_BEGIN()
drm_modeset_lock_all_ctx()
drm_modeset_lock(&obj->lock)
ctx->contended = &obj->lock
returns -EDEADLK
DRM_MODESET_LOCK_ALL_END()
drm_modeset_backoff()
contended = ctx->contended
drm_modeset_drop_locks()
drm_bridge_detach()
drm_atomic_private_obj_fini()
DRM_MODESET_LOCK_ALL_BEGIN()
list_del_init(&obj->head)
DRM_MODESET_LOCK_ALL_END()
modeset_lock(contended, ...)
list_add(&obj->lock.head,
&ctx->locked)
atomic_destroy_state()
drm_modeset_lock_fini(&obj->lock)
WARN_ON(!list_empty(&lock->head))
...
drm_bridge_put() -> kfree(bridge)
drm_modeset_drop_locks()
/* touches freed obj->lock */ <-- use-after-free
The same race occurs if another thread blocks directly on obj->lock
without holding connection_mutex, such as drm_atomic_get_bridge_state()
while bridge->chain_node is still on encoder->bridge_chain (since
drm_bridge_detach() unlinks chain_node after drm_atomic_private_obj_fini()),
or __drm_state_dump(). When DRM_MODESET_LOCK_ALL_END() unlocks obj->lock,
the waiter wakes up and duplicates or reads obj->state while
atomic_destroy_state() frees it.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=15
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (14 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 15/32] drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:10 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 17/32] drm: event-notifier: add mechanism to notify about hotplug events Luca Ceresoli
` (15 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
With the upcoming DRM bridge hotplug support, drm_connectors will be added
and removed at any time after initial card probing.
This means the existing calls to drm_kms_helper_poll_init() at probe time
will not enable HPD on connectors added later on (and potentially not start
the polling work), so late connectors cannot perform HPD polling.
Similarly, drm_kms_helper_poll_fini() cannot disable HPD for hot-unplugged
connectors without disabling it for other connectors.
Add drm_kms_helper_poll_enable_connector() and
drm_kms_helper_poll_disable_connector() to enable or disable HPD for a
single connector, and also arm the work when an enabled connector requests
polling and stop on disable it unless other connectors still need it.
Polling must still be initialized once per device with
drm_kms_helper_poll_init() and finally torn down with
drm_kms_helper_poll_fini().
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
New patch in v4
---
drivers/gpu/drm/drm_probe_helper.c | 92 ++++++++++++++++++++++++++++++++++++++
include/drm/drm_probe_helper.h | 2 +
2 files changed, 94 insertions(+)
diff --git a/drivers/gpu/drm/drm_probe_helper.c b/drivers/gpu/drm/drm_probe_helper.c
index 856b40fdaac4..e468971ab642 100644
--- a/drivers/gpu/drm/drm_probe_helper.c
+++ b/drivers/gpu/drm/drm_probe_helper.c
@@ -224,6 +224,14 @@ drm_connector_mode_valid(struct drm_connector *connector,
return ret;
}
+static void drm_kms_helper_disable_hpd_connector(struct drm_connector *connector)
+{
+ const struct drm_connector_helper_funcs *funcs = connector->helper_private;
+
+ if (funcs && funcs->disable_hpd)
+ funcs->disable_hpd(connector);
+}
+
static void drm_kms_helper_disable_hpd(struct drm_device *dev)
{
struct drm_connector *connector;
@@ -240,6 +248,16 @@ static void drm_kms_helper_disable_hpd(struct drm_device *dev)
drm_connector_list_iter_end(&conn_iter);
}
+static bool drm_kms_helper_enable_hpd_connector(struct drm_connector *connector)
+{
+ const struct drm_connector_helper_funcs *funcs = connector->helper_private;
+
+ if (funcs && funcs->enable_hpd)
+ funcs->enable_hpd(connector);
+
+ return (connector->polled & (DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT));
+}
+
static bool drm_kms_helper_enable_hpd(struct drm_device *dev)
{
bool poll = false;
@@ -316,6 +334,32 @@ void drm_kms_helper_poll_enable(struct drm_device *dev)
}
EXPORT_SYMBOL(drm_kms_helper_poll_enable);
+/**
+ * drm_kms_helper_poll_enable_connector - enable output polling for a connector
+ * @connector: the connector
+ *
+ * Enables output polling @connector and reschdules the polling work if
+ * needed. Intended for connectors which are added after initial probing.
+ *
+ * This must be called after polling has been initialized by
+ * drm_kms_helper_poll_init(). Safe to call while polling is already
+ * running.
+ */
+void drm_kms_helper_poll_enable_connector(struct drm_connector *connector)
+{
+ struct drm_device *dev = connector->dev;
+
+ if (drm_WARN_ON_ONCE(dev, !dev->mode_config.poll_enabled) || !drm_kms_helper_poll)
+ return;
+
+ if (drm_kms_helper_enable_hpd_connector(connector) ||
+ dev->mode_config.delayed_event)
+ reschedule_output_poll_work(dev);
+
+ dev->mode_config.poll_running = true;
+}
+EXPORT_SYMBOL(drm_kms_helper_poll_enable_connector);
+
/**
* drm_kms_helper_poll_reschedule - reschedule the output polling work
* @dev: drm_device
@@ -927,6 +971,54 @@ void drm_kms_helper_poll_disable(struct drm_device *dev)
}
EXPORT_SYMBOL(drm_kms_helper_poll_disable);
+static bool drm_kms_helper_has_other_connectors(struct drm_connector *connector)
+{
+ struct drm_device *dev = connector->dev;
+ struct drm_connector *curr;
+ struct drm_connector_list_iter conn_iter;
+ bool remaining = false;
+
+ drm_connector_list_iter_begin(dev, &conn_iter);
+ drm_for_each_connector_iter(curr, &conn_iter) {
+ if (curr != connector &&
+ curr->registration_state == DRM_CONNECTOR_REGISTERED) {
+ remaining = true;
+ break;
+ }
+ }
+ drm_connector_list_iter_end(&conn_iter);
+
+ return remaining;
+}
+
+/**
+ * drm_kms_helper_poll_disable_connector - disable output polling for a connector
+ * @connector: the connector
+ *
+ * Disables output polling for @connector. If there are no other registered
+ * connectors, also disables the output poll work.
+ *
+ * Polling stays initialized; call drm_kms_helper_poll_fini() to tear it
+ * down. Does nothing if output polling is not initialized by
+ * drm_kms_helper_poll_init().
+ */
+void drm_kms_helper_poll_disable_connector(struct drm_connector *connector)
+{
+ struct drm_device *dev = connector->dev;
+
+ if (!dev->mode_config.poll_enabled)
+ return;
+
+ drm_kms_helper_disable_hpd_connector(connector);
+
+ if (dev->mode_config.poll_running &&
+ !drm_kms_helper_has_other_connectors(connector)) {
+ cancel_delayed_work_sync(&dev->mode_config.output_poll_work);
+ dev->mode_config.poll_running = false;
+ }
+}
+EXPORT_SYMBOL(drm_kms_helper_poll_disable_connector);
+
/**
* drm_kms_helper_poll_init - initialize and enable output polling
* @dev: drm_device
diff --git a/include/drm/drm_probe_helper.h b/include/drm/drm_probe_helper.h
index 840ae5f798c2..ae58c1b078fe 100644
--- a/include/drm/drm_probe_helper.h
+++ b/include/drm/drm_probe_helper.h
@@ -26,7 +26,9 @@ void drm_kms_helper_hotplug_event(struct drm_device *dev);
void drm_kms_helper_connector_hotplug_event(struct drm_connector *connector);
void drm_kms_helper_poll_disable(struct drm_device *dev);
+void drm_kms_helper_poll_disable_connector(struct drm_connector *connector);
void drm_kms_helper_poll_enable(struct drm_device *dev);
+void drm_kms_helper_poll_enable_connector(struct drm_connector *connector);
void drm_kms_helper_poll_reschedule(struct drm_device *dev);
bool drm_kms_helper_is_poll_worker(void);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable
2026-11-25 17:50 ` [PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable Luca Ceresoli
@ 2026-11-25 18:10 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:10 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/probe-helper: unbalanced HPD callbacks in per-connector
poll helpers
- [High] drm/probe-helper: drm_kms_helper_poll_disable_connector()
leaves poll active
- [Low] drm/probe-helper: duplicated HPD helper logic in
drm_kms_helper_enable_hpd()
--
commit 3fcc8be33037c845672586431b3e9d911af66acb
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/probe-helper: add per-connector polling enable/disable
This commit adds drm_kms_helper_poll_enable_connector() and
drm_kms_helper_poll_disable_connector() to enable and disable output
polling and HPD for individual connectors added or removed dynamically.
> diff --git a/drivers/gpu/drm/drm_probe_helper.c b/drivers/gpu/drm/drm_probe_helper.c
> index 856b40fdaac4a..e468971ab6429 100644
> --- a/drivers/gpu/drm/drm_probe_helper.c
> +++ b/drivers/gpu/drm/drm_probe_helper.c
> @@ -224,6 +224,14 @@ drm_connector_mode_valid(struct drm_connector *connector,
> return ret;
> }
>
> +static void drm_kms_helper_disable_hpd_connector(struct drm_connector *connector)
> +{
> + const struct drm_connector_helper_funcs *funcs = connector->helper_private;
> +
> + if (funcs && funcs->disable_hpd)
> + funcs->disable_hpd(connector);
> +}
> +
> static void drm_kms_helper_disable_hpd(struct drm_device *dev)
> {
> struct drm_connector *connector;
> @@ -240,6 +248,16 @@ static void drm_kms_helper_disable_hpd(struct drm_device *dev)
> drm_connector_list_iter_end(&conn_iter);
> }
>
> +static bool drm_kms_helper_enable_hpd_connector(struct drm_connector *connector)
> +{
> + const struct drm_connector_helper_funcs *funcs = connector->helper_private;
> +
> + if (funcs && funcs->enable_hpd)
> + funcs->enable_hpd(connector);
> +
> + return (connector->polled & (DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT));
> +}
> +
> static bool drm_kms_helper_enable_hpd(struct drm_device *dev)
> {
> bool poll = false;
[Severity: Low]
This isn't a bug, but drm_kms_helper_disable_hpd() and
drm_kms_helper_enable_hpd() right below these new helpers still open-code
the same per-connector callback and connector->polled checks instead of
calling drm_kms_helper_disable_hpd_connector() and
drm_kms_helper_enable_hpd_connector().
> @@ -316,6 +334,32 @@ void drm_kms_helper_poll_enable(struct drm_device *dev)
> }
> EXPORT_SYMBOL(drm_kms_helper_poll_enable);
>
> +/**
> + * drm_kms_helper_poll_enable_connector - enable output polling for a connector
> + * @connector: the connector
> + *
> + * Enables output polling @connector and reschdules the polling work if
> + * needed. Intended for connectors which are added after initial probing.
> + *
> + * This must be called after polling has been initialized by
> + * drm_kms_helper_poll_init(). Safe to call while polling is already
> + * running.
> + */
> +void drm_kms_helper_poll_enable_connector(struct drm_connector *connector)
> +{
> + struct drm_device *dev = connector->dev;
> +
> + if (drm_WARN_ON_ONCE(dev, !dev->mode_config.poll_enabled) || !drm_kms_helper_poll)
> + return;
> +
> + if (drm_kms_helper_enable_hpd_connector(connector) ||
> + dev->mode_config.delayed_event)
> + reschedule_output_poll_work(dev);
> +
> + dev->mode_config.poll_running = true;
> +}
> +EXPORT_SYMBOL(drm_kms_helper_poll_enable_connector);
> +
> /**
> * drm_kms_helper_poll_reschedule - reschedule the output polling work
> * @dev: drm_device
> @@ -927,6 +971,54 @@ void drm_kms_helper_poll_disable(struct drm_device *dev)
> }
> EXPORT_SYMBOL(drm_kms_helper_poll_disable);
>
> +static bool drm_kms_helper_has_other_connectors(struct drm_connector *connector)
> +{
> + struct drm_device *dev = connector->dev;
> + struct drm_connector *curr;
> + struct drm_connector_list_iter conn_iter;
> + bool remaining = false;
> +
> + drm_connector_list_iter_begin(dev, &conn_iter);
> + drm_for_each_connector_iter(curr, &conn_iter) {
> + if (curr != connector &&
> + curr->registration_state == DRM_CONNECTOR_REGISTERED) {
> + remaining = true;
> + break;
> + }
> + }
> + drm_connector_list_iter_end(&conn_iter);
> +
> + return remaining;
> +}
> +
> +/**
> + * drm_kms_helper_poll_disable_connector - disable output polling for a connector
> + * @connector: the connector
> + *
> + * Disables output polling for @connector. If there are no other registered
> + * connectors, also disables the output poll work.
> + *
> + * Polling stays initialized; call drm_kms_helper_poll_fini() to tear it
> + * down. Does nothing if output polling is not initialized by
> + * drm_kms_helper_poll_init().
> + */
> +void drm_kms_helper_poll_disable_connector(struct drm_connector *connector)
> +{
> + struct drm_device *dev = connector->dev;
> +
> + if (!dev->mode_config.poll_enabled)
> + return;
> +
> + drm_kms_helper_disable_hpd_connector(connector);
[Severity: High]
Can drm_kms_helper_poll_enable_connector() and
drm_kms_helper_poll_disable_connector() cause unbalanced
enable_hpd()/disable_hpd() callbacks on connectors?
struct drm_connector_helper_funcs documents that drivers do not need to
track HPD state because the DRM core guarantees enable_hpd() and
disable_hpd() calls are balanced. However, no per-connector HPD state is
recorded here:
1. drm_kms_helper_poll_disable_connector() calls
drm_kms_helper_disable_hpd_connector() without checking
dev->mode_config.poll_running. If poll_running is false (for example
because drm_kms_helper_poll was false or polling was disabled for
suspend via drm_kms_helper_poll_disable()), disable_hpd() runs even
though HPD is not enabled.
2. A connector remains on dev->mode_config.connector_list after
drm_kms_helper_poll_disable_connector() until its last reference drops
in drm_connector_cleanup(). If another connector keeps poll_running
true and drm_kms_helper_poll_disable() or drm_kms_helper_poll_fini()
runs while an atomic state or client still holds a reference to the
disabled connector, drm_kms_helper_disable_hpd() walks connector_list
and calls disable_hpd() on it a second time.
3. Conversely, when disabling the last connector clears poll_running, a
later drm_helper_probe_single_connector_modes() on a newly registered
connector calls drm_kms_helper_poll_enable(dev), which enables HPD on
all connectors on connector_list and sets poll_running = true before
the caller invokes drm_kms_helper_poll_enable_connector(), calling
enable_hpd() twice. And if poll_running was false with multiple
connectors present, drm_kms_helper_poll_enable_connector() sets
device-wide poll_running = true after enabling only one connector,
causing a subsequent drm_kms_helper_poll_enable(dev) to return early
and leave HPD disabled on the other connectors.
Unbalanced enable_hpd()/disable_hpd() calls trigger WARN(bridge->hpd_cb)
in drm_bridge_hpd_enable() and cause runtime PM or IRQ count underflows
in bridge drivers such as ti_sn_bridge_hpd_disable() and
display_connector_hpd_disable().
> +
> + if (dev->mode_config.poll_running &&
> + !drm_kms_helper_has_other_connectors(connector)) {
> + cancel_delayed_work_sync(&dev->mode_config.output_poll_work);
> + dev->mode_config.poll_running = false;
> + }
> +}
> +EXPORT_SYMBOL(drm_kms_helper_poll_disable_connector);
[Severity: High]
Does drm_kms_helper_poll_disable_connector() actually stop or synchronize
with output_poll_work for a polled connector when another connector is
registered on the device?
drm_kms_helper_has_other_connectors() returns true whenever any other
registered connector exists, even if that other connector does not use
polling (polled == 0 or DRM_CONNECTOR_POLL_HPD), so output_poll_work is
left running when no remaining connector needs polling.
More importantly, when another registered connector exists,
drm_kms_helper_poll_disable_connector() neither waits for an in-flight
output_poll_execute() nor marks @connector as poll-disabled. Because
output_poll_execute() iterates dev->mode_config.connector_list and checks
only connector->force and connector->polled, it can run
drm_helper_probe_detect() on @connector concurrently with bridge teardown
and keep repolling it every DRM_OUTPUT_POLL_PERIOD until its final
connector reference is dropped.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=16
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 17/32] drm: event-notifier: add mechanism to notify about hotplug events
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (15 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 18/32] drm/bridge: notify about added and detached bridges Luca Ceresoli
` (14 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
In preparation for supporting DRM bridge hotplug, add an event notifier to
allow interested parties to be notified about events they need to react to.
For the initial implementation of bridge hotplug, a few events are needed:
* A bridge was added (happening in drm_bridge.c)
* A bridge was detached (happening in drm_bridge.c)
* A MIPI device was attached to a MIPI host (happening in drm_mipi_dsi.c)
Being originated from different modules, implement the event notifier
mechanism in a new module with minimal dependencies that event producers
can easily use to send events.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- Renamed to clarify the scope is only about hotplug
- Extend enum drm_event_notifier_event documentation
- Add DRM_BRIDGE_ADDED event to support non-DSI (and some DSI too) bridges
- Reword event description in a more concise way
- Make DRM_HOTPLUG_EVENT_NOTIFIER a bool, not a tristate: DRM_MIPI_DSI
cannot be made a tristate with current code, and it depends on
DRM_HOTPLUG_EVENT_NOTIFIER
- Use EXPORT_SYMBOL_GPL instead of EXPORT_SYMBOL to avoid GPL-bypass of the
notifier API
Changes in v2:
- added missing include
---
MAINTAINERS | 8 ++++
drivers/gpu/drm/Kconfig | 3 ++
drivers/gpu/drm/Makefile | 2 +
drivers/gpu/drm/drm_hotplug_event_notifier.c | 62 ++++++++++++++++++++++++++++
include/drm/drm_hotplug_event_notifier.h | 52 +++++++++++++++++++++++
5 files changed, 127 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 0afa391498d0..a5e2bf15e59f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9320,6 +9320,14 @@ F: include/drm/drm_gpusvm.h
F: include/drm/drm_pagemap.h
F: include/drm/drm_pagemap_util.h
+DRM HOTPLUG EVENT NOTIFIER
+M: Luca Ceresoli <luca.ceresoli@bootlin.com>
+L: dri-devel@lists.freedesktop.org
+S: Maintained
+T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F: drivers/gpu/drm/drm_hotplug_event_notifier.c
+F: include/drm/drm_hotplug_event_notifier.h
+
DRM LOG
M: Jocelyn Falempe <jfalempe@redhat.com>
M: Javier Martinez Canillas <javierm@redhat.com>
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 61111d50b1c6..5268bf47b2e3 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -33,6 +33,9 @@ endmenu
if DRM
+config DRM_HOTPLUG_EVENT_NOTIFIER
+ bool
+
config DRM_MIPI_DBI
tristate
depends on DRM
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 2c6bc093a923..e4268c5b771a 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -95,6 +95,8 @@ drm-$(CONFIG_DRM_DRAW) += drm_draw.o
drm-$(CONFIG_DRM_RAS) += drm_ras.o drm_ras_nl.o drm_ras_genl_family.o
obj-$(CONFIG_DRM) += drm.o
+obj-$(CONFIG_DRM_HOTPLUG_EVENT_NOTIFIER) += drm_hotplug_event_notifier.o
+
obj-$(CONFIG_DRM_PANEL) += drm_panel.o
obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
obj-$(CONFIG_DRM_PANEL_BACKLIGHT_QUIRKS) += drm_panel_backlight_quirks.o
diff --git a/drivers/gpu/drm/drm_hotplug_event_notifier.c b/drivers/gpu/drm/drm_hotplug_event_notifier.c
new file mode 100644
index 000000000000..9cc252d10c73
--- /dev/null
+++ b/drivers/gpu/drm/drm_hotplug_event_notifier.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Internal event notifier of events about DRM bridge hotplug
+ *
+ * Copyright (C) 2026 GE HealthCare
+ * Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
+ */
+
+#include <linux/module.h>
+#include <linux/notifier.h>
+
+#include <drm/drm_hotplug_event_notifier.h>
+
+static BLOCKING_NOTIFIER_HEAD(drm_hotplug_event_notifier);
+
+/**
+ * drm_hotplug_event_notifier_register - Register to be notified of DRM
+ * hotplug events
+ * @nb: the notifier block to be registered
+ *
+ * @nb will be notified of events defined in
+ * &drm_hotplug_event_notifier_event
+ *
+ * Returns 0 on success, %-EEXIST on error.
+ */
+int drm_hotplug_event_notifier_register(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_register(&drm_hotplug_event_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(drm_hotplug_event_notifier_register);
+
+/**
+ * drm_hotplug_event_notifier_unregister - Unregister from being notified
+ * of DRM hotplug events
+ * @nb: the notifier block to be unregistered
+ *
+ * @nb will stop being notified of events defined in
+ * &drm_hotplug_event_notifier_event
+ *
+ * Returns zero on success or %-ENOENT on failure.
+ */
+int drm_hotplug_event_notifier_unregister(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_unregister(&drm_hotplug_event_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(drm_hotplug_event_notifier_unregister);
+
+/**
+ * drm_hotplug_event_notifier_notify - Emit an event to be notified to
+ * registered entities
+ * @event: event ID as defined in &drm_hotplug_event_notifier_event
+ * @data: metadata associated to the event
+ */
+void drm_hotplug_event_notifier_notify(unsigned long event, void *data)
+{
+ blocking_notifier_call_chain(&drm_hotplug_event_notifier, event, data);
+}
+EXPORT_SYMBOL_GPL(drm_hotplug_event_notifier_notify);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Luca Ceresoli <luca.ceresoli@bootlin.com>");
+MODULE_DESCRIPTION("Notifier for DRM components addition/removal and attach/detach");
diff --git a/include/drm/drm_hotplug_event_notifier.h b/include/drm/drm_hotplug_event_notifier.h
new file mode 100644
index 000000000000..008e041444be
--- /dev/null
+++ b/include/drm/drm_hotplug_event_notifier.h
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Internal event notifier of events about DRM bridge hotplug
+ *
+ * Copyright (C) 2026 GE HealthCare
+ * Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
+ */
+
+#ifndef _DRM_HOTPLUG_EVENT_NOTIFIER_H_
+#define _DRM_HOTPLUG_EVENT_NOTIFIER_H_
+
+#include <linux/notifier.h>
+
+/**
+ * enum drm_hotplug_event_notifier_event - DRM bridge hotplug and
+ * hotunplug events
+ *
+ * Describe any event about DRM bridge appearing, disappearing, or getting
+ * connected at runtime (hotplug). Any of these events may need to trigger
+ * a response in order to start or stop the video pipeline, including
+ * creating or destroying a drm_connector.
+ *
+ * Each of these events is accompanied by a void* argument, whose meaning
+ * is event-specific and defined per each event.
+ */
+enum drm_hotplug_event_notifier_event {
+ /**
+ * @DRM_MIPI_DSI_ATTACHED: A MIPI DSI device has just been attached
+ * to its MIPI DSI host. @data is a pointer to the attached &struct
+ * mipi_dsi_device.
+ */
+ DRM_MIPI_DSI_ATTACHED,
+ /**
+ * @DRM_BRIDGE_ADDED: A bridge has just been added by calling
+ * drm_bridge_add(). As such, it is not yet attached to an encoder
+ * and is not part of any encoder bridge chain. @data is a pointer
+ * to the added &struct drm_bridge.
+ */
+ DRM_BRIDGE_ADDED,
+ /**
+ * @DRM_BRIDGE_DETACHED: A bridge has just been detached and
+ * removed from the encoder bridge chain. @data is a pointer to the
+ * detached &struct drm_bridge.
+ */
+ DRM_BRIDGE_DETACHED,
+};
+
+int drm_hotplug_event_notifier_register(struct notifier_block *nb);
+int drm_hotplug_event_notifier_unregister(struct notifier_block *nb);
+void drm_hotplug_event_notifier_notify(unsigned long event, void *data);
+
+#endif /* _DRM_HOTPLUG_EVENT_NOTIFIER_H_ */
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 18/32] drm/bridge: notify about added and detached bridges
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (16 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 17/32] drm: event-notifier: add mechanism to notify about hotplug events Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 19/32] drm/mipi-dsi: notify about DSI attach Luca Ceresoli
` (13 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
In preparation to support DRM bridge hotplug, let the drm_bridge code emit
an event when a bridge is added and when it is detached, so that this event
can trigger the actions needed to (de)configure the pipeline and
(un)register the connector as appropriate.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- also notify on added bridges (for non-DSI bridges)
- use new v3 notifier API name
---
drivers/gpu/drm/Kconfig | 1 +
drivers/gpu/drm/drm_bridge.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 5268bf47b2e3..105dd46a0a45 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -17,6 +17,7 @@ menuconfig DRM
# device and dmabuf fd. Let's make sure that is available for our userspace.
select KCMP
select VIDEO
+ select DRM_HOTPLUG_EVENT_NOTIFIER
help
Kernel-level support for the Direct Rendering Infrastructure (DRI)
introduced in XFree86 4.0. If you say Y here, you need to select
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 310f03bdb744..a50709ac8b06 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -34,6 +34,7 @@
#include <drm/drm_debugfs.h>
#include <drm/drm_edid.h>
#include <drm/drm_encoder.h>
+#include <drm/drm_hotplug_event_notifier.h>
#include <drm/drm_file.h>
#include <drm/drm_of.h>
#include <drm/drm_print.h>
@@ -475,6 +476,8 @@ void drm_bridge_add(struct drm_bridge *bridge)
mutex_lock(&bridge_lock);
list_add_tail(&bridge->list, &bridge_list);
mutex_unlock(&bridge_lock);
+
+ drm_hotplug_event_notifier_notify(DRM_BRIDGE_ADDED, bridge);
}
EXPORT_SYMBOL(drm_bridge_add);
@@ -710,6 +713,9 @@ void drm_bridge_detach(struct drm_bridge *bridge)
bridge->funcs->detach(bridge);
list_del_init(&bridge->chain_node);
+
+ drm_hotplug_event_notifier_notify(DRM_BRIDGE_DETACHED, bridge);
+
bridge->dev = NULL;
drm_bridge_put(bridge);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 19/32] drm/mipi-dsi: notify about DSI attach
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (17 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 18/32] drm/bridge: notify about added and detached bridges Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 20/32] drm/bridge: add drm_bridge_get_next() and supporting func Luca Ceresoli
` (12 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
In preparation to support DRM bridge hotplug, let the drm_mipi_dsi code
emit an event when a DSI device is attached to the corresponding DSI host,
so that this event can trigger the actions needed to configure the pipeline
and register the connector as appropriate.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- use new v3 notifier API name
- fix commit message
---
drivers/gpu/drm/Kconfig | 1 +
drivers/gpu/drm/drm_mipi_dsi.c | 3 +++
2 files changed, 4 insertions(+)
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 105dd46a0a45..3ebd9388bdda 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -45,6 +45,7 @@ config DRM_MIPI_DBI
config DRM_MIPI_DSI
bool
depends on DRM
+ select DRM_HOTPLUG_EVENT_NOTIFIER
config DRM_KMS_HELPER
tristate
diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 3ac1dd5ad640..ae49f3aa1b2b 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -34,6 +34,7 @@
#include <linux/slab.h>
#include <drm/display/drm_dsc.h>
+#include <drm/drm_hotplug_event_notifier.h>
#include <drm/drm_mipi_dsi.h>
#include <drm/drm_print.h>
@@ -386,6 +387,8 @@ int mipi_dsi_attach(struct mipi_dsi_device *dsi)
dsi->attached = true;
+ drm_hotplug_event_notifier_notify(DRM_MIPI_DSI_ATTACHED, dsi);
+
return 0;
}
EXPORT_SYMBOL(mipi_dsi_attach);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 20/32] drm/bridge: add drm_bridge_get_next() and supporting func
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (18 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 19/32] drm/mipi-dsi: notify about DSI attach Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 21/32] drm/panel: implement .get_next_bridge Luca Ceresoli
` (11 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
For bridge hotplug we need to successfully probe a card with an incomplete
bridge chain, i.e. a chain whose last bridge currently in bridge_chain
needs another bridge at its output. Such a card would have no connector,
and be able to add one as soon as the following bridges are added up to the
bridge that requires no further ones (like a panel or a connector_bridge).
So we need a way to know whether the pipeline is complete in the hardware
(all bridges probed), in order to complete it in software (attach all
bridges not yet attached). Currently common DRM code has no way to know
that.
Add drm_bridge_get_next() and a supporting get_next_bridge func so each
bridge can expose its next bridge, and whether there's supposed to be one.
A subsequent commit will use this function to detect whether the pipeline
is complete in the hardware or not.
Link: https://lore.kernel.org/r/20260624-vagabond-neon-gorilla-cd6487@houat
Suggested-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- fix and improve kerneldoc
New patch in v2, replacing the is_tail patch in v1
---
drivers/gpu/drm/drm_bridge.c | 30 ++++++++++++++++++++++++++++++
include/drm/drm_bridge.h | 25 +++++++++++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index a50709ac8b06..e0e0dd7fc12b 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -720,6 +720,36 @@ void drm_bridge_detach(struct drm_bridge *bridge)
drm_bridge_put(bridge);
}
+/**
+ * drm_bridge_get_next - return the bridge at this bridge's output port
+ * @bridge: the bridge to query
+ *
+ * Return the next bridge, i.e. the bridge that is connected at the output
+ * port of @bridge. Unlike drm_bridge_get_next_bridge(), the next bridge
+ * might or not be in the encoder chain.
+ *
+ * Returns:
+ * * Pointer to a bridge connected to the output port of this bridge,
+ * with refcount incremented; call drm_bridge_put() when done
+ * * ERR_PTR(-ENODEV): this bridge has an output port where a next bridge
+ * needs to be present for video output, but the next
+ * bridge is not currently available
+ * * NULL: this bridge does not have an output port where a next bridge
+ * is expected
+ * * ERR_PTR(-ENOENT): the bridge does not implement the func
+ * * Another negative error returned by the bridge func
+ */
+struct drm_bridge *drm_bridge_get_next(struct drm_bridge *bridge)
+{
+ if (!(bridge->ops & DRM_BRIDGE_OP_GET_NEXT_BRIDGE)) {
+ drm_warn_once(bridge->dev, "get_next_bridge func not implemented!");
+ return ERR_PTR(-ENOENT);
+ }
+
+ return bridge->funcs->get_next_bridge(bridge);
+}
+EXPORT_SYMBOL(drm_bridge_get_next);
+
/**
* DOC: bridge operations
*
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index d6ef020c4cc9..cfa0aff1de4f 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -62,6 +62,25 @@ enum drm_bridge_attach_flags {
* struct drm_bridge_funcs - drm_bridge control functions
*/
struct drm_bridge_funcs {
+ /**
+ * @get_next_bridge:
+ *
+ * Return a pointer to the bridge connected at the output port of
+ * this bridge.
+ *
+ * Returns:
+ * * Pointer to a bridge connected to the output port of this bridge,
+ * with refcount incremented; call drm_bridge_put() when done
+ * * ERR_PTR(-ENODEV): this bridge has an output port where a next
+ * bridge needs to be present for video output,
+ * but the next bridge is not currently
+ * available
+ * * NULL: this bridge does not have an output port where a next
+ * bridge is expected (e.g. a panel)
+ * * Another negative error returned by the bridge func
+ */
+ struct drm_bridge *(*get_next_bridge)(struct drm_bridge *bridge);
+
/**
* @attach:
*
@@ -1021,6 +1040,11 @@ enum drm_bridge_ops {
* &drm_bridge_funcs->hdmi_clear_spd_infoframe callbacks.
*/
DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME = BIT(10),
+ /**
+ * @DRM_BRIDGE_OP_GET_NEXT_BRIDGE: The bridge implements the
+ * &drm_bridge_funcs->get_next_bridge callback.
+ */
+ DRM_BRIDGE_OP_GET_NEXT_BRIDGE = BIT(11),
};
/**
@@ -1272,6 +1296,7 @@ void drm_bridge_remove(struct drm_bridge *bridge);
int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
struct drm_bridge *previous,
enum drm_bridge_attach_flags flags);
+struct drm_bridge *drm_bridge_get_next(struct drm_bridge *bridge);
#ifdef CONFIG_OF
struct drm_bridge *of_drm_find_and_get_bridge(const struct device_node *np);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 21/32] drm/panel: implement .get_next_bridge
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (19 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 20/32] drm/bridge: add drm_bridge_get_next() and supporting func Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 22/32] drm/bridge: display-connector: " Luca Ceresoli
` (10 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
This bridge never has a next bridge. Add get_next_callback func to expose
this.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/drm_panel.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index 26d9378563f5..ed8d6c43b6fb 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -70,6 +70,11 @@ static const struct drm_connector_funcs panel_bridge_connector_funcs = {
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
};
+static struct drm_bridge *drm_panel_bridge_get_next_bridge(struct drm_bridge *bridge)
+{
+ return NULL;
+}
+
static int panel_bridge_attach(struct drm_bridge *bridge,
struct drm_encoder *encoder,
enum drm_bridge_attach_flags flags)
@@ -220,6 +225,7 @@ static void panel_bridge_debugfs_init(struct drm_bridge *bridge,
}
static const struct drm_bridge_funcs panel_bridge_bridge_funcs = {
+ .get_next_bridge = drm_panel_bridge_get_next_bridge,
.attach = panel_bridge_attach,
.detach = panel_bridge_detach,
.atomic_pre_enable = panel_bridge_atomic_pre_enable,
@@ -516,7 +522,7 @@ void drm_panel_add(struct drm_panel *panel)
mutex_unlock(&panel_lock);
panel->bridge.of_node = panel->dev->of_node;
- panel->bridge.ops = DRM_BRIDGE_OP_MODES;
+ panel->bridge.ops = DRM_BRIDGE_OP_MODES | DRM_BRIDGE_OP_GET_NEXT_BRIDGE;
panel->bridge.pre_enable_prev_first = panel->prepare_prev_first;
drm_bridge_add(&panel->bridge);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 22/32] drm/bridge: display-connector: implement .get_next_bridge
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (20 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 21/32] drm/panel: implement .get_next_bridge Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 23/32] drm/bridge: ti-sn65dsi83: " Luca Ceresoli
` (9 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
This bridge never has a next bridge. Add get_next_callback func to expose
this.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
drivers/gpu/drm/bridge/display-connector.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/gpu/drm/bridge/display-connector.c b/drivers/gpu/drm/bridge/display-connector.c
index eb3412ec30a0..8b16ad89c7f1 100644
--- a/drivers/gpu/drm/bridge/display-connector.c
+++ b/drivers/gpu/drm/bridge/display-connector.c
@@ -36,6 +36,11 @@ to_display_connector(struct drm_bridge *bridge)
return container_of(bridge, struct display_connector, bridge);
}
+static struct drm_bridge *display_connector_get_next_bridge(struct drm_bridge *bridge)
+{
+ return NULL;
+}
+
static int display_connector_attach(struct drm_bridge *bridge,
struct drm_encoder *encoder,
enum drm_bridge_attach_flags flags)
@@ -214,6 +219,7 @@ static u32 *display_connector_get_input_bus_fmts(struct drm_bridge *bridge,
}
static const struct drm_bridge_funcs display_connector_bridge_funcs = {
+ .get_next_bridge = display_connector_get_next_bridge,
.attach = display_connector_attach,
.destroy = display_connector_destroy,
.detect = display_connector_bridge_detect,
@@ -412,6 +418,7 @@ static int display_connector_probe(struct platform_device *pdev)
conn->bridge.of_node = pdev->dev.of_node;
+ conn->bridge.ops = DRM_BRIDGE_OP_GET_NEXT_BRIDGE;
if (conn->bridge.ddc)
conn->bridge.ops |= DRM_BRIDGE_OP_EDID
| DRM_BRIDGE_OP_DETECT;
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 23/32] drm/bridge: ti-sn65dsi83: implement .get_next_bridge
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (21 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 22/32] drm/bridge: display-connector: " Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:14 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 24/32] drm/bridge: ti-sn65dsi86: " Luca Ceresoli
` (8 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Add get_next_callback func to expose the next bridge.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- add missing drm_bridge_get
---
drivers/gpu/drm/bridge/ti-sn65dsi83.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi83.c b/drivers/gpu/drm/bridge/ti-sn65dsi83.c
index 77ef1613c5f5..9e9cf0dda92d 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi83.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi83.c
@@ -295,6 +295,13 @@ static struct sn65dsi83 *bridge_to_sn65dsi83(struct drm_bridge *bridge)
return container_of(bridge, struct sn65dsi83, bridge);
}
+static struct drm_bridge *sn65dsi83_get_next_bridge(struct drm_bridge *bridge)
+{
+ struct sn65dsi83 *ctx = bridge_to_sn65dsi83(bridge);
+
+ return ctx->panel_bridge ? drm_bridge_get(ctx->panel_bridge) : ERR_PTR(-ENODEV);
+}
+
static int sn65dsi83_attach(struct drm_bridge *bridge,
struct drm_encoder *encoder,
enum drm_bridge_attach_flags flags)
@@ -795,6 +802,7 @@ sn65dsi83_atomic_get_input_bus_fmts(struct drm_bridge *bridge,
}
static const struct drm_bridge_funcs sn65dsi83_funcs = {
+ .get_next_bridge = sn65dsi83_get_next_bridge,
.attach = sn65dsi83_attach,
.detach = sn65dsi83_detach,
.atomic_enable = sn65dsi83_atomic_enable,
@@ -1045,6 +1053,7 @@ static int sn65dsi83_probe(struct i2c_client *client)
ctx->bridge.of_node = dev->of_node;
ctx->bridge.pre_enable_prev_first = true;
ctx->bridge.type = DRM_MODE_CONNECTOR_LVDS;
+ ctx->bridge.ops = DRM_BRIDGE_OP_GET_NEXT_BRIDGE;
drm_bridge_add(&ctx->bridge);
ret = sn65dsi83_host_attach(ctx);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 23/32] drm/bridge: ti-sn65dsi83: implement .get_next_bridge
2026-11-25 17:50 ` [PATCH v4 23/32] drm/bridge: ti-sn65dsi83: " Luca Ceresoli
@ 2026-11-25 18:14 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:14 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/bridge: ti-sn65dsi83: use-after-free in
sn65dsi83_get_next_bridge()
--
commit 07f44b5de19c58e65f65432a2a999004dd04f3ae
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/bridge: ti-sn65dsi83: implement .get_next_bridge
This commit implements the .get_next_bridge callback for the ti-sn65dsi83
bridge driver to return a reference to ctx->panel_bridge.
> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi83.c b/drivers/gpu/drm/bridge/ti-sn65dsi83.c
> index 77ef1613c5f51..9e9cf0dda92d8 100644
> --- a/drivers/gpu/drm/bridge/ti-sn65dsi83.c
> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi83.c
> @@ -295,6 +295,13 @@ static struct sn65dsi83 *bridge_to_sn65dsi83(struct drm_bridge *bridge)
> return container_of(bridge, struct sn65dsi83, bridge);
> }
>
> +static struct drm_bridge *sn65dsi83_get_next_bridge(struct drm_bridge *bridge)
> +{
> + struct sn65dsi83 *ctx = bridge_to_sn65dsi83(bridge);
> +
> + return ctx->panel_bridge ? drm_bridge_get(ctx->panel_bridge) : ERR_PTR(-ENODEV);
> +}
[Severity: High]
Can sn65dsi83_get_next_bridge() cause a use-after-free on
ctx->panel_bridge?
sn65dsi83_parse_dt() acquires ctx->panel_bridge via
devm_drm_of_get_bridge() -> drm_of_find_panel_or_bridge():
drivers/gpu/drm/drm_panel.c:drm_of_find_panel_or_bridge() {
...
if (bridge) {
...
*bridge = of_drm_find_bridge(remote);
if (*bridge)
return 0;
}
...
}
When the remote DT node is a non-panel bridge, of_drm_find_bridge() drops
the bridge reference before returning, so ctx->panel_bridge holds no
reference. If the downstream bridge is later removed and freed while
sn65dsi83 stays bound, drm_bridge_get(ctx->panel_bridge) increments the
refcount on freed memory and returns a dangling pointer.
Even when the remote node is a drm_panel, devm_drm_panel_bridge_add() is
registered on ctx->dev after devm_drm_bridge_alloc(), so on unbind devres
puts ctx->panel_bridge before ctx->bridge is destroyed without clearing
ctx->panel_bridge; a concurrent holder of ctx->bridge calling
drm_bridge_get_next() can then access ctx->panel_bridge after its
reference was dropped. Acquiring the downstream bridge with
of_drm_get_bridge_by_endpoint() and storing it in ctx->bridge.next_bridge
(or releasing it in a bridge .destroy callback) would keep the reference
alive for the lifetime of ctx->bridge.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=23
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 24/32] drm/bridge: ti-sn65dsi86: implement .get_next_bridge
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (22 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 23/32] drm/bridge: ti-sn65dsi83: " Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:18 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 25/32] drm/bridge: samsung-dsim: " Luca Ceresoli
` (7 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Add get_next_callback func to expose the next bridge.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- add missing drm_bridge_get
---
drivers/gpu/drm/bridge/ti-sn65dsi86.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
index 38318113a534..6dadcd7eb8d1 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
@@ -743,6 +743,13 @@ static int ti_sn_attach_host(struct auxiliary_device *adev, struct ti_sn65dsi86
return devm_mipi_dsi_attach(&adev->dev, dsi);
}
+static struct drm_bridge *sn65dsi86_get_next_bridge(struct drm_bridge *bridge)
+{
+ struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
+
+ return pdata->next_bridge ? drm_bridge_get(pdata->next_bridge) : ERR_PTR(-ENODEV);
+}
+
static int ti_sn_bridge_attach(struct drm_bridge *bridge,
struct drm_encoder *encoder,
enum drm_bridge_attach_flags flags)
@@ -1353,6 +1360,7 @@ static void ti_sn_bridge_hpd_disable(struct drm_bridge *bridge)
}
static const struct drm_bridge_funcs ti_sn_bridge_funcs = {
+ .get_next_bridge = sn65dsi86_get_next_bridge,
.attach = ti_sn_bridge_attach,
.detach = ti_sn_bridge_detach,
.mode_valid = ti_sn_bridge_mode_valid,
@@ -1491,8 +1499,9 @@ static int ti_sn_bridge_probe(struct auxiliary_device *adev,
pdata->bridge.type = pdata->next_bridge->type == DRM_MODE_CONNECTOR_DisplayPort
? DRM_MODE_CONNECTOR_DisplayPort : DRM_MODE_CONNECTOR_eDP;
+ pdata->bridge.ops = DRM_BRIDGE_OP_GET_NEXT_BRIDGE;
if (pdata->bridge.type == DRM_MODE_CONNECTOR_DisplayPort) {
- pdata->bridge.ops = DRM_BRIDGE_OP_EDID | DRM_BRIDGE_OP_DETECT;
+ pdata->bridge.ops |= DRM_BRIDGE_OP_EDID | DRM_BRIDGE_OP_DETECT;
if (client->irq)
pdata->bridge.ops |= DRM_BRIDGE_OP_HPD;
/*
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 24/32] drm/bridge: ti-sn65dsi86: implement .get_next_bridge
2026-11-25 17:50 ` [PATCH v4 24/32] drm/bridge: ti-sn65dsi86: " Luca Ceresoli
@ 2026-11-25 18:18 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:18 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/bridge: ti-sn65dsi86: UAF on pdata->next_bridge in
sn65dsi86_get_next_bridge()
--
commit 79f96bd174206efa5c1019cb2a4980bed689b63c
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/bridge: ti-sn65dsi86: implement .get_next_bridge
This commit implements the .get_next_bridge callback and sets
DRM_BRIDGE_OP_GET_NEXT_BRIDGE to expose the downstream bridge in the
ti-sn65dsi86 driver.
> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> index 38318113a534f..6dadcd7eb8d18 100644
> --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> @@ -743,6 +743,13 @@ static int ti_sn_attach_host(struct auxiliary_device *adev, struct ti_sn65dsi86
> return devm_mipi_dsi_attach(&adev->dev, dsi);
> }
>
> +static struct drm_bridge *sn65dsi86_get_next_bridge(struct drm_bridge *bridge)
> +{
> + struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
> +
> + return pdata->next_bridge ? drm_bridge_get(pdata->next_bridge) : ERR_PTR(-ENODEV);
> +}
[Severity: High]
Can sn65dsi86_get_next_bridge() pass a dangling or ERR_PTR pointer to
drm_bridge_get()?
ti_sn_bridge_probe() obtains pdata->next_bridge with
devm_drm_of_get_bridge(&adev->dev, np, 1, 0). For a non-panel downstream
bridge (such as a DisplayPort connector bridge), devm_drm_of_get_bridge()
does not hold a reference to the returned bridge, so pdata->next_bridge
becomes a dangling pointer if the downstream bridge is removed and freed.
Even for a panel bridge, its devres release is bound to the child
auxiliary device (&adev->dev), whereas pdata->bridge lives on the parent
I2C device and neither ti_sn_bridge_remove() nor the probe error path
clears pdata->next_bridge. In addition, ti_sn_bridge_probe() stores the
result of devm_drm_of_get_bridge() directly into pdata->next_bridge before
checking IS_ERR(), so a failed re-probe leaves an ERR_PTR in
pdata->next_bridge that passes the non-NULL check here and is dereferenced
by drm_bridge_get().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=24
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 25/32] drm/bridge: samsung-dsim: implement .get_next_bridge
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (23 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 24/32] drm/bridge: ti-sn65dsi86: " Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:15 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 26/32] drm/bridge: add drm_bridge_detach_from() Luca Ceresoli
` (6 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Add get_next_callback func to expose the next bridge.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- add missing drm_bridge_get
---
drivers/gpu/drm/bridge/samsung-dsim.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge/samsung-dsim.c
index 480e568dd2c9..a00902871b79 100644
--- a/drivers/gpu/drm/bridge/samsung-dsim.c
+++ b/drivers/gpu/drm/bridge/samsung-dsim.c
@@ -1821,6 +1821,13 @@ static void samsung_dsim_mode_set(struct drm_bridge *bridge,
drm_mode_copy(&dsi->mode, adjusted_mode);
}
+static struct drm_bridge *samsung_dsim_get_next_bridge(struct drm_bridge *bridge)
+{
+ struct samsung_dsim *dsi = bridge_to_dsi(bridge);
+
+ return dsi->bridge.next_bridge ? drm_bridge_get(dsi->bridge.next_bridge) : ERR_PTR(-ENODEV);
+}
+
static int samsung_dsim_attach(struct drm_bridge *bridge,
struct drm_encoder *encoder,
enum drm_bridge_attach_flags flags)
@@ -1832,6 +1839,7 @@ static int samsung_dsim_attach(struct drm_bridge *bridge,
}
static const struct drm_bridge_funcs samsung_dsim_bridge_funcs = {
+ .get_next_bridge = samsung_dsim_get_next_bridge,
.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
.atomic_create_state = drm_atomic_helper_bridge_create_state,
@@ -2183,6 +2191,7 @@ int samsung_dsim_probe(struct platform_device *pdev)
dsi->bridge.of_node = dev->of_node;
dsi->bridge.type = DRM_MODE_CONNECTOR_DSI;
+ dsi->bridge.ops = DRM_BRIDGE_OP_GET_NEXT_BRIDGE;
/* DE_LOW: i.MX8M Mini/Nano LCDIF-DSIM glue logic inverts HS/VS/DE */
if (dsi->plat_data->hw_type == DSIM_TYPE_IMX8MM)
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 25/32] drm/bridge: samsung-dsim: implement .get_next_bridge
2026-11-25 17:50 ` [PATCH v4 25/32] drm/bridge: samsung-dsim: " Luca Ceresoli
@ 2026-11-25 18:15 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:15 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/bridge: samsung-dsim: next_bridge set after
drm_bridge_add()
--
commit 1b84a9a9872c3d15595f65a9e6b8efef31c355b5
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/bridge: samsung-dsim: implement .get_next_bridge
This commit implements the .get_next_bridge callback and sets
DRM_BRIDGE_OP_GET_NEXT_BRIDGE in the samsung-dsim bridge driver.
> diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge/samsung-dsim.c
> index 480e568dd2c9d..a00902871b79e 100644
> --- a/drivers/gpu/drm/bridge/samsung-dsim.c
> +++ b/drivers/gpu/drm/bridge/samsung-dsim.c
> @@ -1821,6 +1821,13 @@ static void samsung_dsim_mode_set(struct drm_bridge *bridge,
> drm_mode_copy(&dsi->mode, adjusted_mode);
> }
>
> +static struct drm_bridge *samsung_dsim_get_next_bridge(struct drm_bridge *bridge)
> +{
> + struct samsung_dsim *dsi = bridge_to_dsi(bridge);
> +
> + return dsi->bridge.next_bridge ? drm_bridge_get(dsi->bridge.next_bridge) : ERR_PTR(-ENODEV);
> +}
[Severity: Medium]
Can samsung_dsim_get_next_bridge() observe dsi->bridge.next_bridge as NULL
when drm_bridge_add() notifies listeners?
In samsung_dsim_host_attach(), drm_bridge_add(&dsi->bridge) is called
before dsi->bridge.next_bridge is assigned:
drivers/gpu/drm/bridge/samsung-dsim.c:samsung_dsim_host_attach() {
...
drm_bridge_add(&dsi->bridge);
if (!(device->mode_flags & MIPI_DSI_MODE_VIDEO)) {
ret = samsung_dsim_register_te_irq(dsi, &device->dev);
if (ret)
goto err_remove_bridge;
}
// The next bridge can be used by host_ops->attach
dsi->bridge.next_bridge = drm_bridge_get(next_bridge);
...
}
Because drm_bridge_add() publishes &dsi->bridge on bridge_list and
synchronously emits DRM_BRIDGE_ADDED, a hotplug handler such as
drm_hotplug_helper_bridge_notif() runs before dsi->bridge.next_bridge is
populated. Calling drm_bridge_get_next() from that notification returns
ERR_PTR(-ENODEV), and drm_hotplug_helper_try_complete() ->
drm_bridge_attach() -> samsung_dsim_attach() passes NULL to
drm_bridge_attach(), failing with -EINVAL and logging a DRM_ERROR().
Assigning dsi->bridge.next_bridge before calling drm_bridge_add() (and
cleaning it up on error) would ensure it is valid as soon as the bridge is
published.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=25
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 26/32] drm/bridge: add drm_bridge_detach_from()
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (24 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 25/32] drm/bridge: samsung-dsim: " Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:15 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 27/32] drm/atomic: add drm_atomic_shutdown_encoder() Luca Ceresoli
` (5 subsequent siblings)
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Supporting bridge hotplug requires the ability to detach all bridges from
the one that got removed to the end of the pipeline. Add a function for
this.
Take care to not try detaching non-attached bridges. This is needed because
when two or more bridges are removed not in the backwards order,
drm_encoder_cleanup_from() is called more than once for bridges closer to
the panel.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
This replaces "drm/encoder: add drm_encoder_cleanup_from()" from v2 as
discussed with Maxime in v1:
https://lore.kernel.org/all/20260609-hypnotic-honeybee-of-adventure-d89b7c@houat/
---
drivers/gpu/drm/drm_bridge.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index e0e0dd7fc12b..c00d5276e55b 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -504,6 +504,40 @@ int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge)
}
EXPORT_SYMBOL(devm_drm_bridge_add);
+/**
+ * drm_bridge_detach_from - detach a given bridge and all the following
+ * from an encoder chain
+ * @bridge: first bridge to remove
+ *
+ * Removes from an encoder all the bridges starting with a given bridge
+ * and until the end of the chain.
+ *
+ * Does nothing if the bridge is not attached to an encoder chain.
+ */
+static void drm_bridge_detach_from(struct drm_bridge *bridge)
+{
+ struct drm_encoder *encoder = bridge->encoder;
+ struct drm_bridge *next;
+ LIST_HEAD(tmplist);
+
+ /*
+ * We need the bridge_chain_mutex to modify the chain, but
+ * drm_bridge_detach() will call DRM_MODESET_LOCK_ALL_BEGIN() (in
+ * drm_modeset_lock_fini()), resulting in a possible ABBA circular
+ * deadlock. Avoid it by first moving all the bridges to a
+ * temporary list holding the lock, and then calling
+ * drm_bridge_detach() without the lock.
+ */
+ mutex_lock(&encoder->bridge_chain_mutex);
+ if (!list_empty(&bridge->chain_node))
+ list_for_each_entry_safe_from(bridge, next, &encoder->bridge_chain, chain_node)
+ list_move_tail(&bridge->chain_node, &tmplist);
+ mutex_unlock(&encoder->bridge_chain_mutex);
+
+ while (!list_empty(&tmplist))
+ drm_bridge_detach(list_first_entry(&tmplist, struct drm_bridge, chain_node));
+}
+
/**
* drm_bridge_remove - unregister a bridge
*
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 26/32] drm/bridge: add drm_bridge_detach_from()
2026-11-25 17:50 ` [PATCH v4 26/32] drm/bridge: add drm_bridge_detach_from() Luca Ceresoli
@ 2026-11-25 18:15 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:15 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/bridge: stack list corruption and infinite loop in
drm_bridge_detach_from()
- [Medium] drm/bridge: unused static drm_bridge_detach_from() breaks
-Werror bisect
--
commit 2c3d13618a66d24a86a5bd8331f35f64a19c35c9
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/bridge: add drm_bridge_detach_from()
This commit adds a helper to detach a bridge and all subsequent bridges in an
encoder's bridge chain.
> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> index e0e0dd7fc12bb..c00d5276e55b3 100644
> --- a/drivers/gpu/drm/drm_bridge.c
> +++ b/drivers/gpu/drm/drm_bridge.c
> @@ -504,6 +504,40 @@ int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge)
> }
> EXPORT_SYMBOL(devm_drm_bridge_add);
>
> +/**
> + * drm_bridge_detach_from - detach a given bridge and all the following
> + * from an encoder chain
> + * @bridge: first bridge to remove
> + *
> + * Removes from an encoder all the bridges starting with a given bridge
> + * and until the end of the chain.
> + *
> + * Does nothing if the bridge is not attached to an encoder chain.
> + */
> +static void drm_bridge_detach_from(struct drm_bridge *bridge)
[Severity: Medium]
Does defining drm_bridge_detach_from() as static without any callers in this
patch break bisection under CONFIG_WERROR=y or CONFIG_DRM_WERROR=y?
drivers/gpu/drm/Makefile enables -Wunused, so compiling drm_bridge.o fails
with -Werror=unused-function until the later commit "drm/bridge: shutdown
encoder and detach downstream bridges on bridge unplug" adds the caller in
drm_bridge_remove(). Marking it __maybe_unused here (or introducing it in
the patch that uses it) avoids the build failure.
Also, the commit message still refers to the v2 name
drm_encoder_cleanup_from() instead of drm_bridge_detach_from().
> +{
> + struct drm_encoder *encoder = bridge->encoder;
> + struct drm_bridge *next;
> + LIST_HEAD(tmplist);
> +
> + /*
> + * We need the bridge_chain_mutex to modify the chain, but
> + * drm_bridge_detach() will call DRM_MODESET_LOCK_ALL_BEGIN() (in
> + * drm_modeset_lock_fini()), resulting in a possible ABBA circular
> + * deadlock. Avoid it by first moving all the bridges to a
> + * temporary list holding the lock, and then calling
> + * drm_bridge_detach() without the lock.
> + */
> + mutex_lock(&encoder->bridge_chain_mutex);
> + if (!list_empty(&bridge->chain_node))
> + list_for_each_entry_safe_from(bridge, next, &encoder->bridge_chain, chain_node)
> + list_move_tail(&bridge->chain_node, &tmplist);
> + mutex_unlock(&encoder->bridge_chain_mutex);
> +
> + while (!list_empty(&tmplist))
> + drm_bridge_detach(list_first_entry(&tmplist, struct drm_bridge, chain_node));
> +}
[Severity: High]
Can moving bridge->chain_node onto a stack-local tmplist cause list
corruption and an infinite loop if a downstream bridge is detached while
drm_bridge_detach_from() is already running?
list_move_tail(&bridge->chain_node, &tmplist) removes each bridge from
encoder->bridge_chain, but leaves bridge->chain_node non-empty while linked
into tmplist on the first caller's stack. drm_bridge_detach() only runs
list_del_init(&bridge->chain_node) after sleeping in
drm_atomic_private_obj_fini() and calling bridge->funcs->detach() without
encoder->bridge_chain_mutex held:
CPU0 CPU1
drm_bridge_detach_from(bridgeA)
mutex_lock(&bridge_chain_mutex)
list_move_tail(bridgeA, &tmplist0)
list_move_tail(bridgeB, &tmplist0)
mutex_unlock(&bridge_chain_mutex)
drm_bridge_detach(bridgeA)
drm_atomic_private_obj_fini()
drm_bridge_detach_from(bridgeB)
mutex_lock(&bridge_chain_mutex)
if (!list_empty(&bridgeB->chain_node))
list_for_each_entry_safe_from(
bridgeB, ...,
&encoder->bridge_chain, ...)
<-- walks tmplist0, never hits
&encoder->bridge_chain
Because bridgeB->chain_node is on CPU0's tmplist0 rather than
encoder->bridge_chain, CPU1's list_for_each_entry_safe_from() walks around
tmplist0 (including the stack list head itself as a struct drm_bridge),
never reaches &encoder->bridge_chain, and corrupts CPU0's stack list while
looping forever under encoder->bridge_chain_mutex.
In addition, if drm_bridge_detach() ever takes its early return on
WARN_ON(!bridge->dev), bridge->chain_node is not unlinked and
while (!list_empty(&tmplist)) spins forever.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=26
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 27/32] drm/atomic: add drm_atomic_shutdown_encoder()
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (25 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 26/32] drm/bridge: add drm_bridge_detach_from() Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 28/32] drm/tests: atomic: add tests for drm_atomic_shutdown_encoder() Luca Ceresoli
` (4 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
To support bridge hotplug we need to stop the components of a card that are
affected by the removal of a bridge: the connector, the encoder and
possibly the CRTC (unless it is still in use after the removal due to
cloning).
drm_atomic_helper_shutdown() does it, but it disables the entire card,
including unrelated CRTCs for multi-CRTC cards. Moreover it is in the
drm_kms_helper module, which makes it unaccessible from the core code where
we need this.
Add drm_atomic_shutdown_encoder() to drm_atomic code, doing what we need.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
New patch in v3
---
drivers/gpu/drm/drm_atomic.c | 145 +++++++++++++++++++++++++++++++++++++++++++
include/drm/drm_atomic.h | 1 +
2 files changed, 146 insertions(+)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 096f85419b36..536813562f6f 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -2207,6 +2207,151 @@ int __drm_atomic_helper_set_config(struct drm_mode_set *set,
}
EXPORT_SYMBOL(__drm_atomic_helper_set_config);
+static int drm_atomic_disable_encoder(struct drm_device *drm,
+ struct drm_encoder *encoder,
+ struct drm_modeset_acquire_ctx *ctx)
+{
+ struct drm_connector_list_iter conn_iter;
+ struct drm_connector *connector;
+ struct drm_crtc *crtc = NULL;
+ struct drm_atomic_commit *commit;
+ struct drm_crtc_state *crtc_state;
+ bool crtc_still_used = false;
+ int ret;
+
+ drm_connector_list_iter_begin(drm, &conn_iter);
+ drm_for_each_connector_iter(connector, &conn_iter) {
+ if (!connector->state ||
+ connector->state->best_encoder != encoder ||
+ !connector->state->crtc)
+ continue;
+
+ crtc = connector->state->crtc;
+ break;
+ }
+ drm_connector_list_iter_end(&conn_iter);
+
+ if (!crtc)
+ return 0;
+
+ commit = drm_atomic_commit_alloc(drm);
+ if (!commit)
+ return -ENOMEM;
+
+ commit->acquire_ctx = ctx;
+
+ crtc_state = drm_atomic_get_crtc_state(commit, crtc);
+ if (IS_ERR(crtc_state)) {
+ ret = PTR_ERR(crtc_state);
+ goto free;
+ }
+
+ drm_connector_list_iter_begin(drm, &conn_iter);
+ drm_for_each_connector_iter(connector, &conn_iter) {
+ struct drm_connector_state *conn_state;
+
+ if (!connector->state || connector->state->crtc != crtc)
+ continue;
+
+ if (connector->state->best_encoder != encoder) {
+ crtc_still_used = true;
+ continue;
+ }
+
+ conn_state = drm_atomic_get_connector_state(commit, connector);
+ if (IS_ERR(conn_state)) {
+ ret = PTR_ERR(conn_state);
+ drm_connector_list_iter_end(&conn_iter);
+ goto free;
+ }
+ }
+ drm_connector_list_iter_end(&conn_iter);
+
+ if (crtc_still_used) {
+ struct drm_connector_state *conn_state;
+ int i;
+
+ /* Some connector still uses @crtc, keep it and its planes enabled */
+ for_each_new_connector_in_state(commit, connector, conn_state, i) {
+ ret = drm_atomic_set_crtc_for_connector(conn_state, NULL);
+ if (ret < 0)
+ goto free;
+ }
+ } else {
+ struct drm_connector_state *conn_state;
+ struct drm_plane_state *plane_state;
+ struct drm_plane *plane;
+ int i;
+
+ crtc_state->active = false;
+
+ ret = drm_atomic_set_mode_prop_for_crtc(crtc_state, NULL);
+ if (ret < 0)
+ goto free;
+
+ ret = drm_atomic_add_affected_planes(commit, crtc);
+ if (ret < 0)
+ goto free;
+
+ ret = drm_atomic_add_affected_connectors(commit, crtc);
+ if (ret < 0)
+ goto free;
+
+ for_each_new_connector_in_state(commit, connector, conn_state, i) {
+ ret = drm_atomic_set_crtc_for_connector(conn_state, NULL);
+ if (ret < 0)
+ goto free;
+ }
+
+ for_each_new_plane_in_state(commit, plane, plane_state, i) {
+ ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
+ if (ret < 0)
+ goto free;
+
+ drm_atomic_set_fb_for_plane(plane_state, NULL);
+ }
+ }
+
+ ret = drm_atomic_commit(commit);
+free:
+ drm_atomic_commit_put(commit);
+ return ret;
+}
+
+/**
+ * drm_atomic_shutdown_encoder - shutdown the pipeline behind an encoder
+ * @encoder: encoder whose pipeline should be shut down
+ *
+ * Stop the output currently driven by @encoder. Also shutdown the
+ * connected CRTC unless other connectors are still attached to it
+ * (e.g. cloning).
+ */
+void drm_atomic_shutdown_encoder(struct drm_encoder *encoder)
+{
+ struct drm_modeset_acquire_ctx ctx;
+ struct drm_device *dev;
+ int ret;
+
+ if (!encoder)
+ return;
+
+ dev = encoder->dev;
+ if (!dev)
+ return;
+
+ if (!drm_drv_uses_atomic_modeset(dev))
+ return;
+
+ DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+
+ ret = drm_atomic_disable_encoder(dev, encoder, &ctx);
+ if (ret)
+ drm_err(dev, "Disabling CRTC for encoder %s failed with %i\n", encoder->name, ret);
+
+ DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+}
+EXPORT_SYMBOL(drm_atomic_shutdown_encoder);
+
void drm_atomic_private_obj_print_state(struct drm_printer *p,
const struct drm_private_state *state)
{
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index c8d0f18fd0fd..9e7bd94922ac 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -1411,5 +1411,6 @@ drm_atomic_get_old_bridge_state(const struct drm_atomic_commit *state,
struct drm_bridge_state *
drm_atomic_get_new_bridge_state(const struct drm_atomic_commit *state,
struct drm_bridge *bridge);
+void drm_atomic_shutdown_encoder(struct drm_encoder *encoder);
#endif /* DRM_ATOMIC_H_ */
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 28/32] drm/tests: atomic: add tests for drm_atomic_shutdown_encoder()
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (26 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 27/32] drm/atomic: add drm_atomic_shutdown_encoder() Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 29/32] drm/bridge: clear bridge->encoder on detach Luca Ceresoli
` (3 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Add KUnit tests to exercise the newly added drm_atomic_shutdown_encoder(),
including in the case of a card with multiple CRTCs.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
New patch in v3
---
drivers/gpu/drm/tests/drm_bridge_test.c | 209 ++++++++++++++++++++++++++++++++
1 file changed, 209 insertions(+)
diff --git a/drivers/gpu/drm/tests/drm_bridge_test.c b/drivers/gpu/drm/tests/drm_bridge_test.c
index f56209c0ab1c..06d08d1316ae 100644
--- a/drivers/gpu/drm/tests/drm_bridge_test.c
+++ b/drivers/gpu/drm/tests/drm_bridge_test.c
@@ -5,6 +5,7 @@
#include <linux/cleanup.h>
#include <linux/media-bus-format.h>
+#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_atomic_state_helper.h>
#include <drm/drm_atomic_uapi.h>
@@ -951,6 +952,213 @@ static struct kunit_suite drm_bridge_alloc_test_suite = {
.test_cases = drm_bridge_alloc_tests,
};
+/*
+ * Two CRTC/encoder/bridge/connector pipelines on the same DRM device, to
+ * check that drm_atomic_shutdown_encoder() only stops one.
+ */
+struct drm_bridge_two_priv {
+ struct drm_device drm;
+ struct drm_plane *plane[2];
+ struct drm_crtc *crtc[2];
+ struct drm_encoder encoder[2];
+ struct drm_bridge_priv *bridge[2];
+ struct drm_connector *connector[2];
+};
+
+static const struct drm_bridge_funcs drm_test_bridge_atomic_no_destroy_funcs = {
+ .atomic_enable = drm_test_bridge_atomic_enable,
+ .atomic_disable = drm_test_bridge_atomic_disable,
+ .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
+ .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
+ .atomic_create_state = drm_atomic_helper_bridge_create_state,
+};
+
+static struct drm_bridge_two_priv *
+drm_test_bridge_two_init(struct kunit *test)
+{
+ struct drm_bridge_two_priv *priv;
+ struct drm_device *drm;
+ struct device *dev;
+ int i, ret;
+
+ dev = drm_kunit_helper_alloc_device(test);
+ if (IS_ERR(dev))
+ return ERR_CAST(dev);
+
+ priv = drm_kunit_helper_alloc_drm_device(test, dev, struct drm_bridge_two_priv,
+ drm, DRIVER_MODESET | DRIVER_ATOMIC);
+ if (IS_ERR(priv))
+ return priv;
+
+ drm = &priv->drm;
+
+ for (i = 0; i < 2; i++) {
+ priv->bridge[i] = devm_drm_bridge_alloc(dev, struct drm_bridge_priv, bridge,
+ &drm_test_bridge_atomic_no_destroy_funcs);
+ if (IS_ERR(priv->bridge[i]))
+ return ERR_CAST(priv->bridge[i]);
+
+ priv->plane[i] = drm_kunit_helper_create_primary_plane(test, drm,
+ NULL, NULL, NULL, 0, NULL);
+ if (IS_ERR(priv->plane[i]))
+ return ERR_CAST(priv->plane[i]);
+
+ priv->crtc[i] = drm_kunit_helper_create_crtc(test, drm,
+ priv->plane[i], NULL, NULL, NULL);
+ if (IS_ERR(priv->crtc[i]))
+ return ERR_CAST(priv->crtc[i]);
+
+ ret = drmm_encoder_init(drm, &priv->encoder[i], NULL, DRM_MODE_ENCODER_TMDS, NULL);
+ if (ret)
+ return ERR_PTR(ret);
+
+ priv->encoder[i].possible_crtcs = drm_crtc_mask(priv->crtc[i]);
+
+ priv->bridge[i]->bridge.type = DRM_MODE_CONNECTOR_VIRTUAL;
+
+ ret = drm_kunit_bridge_add(test, &priv->bridge[i]->bridge);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ret = drm_bridge_attach(&priv->encoder[i], &priv->bridge[i]->bridge, NULL, 0);
+ if (ret)
+ return ERR_PTR(ret);
+
+ priv->connector[i] = drm_bridge_connector_init(drm, &priv->encoder[i]);
+ if (IS_ERR(priv->connector[i]))
+ return ERR_CAST(priv->connector[i]);
+ }
+
+ drm_mode_config_reset(drm);
+
+ return priv;
+}
+
+static int drm_test_enable_pipeline(struct kunit *test,
+ struct drm_device *drm,
+ struct drm_crtc *crtc,
+ struct drm_connector *connector,
+ const struct drm_display_mode *mode)
+{
+ struct drm_modeset_acquire_ctx ctx;
+ int ret;
+
+ drm_modeset_acquire_init(&ctx, 0);
+
+retry:
+ ret = drm_kunit_helper_enable_crtc_connector(test, drm, crtc, connector, mode, &ctx);
+ if (ret == -EDEADLK) {
+ drm_modeset_backoff(&ctx);
+ goto retry;
+ }
+
+ drm_modeset_drop_locks(&ctx);
+ drm_modeset_acquire_fini(&ctx);
+
+ return ret;
+}
+
+/*
+ * Test that drm_atomic_shutdown_encoder() disables the CRTC feeding the
+ * encoder and detaches its connector.
+ */
+static void drm_test_drm_atomic_shutdown_encoder(struct kunit *test)
+{
+ struct drm_bridge_init_priv *priv;
+ struct drm_display_mode *mode;
+ struct drm_bridge_priv *bridge_priv;
+ int ret;
+
+ priv = drm_test_bridge_init(test, &drm_test_bridge_atomic_funcs);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);
+
+ mode = drm_kunit_display_mode_from_cea_vic(test, &priv->drm, 16);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mode);
+
+ ret = drm_test_enable_pipeline(test, &priv->drm, priv->crtc, priv->connector, mode);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ bridge_priv = priv->test_bridge;
+ KUNIT_ASSERT_EQ(test, bridge_priv->enable_count, 1);
+ KUNIT_ASSERT_EQ(test, bridge_priv->disable_count, 0);
+ KUNIT_ASSERT_PTR_EQ(test, priv->connector->state->crtc, priv->crtc);
+
+ drm_atomic_shutdown_encoder(&priv->encoder);
+
+ KUNIT_EXPECT_EQ(test, bridge_priv->disable_count, 1);
+ KUNIT_EXPECT_NULL(test, priv->connector->state->crtc);
+ KUNIT_EXPECT_FALSE(test, priv->crtc->state->active);
+}
+
+/*
+ * Test that drm_atomic_shutdown_encoder() is a no-op when the encoder is not
+ * driving any output.
+ */
+static void drm_test_drm_atomic_shutdown_encoder_disabled(struct kunit *test)
+{
+ struct drm_bridge_init_priv *priv;
+ struct drm_bridge_priv *bridge_priv;
+
+ priv = drm_test_bridge_init(test, &drm_test_bridge_atomic_funcs);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);
+
+ bridge_priv = priv->test_bridge;
+
+ drm_atomic_shutdown_encoder(&priv->encoder);
+
+ KUNIT_EXPECT_EQ(test, bridge_priv->enable_count, 0);
+ KUNIT_EXPECT_EQ(test, bridge_priv->disable_count, 0);
+ KUNIT_EXPECT_NULL(test, priv->connector->state->crtc);
+}
+
+/*
+ * Test that drm_atomic_shutdown_encoder() only stops the pipeline of the
+ * given encoder and leaves the other CRTC untouched.
+ */
+static void drm_test_drm_atomic_shutdown_encoder_two_crtcs(struct kunit *test)
+{
+ struct drm_bridge_two_priv *priv;
+ struct drm_display_mode *mode;
+ int ret;
+
+ priv = drm_test_bridge_two_init(test);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);
+
+ mode = drm_kunit_display_mode_from_cea_vic(test, &priv->drm, 16);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mode);
+
+ ret = drm_test_enable_pipeline(test, &priv->drm, priv->crtc[0], priv->connector[0], mode);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ ret = drm_test_enable_pipeline(test, &priv->drm, priv->crtc[1], priv->connector[1], mode);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ KUNIT_ASSERT_EQ(test, priv->bridge[0]->enable_count, 1);
+ KUNIT_ASSERT_EQ(test, priv->bridge[1]->enable_count, 1);
+
+ drm_atomic_shutdown_encoder(&priv->encoder[0]);
+
+ KUNIT_EXPECT_EQ(test, priv->bridge[0]->disable_count, 1);
+ KUNIT_EXPECT_NULL(test, priv->connector[0]->state->crtc);
+ KUNIT_EXPECT_FALSE(test, priv->crtc[0]->state->active);
+
+ KUNIT_EXPECT_EQ(test, priv->bridge[1]->disable_count, 0);
+ KUNIT_EXPECT_PTR_EQ(test, priv->connector[1]->state->crtc, priv->crtc[1]);
+ KUNIT_EXPECT_TRUE(test, priv->crtc[1]->state->active);
+}
+
+static struct kunit_case drm_atomic_shutdown_encoder_tests[] = {
+ KUNIT_CASE(drm_test_drm_atomic_shutdown_encoder),
+ KUNIT_CASE(drm_test_drm_atomic_shutdown_encoder_disabled),
+ KUNIT_CASE(drm_test_drm_atomic_shutdown_encoder_two_crtcs),
+ { }
+};
+
+static struct kunit_suite drm_atomic_shutdown_encoder_test_suite = {
+ .name = "drm_atomic_shutdown_encoder",
+ .test_cases = drm_atomic_shutdown_encoder_tests,
+};
+
/**
* drm_test_bridge_chain_verify_fmt - Verify bridge chain format selection
* @test: pointer to KUnit test object
@@ -1381,6 +1589,7 @@ kunit_test_suites(
&drm_bridge_get_current_state_test_suite,
&drm_bridge_helper_reset_crtc_test_suite,
&drm_bridge_alloc_test_suite,
+ &drm_atomic_shutdown_encoder_test_suite,
&drm_bridge_bus_fmt_test_suite,
);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 29/32] drm/bridge: clear bridge->encoder on detach
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (27 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 28/32] drm/tests: atomic: add tests for drm_atomic_shutdown_encoder() Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug Luca Ceresoli
` (2 subsequent siblings)
31 siblings, 0 replies; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Attaching a bridge to an encoder rightfully sets bridge->encoder to point
to the encoder. It also sets it to NULL in the error management path.
However drm_bridge_detach() does not set bridge->encoder to NULL.
This will create a potential NULL pointer dereference in a following commit
(part of when introducing DRM bridge hotplug) because drm_bridge_remove()
will have to detach bridges attached to an encoder, so it needs to use 'if
(bridge->encoder)' to know whether the bridge is attached to an
encoder. For this to work, the bridge->encoder pointer must NULL whenever
the bridge is not attached to an encoder.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Issue found by sashiko:
https://lore.kernel.org/all/20261001131425.A001E1F000FF@smtp.kernel.org/
---
drivers/gpu/drm/drm_bridge.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index c00d5276e55b..d82e81b26ace 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -751,6 +751,7 @@ void drm_bridge_detach(struct drm_bridge *bridge)
drm_hotplug_event_notifier_notify(DRM_BRIDGE_DETACHED, bridge);
bridge->dev = NULL;
+ bridge->encoder = NULL;
drm_bridge_put(bridge);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (28 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 29/32] drm/bridge: clear bridge->encoder on detach Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:28 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 32/32] drm/mxsfb/lcdif: enable " Luca Ceresoli
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
With the upcoming support for DRM bridge hot(un)plugging, bridges can be
removed at any time. When this happens, shutdown the affected pipeline
components and detach from the encoder chain the bridge being removed along
with all the following ones.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
changes in v3:
- do not shutdown the whole card
- adapt to use drm_bridge_detach_from()
---
drivers/gpu/drm/drm_bridge.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index d82e81b26ace..d942c776db1a 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -29,6 +29,7 @@
#include <linux/mutex.h>
#include <linux/srcu.h>
+#include <drm/drm_atomic.h>
#include <drm/drm_atomic_state_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_debugfs.h>
@@ -547,9 +548,17 @@ static void drm_bridge_detach_from(struct drm_bridge *bridge)
* it won't be found by users via of_drm_find_and_get_bridge(), and add it
* to the lingering bridge list, to keep track of it until its allocated
* memory is eventually freed.
+ *
+ * If the bridge is currently attached, also shut down the encoder pipeline
+ * and detach this bridge and the following ones.
*/
void drm_bridge_remove(struct drm_bridge *bridge)
{
+ if (bridge->encoder) {
+ drm_atomic_shutdown_encoder(bridge->encoder);
+ drm_bridge_detach_from(bridge);
+ }
+
mutex_lock(&bridge_lock);
list_move_tail(&bridge->list, &bridge_lingering_list);
mutex_unlock(&bridge_lock);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug
2026-11-25 17:50 ` [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug Luca Ceresoli
@ 2026-11-25 18:28 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:28 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/bridge: UAF of shared encoder-bridge container in
drm_bridge_remove()
- [High] drm/bridge: TOCTOU race and NULL deref on encoder in
drm_bridge_remove()
- [High] drm/bridge: cross-thread stack tmplist corruption in
drm_bridge_detach_from()
- [Medium] drm/bridge: bridge left on bridge_list during detach in
drm_bridge_remove()
--
commit ed101139b3ca92ec58e58cfca1356ce33f6b56c4
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug
This commit shuts down the encoder pipeline and detaches the removed
bridge and any downstream bridges from the encoder chain when
drm_bridge_remove() is called on an attached bridge.
> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> index d82e81b26ace2..d942c776db1a9 100644
> --- a/drivers/gpu/drm/drm_bridge.c
> +++ b/drivers/gpu/drm/drm_bridge.c
[ ... ]
> @@ -547,9 +548,17 @@ static void drm_bridge_detach_from(struct drm_bridge *bridge)
> * it won't be found by users via of_drm_find_and_get_bridge(), and add it
> * to the lingering bridge list, to keep track of it until its allocated
> * memory is eventually freed.
> + *
> + * If the bridge is currently attached, also shut down the encoder pipeline
> + * and detach this bridge and the following ones.
> */
> void drm_bridge_remove(struct drm_bridge *bridge)
> {
> + if (bridge->encoder) {
> + drm_atomic_shutdown_encoder(bridge->encoder);
> + drm_bridge_detach_from(bridge);
> + }
[Severity: High]
Does detaching the bridge in drm_bridge_remove() cause a use-after-free of
the encoder in drivers that embed struct drm_bridge and struct drm_encoder
in the same devm_drm_bridge_alloc() container, such as tidss and meson?
drivers/gpu/drm/tidss/tidss_encoder.c:tidss_encoder_create() {
t_enc = devm_drm_bridge_alloc(tidss->dev, struct tidss_encoder,
bridge, &tidss_bridge_funcs);
if (IS_ERR(t_enc))
return PTR_ERR(t_enc);
ret = drm_encoder_init(&tidss->ddev, &t_enc->encoder,
&tidss_encoder_funcs, encoder_type, NULL);
...
}
In tidss, devm_drm_dev_alloc() and drmm_mode_config_init() are registered
before tidss_encoder_create() calls devm_drm_bridge_alloc(),
drm_encoder_init(), devm_drm_bridge_add(), and drm_bridge_attach().
On driver unbind or post-encoder probe failure, devres releases actions in
reverse order: drm_bridge_remove_void() now detaches t_enc->bridge and
drops both the attach and add references, and then drm_bridge_put_void()
drops the final allocation reference. __drm_bridge_free() calls
kfree(bridge->container), freeing t_enc while t_enc->encoder is still on
mode_config.encoder_list. When devm_drm_dev_init_release() later runs
drm_mode_config_cleanup(), it calls drm_encoder_cleanup() on the freed
t_enc->encoder.
[Severity: High]
Can a concurrent upstream bridge removal clear bridge->encoder while
drm_atomic_shutdown_encoder() is sleeping, causing a NULL pointer
dereference in drm_bridge_detach_from()?
CPU0 (downstream bridge B) CPU1 (upstream bridge A)
drm_bridge_remove(B)
if (B->encoder)
drm_atomic_shutdown_encoder()
drm_bridge_remove(A)
...
drm_bridge_detach_from(A)
drm_bridge_detach(B)
B->encoder = NULL
drm_bridge_detach_from(B)
encoder = B->encoder
mutex_lock(&encoder->bridge_chain_mutex)
<-- NULL pointer dereference
drm_bridge_detach_from() re-reads bridge->encoder without a NULL check
before locking encoder->bridge_chain_mutex. Similarly, if
drm_bridge_remove() races with drm_encoder_cleanup(), the encoder and its
mutex can be destroyed and freed before drm_bridge_detach_from() locks it;
and if it races with drm_bridge_attach() after bridge->encoder is assigned
but before bridge->chain_node is added to encoder->bridge_chain,
drm_bridge_detach_from() sees list_empty(&bridge->chain_node) and leaves
the removed bridge attached.
[Severity: High]
Can concurrent calls to drm_bridge_detach_from() on two bridges in the
same chain corrupt the stack list head in the upstream caller?
drivers/gpu/drm/drm_bridge.c:drm_bridge_detach_from() {
...
mutex_lock(&encoder->bridge_chain_mutex);
if (!list_empty(&bridge->chain_node))
list_for_each_entry_safe_from(bridge, next, &encoder->bridge_chain, chain_node)
list_move_tail(&bridge->chain_node, &tmplist);
mutex_unlock(&encoder->bridge_chain_mutex);
while (!list_empty(&tmplist))
drm_bridge_detach(list_first_entry(&tmplist, struct drm_bridge, chain_node));
}
When drm_bridge_detach_from() moves bridge A and downstream bridge B onto
its stack-allocated tmplist and drops encoder->bridge_chain_mutex, B's
chain_node is still non-empty (linked into that stack tmplist) and
B->encoder is still non-NULL until drm_bridge_detach(B) reaches
list_del_init(&B->chain_node):
CPU0 (upstream bridge A) CPU1 (downstream bridge B)
drm_bridge_detach_from(A)
mutex_lock(&bridge_chain_mutex)
/* moves A and B to CPU0 tmplist */
mutex_unlock(&bridge_chain_mutex)
drm_bridge_detach(A)
drm_atomic_private_obj_fini()
drm_bridge_remove(B)
...
drm_bridge_detach_from(B)
mutex_lock(&bridge_chain_mutex)
if (!list_empty(&B->chain_node))
list_for_each_entry_safe_from(...)
list_move_tail(..., &tmplist)
<-- walks CPU0 tmplist past
its stack list head
Because B->chain_node is on CPU0's tmplist rather than
encoder->bridge_chain, CPU1's list_for_each_entry_safe_from() never sees
&encoder->bridge_chain as the termination head. It moves CPU0's stack
tmplist head onto CPU1's tmplist and passes a bogus struct drm_bridge
pointer derived from CPU0's stack frame to drm_bridge_detach().
> +
> mutex_lock(&bridge_lock);
> list_move_tail(&bridge->list, &bridge_lingering_list);
> mutex_unlock(&bridge_lock);
[Severity: Medium]
Should bridge->list be moved to bridge_lingering_list before shutting down
the encoder and detaching the bridge?
Leaving the bridge on bridge_list until after drm_bridge_detach_from()
means the bridge is still discoverable via of_drm_find_and_get_bridge() or
drm_bridge_get_next() while drm_bridge_detach() emits DRM_BRIDGE_DETACHED
and clears bridge->dev and bridge->encoder, allowing a concurrent lookup
to find and re-attach the bridge right before drm_bridge_remove() moves it
to bridge_lingering_list and destroys its HPD mutexes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=30
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (29 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:30 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 32/32] drm/mxsfb/lcdif: enable " Luca Ceresoli
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Add a new helper to support cards implementing hotpluggable drm_bridges.
drmm_hotplug_helper_init() registers to get notified of relevant events and
react by creating a bridge (if the pipeline is complete in the hardware)
and destroying it on bridge removal.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v3:
- Do not require the first bridge is non-hotpluggable
- Support non-DSI bridges too
- Add callback to report connector add/remove
- Do not store the drm_device pointer, get it from the encoder
- use new v3 notifier API name
Changes in v2:
- Add callback to report connector addition/removal
- Sanity-check drmm_hotplug_helper_init() parameters
- Reformat kdoc comment
---
MAINTAINERS | 8 +
drivers/gpu/drm/display/Kconfig | 7 +
drivers/gpu/drm/display/Makefile | 2 +
drivers/gpu/drm/display/drm_hotplug_helper.c | 325 +++++++++++++++++++++++++++
include/drm/drm_hotplug_helper.h | 30 +++
5 files changed, 372 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index a5e2bf15e59f..18ecb7bb39f4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8219,6 +8219,14 @@ F: Documentation/devicetree/bindings/npu/rockchip,rk3588-rknn-core.yaml
F: drivers/accel/rocket/
F: include/uapi/drm/rocket_accel.h
+DRM BRIDGE HOTPLUG HELPER
+M: Luca Ceresoli <luca.ceresoli@bootlin.com>
+S: Maintained
+T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F: Documentation/devicetree/bindings/display/bridge/
+F: drivers/gpu/drm/display/drm_hotplug_helper.c
+F: include/drm/drm_hotplug_helper.h
+
DRM COMPUTE ACCELERATORS DRIVERS AND FRAMEWORK
M: Oded Gabbay <ogabbay@kernel.org>
L: dri-devel@lists.freedesktop.org
diff --git a/drivers/gpu/drm/display/Kconfig b/drivers/gpu/drm/display/Kconfig
index df09cf9a8ca1..e086e2fd08a4 100644
--- a/drivers/gpu/drm/display/Kconfig
+++ b/drivers/gpu/drm/display/Kconfig
@@ -22,6 +22,13 @@ config DRM_BRIDGE_CONNECTOR
help
DRM connector implementation terminating DRM bridge chains.
+config DRM_HOTPLUG_HELPER
+ bool
+ depends on OF
+ select DRM_BRIDGE_CONNECTOR
+ help
+ Helper code to implement a card supporting hotpluggable bridges.
+
config DRM_DISPLAY_DP_AUX_CEC
bool "Enable DisplayPort CEC-Tunneling-over-AUX HDMI support"
select DRM_DISPLAY_DP_HELPER
diff --git a/drivers/gpu/drm/display/Makefile b/drivers/gpu/drm/display/Makefile
index 0ff4a1ad0222..ce6dbd65833b 100644
--- a/drivers/gpu/drm/display/Makefile
+++ b/drivers/gpu/drm/display/Makefile
@@ -5,6 +5,8 @@ obj-$(CONFIG_DRM_DISPLAY_DP_AUX_BUS) += drm_dp_aux_bus.o
drm_display_helper-y := drm_display_helper_mod.o
drm_display_helper-$(CONFIG_DRM_BRIDGE_CONNECTOR) += \
drm_bridge_connector.o
+drm_display_helper-$(CONFIG_DRM_HOTPLUG_HELPER) += \
+ drm_hotplug_helper.o
drm_display_helper-$(CONFIG_DRM_DISPLAY_DP_HELPER) += \
drm_dp_dual_mode_helper.o \
drm_dp_helper.o \
diff --git a/drivers/gpu/drm/display/drm_hotplug_helper.c b/drivers/gpu/drm/display/drm_hotplug_helper.c
new file mode 100644
index 000000000000..ea32bdb0af8f
--- /dev/null
+++ b/drivers/gpu/drm/display/drm_hotplug_helper.c
@@ -0,0 +1,325 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 GE HealthCare
+ * Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
+ */
+
+#include <linux/of.h>
+#include <linux/of_graph.h>
+
+#include <drm/drm_bridge.h>
+#include <drm/drm_bridge_connector.h>
+#include <drm/drm_hotplug_event_notifier.h>
+#include <drm/drm_hotplug_helper.h>
+#include <drm/drm_managed.h>
+#include <drm/drm_print.h>
+
+struct drm_hotplug_helper {
+ /**
+ * @encoder: The encoder at the start of the bridges chain
+ */
+ struct drm_encoder *encoder;
+ /**
+ * @event_cb: Callback to report connector addition/removal
+ */
+ drm_hotplug_helper_event_cb event_cb;
+ /**
+ * @drm_event_nb: Notifier to receive DRM hotplug-related events
+ */
+ struct notifier_block drm_event_nb;
+ /**
+ * @connector: The drm_connector added/removed on plug/unplug
+ */
+ struct drm_connector *connector;
+ /**
+ * @event_mutex: Protect entry points (init, fini, event notifier)
+ * from concurrent attach and connector creation or destruction
+ */
+ struct mutex event_mutex;
+ /**
+ * @first_bridge_ep: Device tree node of the encoder endpoint
+ * connected to the first bridge
+ */
+ struct device_node *first_bridge_ep;
+};
+
+/*
+ * True if the encoder bridge chain is complete, i.e. the last bridge in
+ * the chain is the last bridge expected in the hardware (e.g. a panel).
+ */
+static bool drm_hotplug_helper_bridge_chain_is_complete(struct drm_hotplug_helper *hotplug_helper)
+{
+ struct drm_bridge *last_bridge __free(drm_bridge_put) =
+ drm_bridge_chain_get_last_bridge(hotplug_helper->encoder);
+ struct drm_device *drm = hotplug_helper->encoder->dev;
+
+ /* We expect at least one bridge */
+ if (!last_bridge) {
+ drm_dbg_driver(drm, "no bridges in pipeline (yet)\n");
+ return false;
+ }
+
+ struct drm_bridge *next_bridge __free(drm_bridge_put) =
+ drm_bridge_get_next(last_bridge);
+
+ /* No next bridge expected, pipeline is complete */
+ if (!next_bridge) {
+ drm_dbg_driver(drm, "pipeline complete\n");
+ return true;
+ }
+
+ /* Next bridge expected but not there now, pipeline incomplete */
+ if (next_bridge == ERR_PTR(-ENODEV)) {
+ drm_dbg_driver(drm, "pipeline not (yet) complete\n");
+ return false;
+ }
+
+ /* Unexpected error */
+ if (IS_ERR(next_bridge))
+ drm_warn(drm, "%s error %pe\n", __func__, next_bridge);
+
+ /* next_bridge is valid, but not (yet|anymore) in chain */
+ return false;
+}
+
+/**
+ * drm_hotplug_helper_connector_add - add the drm_connector
+ * @hotplug_helper: drm_hotplug_helper to add the drm_connector to
+ *
+ * Returns 0 on success or a negative error otherwise.
+ */
+static int drm_hotplug_helper_connector_add(struct drm_hotplug_helper *hotplug_helper)
+{
+ struct drm_device *drm = hotplug_helper->encoder->dev;
+ struct drm_connector *connector;
+
+ if (drm_WARN_ON(drm, hotplug_helper->connector))
+ return -EBUSY;
+
+ connector = drm_bridge_connector_dynamic_add(drm, hotplug_helper->encoder);
+ if (IS_ERR(connector))
+ return PTR_ERR(connector);
+
+ hotplug_helper->connector = connector;
+ hotplug_helper->event_cb(DRM_HOTPLUG_HELPER_CONNECTOR_ADDED, connector);
+
+ dev_dbg(drm->dev, "added bridge connector\n");
+
+ return 0;
+}
+
+/*
+ * Removes the connector, which must be present.
+ *
+ * Must be called with the hotplug_helper->event_mutex locked.
+ */
+static void drm_hotplug_helper_connector_remove(struct drm_hotplug_helper *hotplug_helper)
+{
+ struct drm_device *drm = hotplug_helper->encoder->dev;
+
+ if (drm_WARN_ON(drm, !hotplug_helper->connector))
+ return;
+
+ dev_dbg(drm->dev, "removing bridge connector\n");
+
+ hotplug_helper->event_cb(DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING, hotplug_helper->connector);
+ drm_bridge_connector_dynamic_remove(hotplug_helper->connector);
+ hotplug_helper->connector = NULL;
+}
+
+/*
+ * Propagate the attach chain and possibly add a drm_bridge_connector after
+ * a new drm_bridge is hot-plugged.
+ *
+ * The connector is added only if the pipeline is now complete. This could
+ * not be the case for various reasons:
+ *
+ * - the new bridge is just unrelated to our encoder
+ * - the new bridge is not the next one in the pipeline
+ * - the new bridge is the next in the pipeline but the pipeline is not yet
+ * complete
+ *
+ * All these cases are normal, not an error.
+ *
+ * Must be called with the hotplug_helper->event_mutex locked.
+ */
+static void drm_hotplug_helper_try_complete(struct drm_hotplug_helper *hotplug_helper)
+{
+ struct device *dev = hotplug_helper->encoder->dev->dev;
+ int err;
+
+ WARN_ON(!mutex_is_locked(&hotplug_helper->event_mutex));
+
+ /*
+ * drm_connector already present, the new bridge must be for
+ * another card
+ */
+ if (hotplug_helper->connector)
+ return;
+
+ struct drm_bridge *last_bridge __free(drm_bridge_put) =
+ drm_bridge_chain_get_last_bridge(hotplug_helper->encoder);
+
+ if (last_bridge) {
+ /*
+ * Some bridge(s) already in the chain, propagate the
+ * attach call chain from the current chain tail to newly
+ * hotplugged bridge(s)
+ */
+ dev_dbg(dev, "propagate attach after %ps\n", last_bridge->funcs);
+
+ err = last_bridge->funcs->attach(last_bridge, hotplug_helper->encoder,
+ DRM_BRIDGE_ATTACH_NO_CONNECTOR);
+ if (err)
+ return;
+ } else {
+ /* Bridge chain still empty, find first bridge and attach */
+
+ const struct device_node *first_bridge_node __free(device_node) =
+ of_graph_get_remote_port_parent(hotplug_helper->first_bridge_ep);
+ if (!of_device_is_available(first_bridge_node))
+ return;
+
+ struct drm_bridge *first_bridge __free(drm_bridge_put) =
+ of_drm_find_and_get_bridge(first_bridge_node);
+ if (!first_bridge)
+ return;
+
+ dev_dbg(dev, "attach chain starting at %ps\n", first_bridge->funcs);
+
+ err = drm_bridge_attach(hotplug_helper->encoder, first_bridge, NULL,
+ DRM_BRIDGE_ATTACH_NO_CONNECTOR);
+ if (err)
+ return;
+ }
+
+ /* Add the connector if the encoder chain is now complete */
+ if (drm_hotplug_helper_bridge_chain_is_complete(hotplug_helper))
+ drm_hotplug_helper_connector_add(hotplug_helper);
+}
+
+static int drm_hotplug_helper_handle_event(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct drm_hotplug_helper *hotplug_helper =
+ container_of(nb, struct drm_hotplug_helper, drm_event_nb);
+ struct device *dev = hotplug_helper->encoder->dev->dev;
+
+ guard(mutex)(&hotplug_helper->event_mutex);
+
+ dev_dbg(dev, "received event %lu\n", event);
+
+ switch (event) {
+ case DRM_BRIDGE_ADDED:
+ case DRM_MIPI_DSI_ATTACHED:
+ /*
+ * A bridges hot-plugged, try adding the
+ * drm_bridge_connector
+ */
+ drm_hotplug_helper_try_complete(hotplug_helper);
+ break;
+ case DRM_BRIDGE_DETACHED:
+ {
+ /*
+ * A bridge was unplugged, remove the drm_bridge_connector
+ * if it's part of the same pipeline
+ */
+ struct drm_bridge *bridge = (struct drm_bridge *)data;
+
+ if (hotplug_helper->connector &&
+ bridge->encoder == hotplug_helper->encoder)
+ drm_hotplug_helper_connector_remove(hotplug_helper);
+ break;
+ }
+ default:
+ }
+
+ return NOTIFY_DONE;
+}
+
+static void drmm_hotplug_helper_fini(struct drm_device *dev, void *res)
+{
+ struct drm_hotplug_helper *hotplug_helper = (struct drm_hotplug_helper *)res;
+
+ guard(mutex)(&hotplug_helper->event_mutex);
+
+ if (hotplug_helper->connector)
+ drm_hotplug_helper_connector_remove(hotplug_helper);
+
+ of_node_put(hotplug_helper->first_bridge_ep);
+}
+
+static void drmm_hotplug_helper_notifier_unregister(struct drm_device *dev, void *res)
+{
+ struct notifier_block *nb = (struct notifier_block *)res;
+
+ drm_hotplug_event_notifier_unregister(nb);
+}
+
+/**
+ * drmm_hotplug_helper_init - Initialise the hotplug helper for an encoder
+ * @encoder: the encoder where the bridge chain starts; must be already
+ * associated to the drm_device (e.g. by drm_encoder_init())
+ * @event_cb: callback invoked when a drm_connector is added or removed
+ * @first_bridge_ep: device tree node of the encoder endpoint connected to
+ * the first bridge
+ *
+ * Register to receive hotplug-related events and react to them:
+ * - when a new bridge appears: tries to attach the whole bridge chain,
+ * then checks if the pipeline is now complete, and if it is it adds a
+ * drm_bridge_connector (which in turn will add a drm_connector)
+ * - when a bridge disappears, remove the drm_bridge_connector (which in
+ * turn will remove the drm_connector)
+ *
+ * When a connector is added or removed, the @event_cb will be called.
+ *
+ * The caller does not need to attach the bridge(s) anymore because the
+ * hotplug_helper will do it, including at init time in case all bridges
+ * are present already.
+ *
+ * Returns a pointer to the new &drm_hotplug_helper on success, or a
+ * negative error pointer otherwise.
+ */
+struct drm_hotplug_helper *drmm_hotplug_helper_init(struct drm_encoder *encoder,
+ drm_hotplug_helper_event_cb event_cb,
+ struct device_node *first_bridge_ep)
+{
+ struct drm_hotplug_helper *hotplug_helper;
+ int ret;
+
+ if (!encoder || !event_cb || !first_bridge_ep)
+ return ERR_PTR(-EINVAL);
+
+ struct drm_device *drm = encoder->dev;
+ if (WARN_ON(IS_ERR_OR_NULL(drm)))
+ return ERR_PTR(-EINVAL);
+
+ hotplug_helper = drmm_kzalloc(drm, sizeof(*hotplug_helper), GFP_KERNEL);
+ if (!hotplug_helper)
+ return ERR_PTR(-ENOMEM);
+
+ mutex_init(&hotplug_helper->event_mutex);
+ hotplug_helper->encoder = encoder;
+ hotplug_helper->event_cb = event_cb;
+ hotplug_helper->drm_event_nb.notifier_call = drm_hotplug_helper_handle_event;
+ hotplug_helper->first_bridge_ep = of_node_get(first_bridge_ep);
+
+ ret = drmm_add_action_or_reset(drm, drmm_hotplug_helper_fini, hotplug_helper);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ret = drm_hotplug_event_notifier_register(&hotplug_helper->drm_event_nb);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ret = drmm_add_action_or_reset(drm, drmm_hotplug_helper_notifier_unregister,
+ &hotplug_helper->drm_event_nb);
+ if (ret)
+ return ERR_PTR(ret);
+
+ guard(mutex)(&hotplug_helper->event_mutex);
+ drm_hotplug_helper_try_complete(hotplug_helper);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(drmm_hotplug_helper_init);
diff --git a/include/drm/drm_hotplug_helper.h b/include/drm/drm_hotplug_helper.h
new file mode 100644
index 000000000000..ba14d547f8ff
--- /dev/null
+++ b/include/drm/drm_hotplug_helper.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2026 GE HealthCare
+ * Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
+ */
+
+#ifndef __DRM_HOTPLUG_HELPER_H__
+#define __DRM_HOTPLUG_HELPER_H__
+
+/**
+ * enum drm_hotplug_helper_event - DRM hotplug helper connector events
+ */
+enum drm_hotplug_helper_event {
+ /** @DRM_HOTPLUG_HELPER_CONNECTOR_ADDED: A drm_connector has just been added */
+ DRM_HOTPLUG_HELPER_CONNECTOR_ADDED,
+ /** @DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING: A drm_connector is about to be removed */
+ DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING,
+};
+
+/**
+ * drm_hotplug_helper_event_cb - Callback to report connector addition and removal.
+ */
+typedef void (*drm_hotplug_helper_event_cb)(enum drm_hotplug_helper_event event,
+ struct drm_connector *connector);
+
+struct drm_hotplug_helper *drmm_hotplug_helper_init(struct drm_encoder *encoder,
+ drm_hotplug_helper_event_cb event_cb,
+ struct device_node *next_bridge_ep);
+
+#endif /* __DRM_HOTPLUG_HELPER_H__ */
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug
2026-11-25 17:50 ` [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug Luca Ceresoli
@ 2026-11-25 18:30 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:30 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drm: invalid direct attach() call in
drm_hotplug_helper_try_complete()
- [Medium] drm: drmm_hotplug_helper_init() returns NULL on success
- [Medium] drm: race with bridge detach in
drm_hotplug_helper_try_complete()
- [Low] drm: missing forward declarations and broken kdoc in
drm_hotplug_helper.h
- [Low] drm: MAINTAINERS hotplug helper entry claims all bridge DT
bindings
--
commit 965c3e7b932068825241acd70d8d77673075709c
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm: drm_hotplug_helper: new helper to implement bridge hotplug
This commit adds drmm_hotplug_helper_init() to listen for DRM bridge hotplug
events, attach the encoder's bridge chain, and dynamically add or remove a
drm_bridge_connector as the pipeline completes or breaks.
> diff --git a/MAINTAINERS b/MAINTAINERS
> index a5e2bf15e59f2..18ecb7bb39f40 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -8219,6 +8219,14 @@ F: Documentation/devicetree/bindings/npu/rockchip,rk3588-rknn-core.yaml
> F: drivers/accel/rocket/
> F: include/uapi/drm/rocket_accel.h
>
> +DRM BRIDGE HOTPLUG HELPER
> +M: Luca Ceresoli <luca.ceresoli@bootlin.com>
> +S: Maintained
> +T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
> +F: Documentation/devicetree/bindings/display/bridge/
> +F: drivers/gpu/drm/display/drm_hotplug_helper.c
> +F: include/drm/drm_hotplug_helper.h
> +
> DRM COMPUTE ACCELERATORS DRIVERS AND FRAMEWORK
> M: Oded Gabbay <ogabbay@kernel.org>
> L: dri-devel@lists.freedesktop.org
[Severity: Low]
Should the Documentation/devicetree/bindings/display/bridge/ line be dropped
here? That path covers all bridge chip bindings (already listed under DRM
DRIVERS FOR BRIDGE CHIPS), whereas drm_hotplug_helper is an in-kernel helper
with no devicetree bindings of its own.
> diff --git a/drivers/gpu/drm/display/drm_hotplug_helper.c b/drivers/gpu/drm/display/drm_hotplug_helper.c
> new file mode 100644
> index 0000000000000..ea32bdb0af8f3
> --- /dev/null
> +++ b/drivers/gpu/drm/display/drm_hotplug_helper.c
[ ... ]
> +static void drm_hotplug_helper_try_complete(struct drm_hotplug_helper *hotplug_helper)
> +{
> + struct device *dev = hotplug_helper->encoder->dev->dev;
> + int err;
> +
> + WARN_ON(!mutex_is_locked(&hotplug_helper->event_mutex));
> +
> + /*
> + * drm_connector already present, the new bridge must be for
> + * another card
> + *
> + */
> + if (hotplug_helper->connector)
> + return;
> +
> + struct drm_bridge *last_bridge __free(drm_bridge_put) =
> + drm_bridge_chain_get_last_bridge(hotplug_helper->encoder);
[Severity: Medium]
Can drm_bridge_chain_get_last_bridge() race with concurrent bridge removal in
drm_bridge_detach_from()?
drm_hotplug_helper_try_complete() (and
drm_hotplug_helper_bridge_chain_is_complete()) reads encoder->bridge_chain
under hotplug_helper->event_mutex without holding
encoder->bridge_chain_mutex. Meanwhile, drm_bridge_remove() detaches
bridges before notifying DRM_BRIDGE_DETACHED:
CPU0 CPU1
drm_bridge_remove(last_bridge)
drm_bridge_detach_from()
lock(&encoder->bridge_chain_mutex)
drm_hotplug_helper_try_complete()
drm_bridge_chain_get_last_bridge()
list_last_entry_or_null(...)
list_move_tail(..., &tmplist)
unlock(&encoder->bridge_chain_mutex)
drm_bridge_detach(last_bridge)
list_del_init(&chain_node)
last_bridge->funcs->attach(...)
drm_bridge_attach(..., last_bridge)
list_add(&new->chain_node,
&last_bridge->chain_node)
<-- attaches to detached
bridge / corrupts
tmplist
drm_hotplug_event_notifier_notify()
last_bridge->dev = NULL
last_bridge->encoder = NULL
Because drm_bridge_detach() only clears bridge->dev and bridge->encoder after
the DRM_BRIDGE_DETACHED notification returns, drm_bridge_attach() with
previous = last_bridge passes its validation checks and links the new bridge
onto last_bridge->chain_node while last_bridge is on tmplist or already
detached from encoder->bridge_chain.
> +
> + if (last_bridge) {
> + /*
> + * Some bridge(s) already in the chain, propagate the
> + * attach call chain from the current chain tail to newly
> + * hotplugged bridge(s)
> + */
> + dev_dbg(dev, "propagate attach after %ps\n", last_bridge->funcs);
> +
> + err = last_bridge->funcs->attach(last_bridge, hotplug_helper->encoder,
> + DRM_BRIDGE_ATTACH_NO_CONNECTOR);
> + if (err)
> + return;
[Severity: High]
Is it valid to call last_bridge->funcs->attach() directly on a bridge that is
already attached?
First, drm_bridge_funcs.attach is optional (drm_bridge_attach() checks
if (bridge->funcs->attach)), so dereferencing last_bridge->funcs->attach
unconditionally will cause a NULL pointer dereference if the tail bridge
does not implement .attach.
Second, last_bridge is already attached to encoder->bridge_chain and has not
been detached. Re-invoking its .attach callback on subsequent
DRM_BRIDGE_ADDED or DRM_MIPI_DSI_ATTACHED notifications violates the 1:1
attach/detach lifecycle and re-runs per-bridge attach initialization on an
already-initialized bridge. For example, ti_sn_bridge_attach() in
drivers/gpu/drm/bridge/ti-sn65dsi86.c calls drm_dp_aux_register(&pdata->aux)
before attaching pdata->next_bridge and unwinds with
drm_dp_aux_unregister(&pdata->aux) if attaching next_bridge fails, so
calling .attach() again attempts to re-register an already-registered DP AUX
device and unregisters it on failure while the bridge remains attached.
[ ... ]
> +struct drm_hotplug_helper *drmm_hotplug_helper_init(struct drm_encoder *encoder,
> + drm_hotplug_helper_event_cb event_cb,
> + struct device_node *first_bridge_ep)
> +{
[ ... ]
> + guard(mutex)(&hotplug_helper->event_mutex);
> + drm_hotplug_helper_try_complete(hotplug_helper);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(drmm_hotplug_helper_init);
[Severity: Medium]
Should drmm_hotplug_helper_init() return hotplug_helper instead of 0?
Returning NULL on success contradicts the documented ERR_PTR() contract and
causes callers checking !ret or IS_ERR_OR_NULL() to treat every successful
initialization as a failure.
> diff --git a/include/drm/drm_hotplug_helper.h b/include/drm/drm_hotplug_helper.h
> new file mode 100644
> index 0000000000000..ba14d547f8ff8
> --- /dev/null
> +++ b/include/drm/drm_hotplug_helper.h
> @@ -0,0 +1,30 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (C) 2026 GE HealthCare
> + * Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
> + */
> +
> +#ifndef __DRM_HOTPLUG_HELPER_H__
> +#define __DRM_HOTPLUG_HELPER_H__
> +
> +/**
> + * enum drm_hotplug_helper_event - DRM hotplug helper connector events
> + */
> +enum drm_hotplug_helper_event {
> + /** @DRM_HOTPLUG_HELPER_CONNECTOR_ADDED: A drm_connector has just been added */
> + DRM_HOTPLUG_HELPER_CONNECTOR_ADDED,
> + /** @DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING: A drm_connector is about to be removed */
> + DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING,
> +};
> +
> +/**
> + * drm_hotplug_helper_event_cb - Callback to report connector addition and removal.
> + */
> +typedef void (*drm_hotplug_helper_event_cb)(enum drm_hotplug_helper_event event,
> + struct drm_connector *connector);
> +
> +struct drm_hotplug_helper *drmm_hotplug_helper_init(struct drm_encoder *encoder,
> + drm_hotplug_helper_event_cb event_cb,
> + struct device_node *next_bridge_ep);
> +
> +#endif /* __DRM_HOTPLUG_HELPER_H__ */
[Severity: Low]
Does include/drm/drm_hotplug_helper.h build cleanly under
CONFIG_DRM_HEADER_TEST=y?
struct drm_connector, struct drm_encoder, and struct device_node are used in
the parameter lists without forward declarations, causing -Wvisibility
warnings when the header is compiled standalone. In addition, the kernel-doc
comment for drm_hotplug_helper_event_cb is missing the typedef prefix
("typedef drm_hotplug_helper_event_cb - ...") and @event / @connector
descriptions required by scripts/kernel-doc, and the third parameter of
drmm_hotplug_helper_init() is named next_bridge_ep here instead of
first_bridge_ep as in the definition.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=31
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v4 32/32] drm/mxsfb/lcdif: enable bridge hotplug
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
` (30 preceding siblings ...)
2026-11-25 17:50 ` [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug Luca Ceresoli
@ 2026-11-25 17:50 ` Luca Ceresoli
2026-11-25 18:31 ` sashiko-bot
31 siblings, 1 reply; 50+ messages in thread
From: Luca Ceresoli @ 2026-11-25 17:50 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Inki Dae,
Jagan Teki, Marek Szyprowski, Jessica Zhang, Douglas Anderson,
Marek Vasut, Stefan Agner, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: Javier Martinez Canillas, Dmitry Baryshkov, Hui Pu, Ian Ray,
Luca Ceresoli, Thomas Petazzoni, dri-devel, linux-kernel, imx,
linux-arm-kernel
Switch to the new drm_hotplug_helper() to handle bridge hotplugging:
* use the new drm_hotplug_helper to handle hotplug, including finding
the first bridge and attaching the bridge chain
* use the connector add/remove callback to enable/disable HPD on
added/removed connectors
* move drm_kms_helper_poll_init() before creating the drm_hotplug_helper
so that HPD polling is initialized before connectors can be hotplugged
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v4:
- fix UAF when hot-plugged connectors implement HPD by using the new
per-connector HPD enable/disable API
Changes in v3:
- Adapt to the v3 version of the drm_hotplug_helper, which also handles HPD
Changes in v2:
- Use the hotplug helper callback to enable HPD on the hotplugged connector
---
drivers/gpu/drm/mxsfb/Kconfig | 2 +-
drivers/gpu/drm/mxsfb/lcdif_drv.c | 42 +++++++++++++++++++--------------------
2 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/drivers/gpu/drm/mxsfb/Kconfig b/drivers/gpu/drm/mxsfb/Kconfig
index 31db7a824a93..ada9a9334ea4 100644
--- a/drivers/gpu/drm/mxsfb/Kconfig
+++ b/drivers/gpu/drm/mxsfb/Kconfig
@@ -34,7 +34,7 @@ config DRM_IMX_LCDIF
select DRM_PANEL
select DRM_PANEL_BRIDGE
select DRM_DISPLAY_HELPER
- select DRM_BRIDGE_CONNECTOR
+ select DRM_HOTPLUG_HELPER
help
Choose this option if you have an LCDIFv3 LCD controller.
Those devices are found in various i.MX SoC (i.MX8MP,
diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c
index 2be5a76e936f..591653b39310 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
@@ -18,7 +18,7 @@
#include <drm/clients/drm_client_setup.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_bridge.h>
-#include <drm/drm_bridge_connector.h>
+#include <drm/drm_hotplug_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_encoder.h>
#include <drm/drm_fbdev_dma.h>
@@ -44,6 +44,19 @@ static const struct drm_mode_config_helper_funcs lcdif_mode_config_helpers = {
.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
};
+static void lcdif_hotplug_event(enum drm_hotplug_helper_event event,
+ struct drm_connector *connector)
+{
+ switch (event) {
+ case DRM_HOTPLUG_HELPER_CONNECTOR_ADDED:
+ drm_kms_helper_poll_enable_connector(connector);
+ break;
+ case DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING:
+ drm_kms_helper_poll_disable_connector(connector);
+ break;
+ }
+}
+
static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
{
struct device *dev = lcdif->drm->dev;
@@ -53,9 +66,8 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
struct device_node *remote __free(device_node) =
of_graph_get_remote_port_parent(ep);
struct of_endpoint of_ep;
- struct drm_bridge *bridge;
struct drm_encoder *encoder;
- struct drm_connector *connector;
+ struct drm_hotplug_helper *hotplug_helper;
int ret;
if (!of_device_is_available(remote))
@@ -65,12 +77,6 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
if (ret < 0)
return dev_err_probe(dev, ret, "Failed to parse endpoint %pOF\n", ep);
- bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0, of_ep.id);
- if (IS_ERR(bridge))
- return dev_err_probe(dev, PTR_ERR(bridge),
- "Failed to get bridge for endpoint%u\n",
- of_ep.id);
-
encoder = drmm_plain_encoder_alloc(lcdif->drm, NULL,
DRM_MODE_ENCODER_NONE, NULL);
if (IS_ERR(encoder))
@@ -80,16 +86,10 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc);
- ret = drm_bridge_attach(encoder, bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
- if (ret)
- return dev_err_probe(dev, ret,
- "Failed to attach bridge for endpoint%u\n",
- of_ep.id);
-
- connector = drm_bridge_connector_init(lcdif->drm, encoder);
- if (IS_ERR(connector))
- return dev_err_probe(dev, PTR_ERR(connector),
- "Failed to init bridge_connector for endpoint%u\n",
+ hotplug_helper = drmm_hotplug_helper_init(encoder, lcdif_hotplug_event, ep);
+ if (IS_ERR(hotplug_helper))
+ return dev_err_probe(dev, PTR_ERR(hotplug_helper),
+ "Failed to init hotplug_helper for endpoint%u\n",
of_ep.id);
}
@@ -176,6 +176,8 @@ static int lcdif_load(struct drm_device *drm)
/* Start with vertical blanking interrupt reporting disabled. */
drm_crtc_vblank_off(&lcdif->crtc);
+ drm_kms_helper_poll_init(drm);
+
ret = lcdif_attach_bridge(lcdif);
if (ret)
return ret;
@@ -203,8 +205,6 @@ static int lcdif_load(struct drm_device *drm)
return ret;
}
- drm_kms_helper_poll_init(drm);
-
drm_helper_hpd_irq_event(drm);
pm_runtime_enable(drm->dev);
--
2.56.1
^ permalink raw reply related [flat|nested] 50+ messages in thread* Re: [PATCH v4 32/32] drm/mxsfb/lcdif: enable bridge hotplug
2026-11-25 17:50 ` [PATCH v4 32/32] drm/mxsfb/lcdif: enable " Luca Ceresoli
@ 2026-11-25 18:31 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-11-25 18:31 UTC (permalink / raw)
To: Luca Ceresoli; +Cc: dri-devel, imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/mxsfb/lcdif: missing connector when last bridge lacks
get_next_bridge()
- [High] drm/mxsfb/lcdif: missing client hotplug notification in
lcdif_hotplug_event()
- [High] drm: double bridge attach in drm_hotplug_helper_try_complete()
- [Medium] drm/mxsfb/lcdif: poll_init and drmm_hotplug_helper_init
lifetime mismatch
--
commit d0177b7f727becda395d8ff3eb1f0fa798651116
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/mxsfb/lcdif: enable bridge hotplug
This commit switches the i.MX LCDIF driver to drmm_hotplug_helper_init() to
manage bridge attachment and dynamic connector creation, and moves
drm_kms_helper_poll_init() earlier in lcdif_load() so per-connector HPD
polling can be toggled from the hotplug callback.
> diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c
> index 2be5a76e936f6..591653b39310c 100644
> --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
> +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
[ ... ]
> @@ -44,6 +44,19 @@ static const struct drm_mode_config_helper_funcs lcdif_mode_config_helpers = {
> .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
> };
>
> +static void lcdif_hotplug_event(enum drm_hotplug_helper_event event,
> + struct drm_connector *connector)
> +{
> + switch (event) {
> + case DRM_HOTPLUG_HELPER_CONNECTOR_ADDED:
> + drm_kms_helper_poll_enable_connector(connector);
> + break;
> + case DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING:
> + drm_kms_helper_poll_disable_connector(connector);
> + break;
> + }
> +}
[Severity: High]
Does lcdif_hotplug_event() miss notifying in-kernel DRM clients and running
initial HPD detection when a connector is added after lcdif_load()?
With drmm_hotplug_helper_init(), lcdif_attach_bridge() no longer defers
probe while waiting for downstream bridges, so drm_helper_hpd_irq_event()
and drm_client_setup() can run before any connector exists. When the
bridge chain completes later, drm_bridge_connector_dynamic_add() registers
the connector (emitting a sysfs uevent without calling
drm_client_dev_hotplug()), and drm_kms_helper_poll_enable_connector() does
not schedule output_poll_work for fixed panels (polled == 0) or HPD-IRQ
connectors (polled == DRM_CONNECTOR_POLL_HPD). As a result, fbdev/fbcon
is never set up and HPD-IRQ connectors stay in connector_status_unknown.
[ ... ]
> @@ -80,16 +86,10 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
>
> encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc);
>
> - ret = drm_bridge_attach(encoder, bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
> - if (ret)
> - return dev_err_probe(dev, ret,
> - "Failed to attach bridge for endpoint%u\n",
> - of_ep.id);
> -
> - connector = drm_bridge_connector_init(lcdif->drm, encoder);
> - if (IS_ERR(connector))
> - return dev_err_probe(dev, PTR_ERR(connector),
> - "Failed to init bridge_connector for endpoint%u\n",
> + hotplug_helper = drmm_hotplug_helper_init(encoder, lcdif_hotplug_event, ep);
> + if (IS_ERR(hotplug_helper))
> + return dev_err_probe(dev, PTR_ERR(hotplug_helper),
> + "Failed to init hotplug_helper for endpoint%u\n",
> of_ep.id);
> }
[Severity: High]
Will drmm_hotplug_helper_init() fail to create a connector on LCDIF
pipelines whose last bridge does not implement DRM_BRIDGE_OP_GET_NEXT_BRIDGE?
Previously, lcdif_attach_bridge() unconditionally created the connector
with drm_bridge_connector_init() after drm_bridge_attach(). Now connector
creation in drm_hotplug_helper_try_complete() is gated on
drm_hotplug_helper_bridge_chain_is_complete(), which calls
drm_bridge_get_next() on the last bridge and only returns true when that
returns NULL. On i.MX8MP boards using tc358767 as a DisplayPort terminal
bridge (such as imx8mp-dhcom-pdk3-overlay-732-100-x36.dtso), tc358767 does
not set DRM_BRIDGE_OP_GET_NEXT_BRIDGE, so drm_bridge_get_next() warns and
returns ERR_PTR(-ENOENT) and the connector is never created.
[Severity: High]
Can switching to drmm_hotplug_helper_init() cause last_bridge->funcs->attach()
to be called a second time on an already-attached bridge?
When a downstream bridge in a multi-bridge chain is removed (or when the
terminal bridge lacks DRM_BRIDGE_OP_GET_NEXT_BRIDGE so
hotplug_helper->connector stays NULL), the upstream bridge remains attached
as last_bridge in encoder->bridge_chain. On the next DRM_BRIDGE_ADDED or
DRM_MIPI_DSI_ATTACHED notification, drm_hotplug_helper_try_complete() hits
the if (last_bridge) branch:
drivers/gpu/drm/display/drm_hotplug_helper.c:drm_hotplug_helper_try_complete() {
...
if (last_bridge) {
dev_dbg(dev, "propagate attach after %ps\n", last_bridge->funcs);
err = last_bridge->funcs->attach(last_bridge, hotplug_helper->encoder,
DRM_BRIDGE_ATTACH_NO_CONNECTOR);
...
}
Besides dereferencing last_bridge->funcs->attach without a NULL check,
re-invoking funcs->attach() on an already-attached bridge (such as
ti-sn65dsi86 or tc358767, which call drm_dp_aux_register() in their attach
callbacks before attaching the next bridge) re-registers an initialized
drm_dp_aux i2c adapter kobject and unregisters the active DP AUX channel if
downstream attachment fails.
> @@ -176,6 +176,8 @@ static int lcdif_load(struct drm_device *drm)
> /* Start with vertical blanking interrupt reporting disabled. */
> drm_crtc_vblank_off(&lcdif->crtc);
>
> + drm_kms_helper_poll_init(drm);
> +
> ret = lcdif_attach_bridge(lcdif);
> if (ret)
> return ret;
[Severity: Medium]
Does pairing unmanaged drm_kms_helper_poll_init() with
drmm_hotplug_helper_init() leave polling uncleaned on probe failure and
out of order with hotplug teardown on unbind?
If lcdif_attach_bridge(), drm_mode_config_create_initial_state() or IRQ
setup fails in lcdif_load(), lcdif_probe() jumps to err_free without
calling lcdif_unload() or drm_kms_helper_poll_fini(). On driver unbind,
lcdif_unload() runs drm_kms_helper_poll_fini() (setting poll_enabled = false)
before final drm_dev_put() releases drmm_hotplug_helper_init(); if
userspace holds an open DRM fd across unbind, a bridge hotplug event before
the fd closes will call lcdif_hotplug_event() ->
drm_kms_helper_poll_enable_connector() and hit
drm_WARN_ON_ONCE(dev, !dev->mode_config.poll_enabled). Using
drmm_kms_helper_poll_init() before lcdif_attach_bridge() and dropping
drm_kms_helper_poll_fini() from lcdif_unload() would align both lifetimes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=32
^ permalink raw reply [flat|nested] 50+ messages in thread