[PATCH 4/4] drm/bridge: add warning for bridges attached without being added

Luca Ceresoli posted 4 patches 2 months, 2 weeks ago
There is a newer version of this series
[PATCH 4/4] drm/bridge: add warning for bridges attached without being added
Posted by Luca Ceresoli 2 months, 2 weeks ago
DRM bridges must be added before they are attached. Add a warning to catch
violations.

The warning is based on the bridge not being part of any list, so it will
trigger if the bridge is being attached without ever having been added.

It won't catch cases of bridges attached after having been added and then
removed, because in that case the bridge will be in
bridge_lingering_list. However such a case is both more demanding to detect
and less likely to happen, so it can be left unchecked, at least for now.

Link: https://lore.kernel.org/all/20250709-sophisticated-loon-of-rain-6ccdd8@houat/
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
 drivers/gpu/drm/drm_bridge.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 1246a52f8767b52c5f10139aa897824b3c2f28da..6dba601a056bb3cff8b8dd5b1ec46299235b2d85 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -441,6 +441,9 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
 	if (!encoder || !bridge)
 		return -EINVAL;
 
+	if (list_empty(&bridge->list))
+		DRM_WARN("Missing drm_bridge_add() before attach\n");
+
 	drm_bridge_get(bridge);
 
 	if (previous && (!previous->dev || previous->encoder != encoder)) {

-- 
2.51.0
Re: [PATCH 4/4] drm/bridge: add warning for bridges attached without being added
Posted by Raphaël Gallais-Pou 2 months ago

Le 03/10/2025 à 10:59, Luca Ceresoli a écrit :
> DRM bridges must be added before they are attached. Add a warning to catch
> violations.
> 
> The warning is based on the bridge not being part of any list, so it will
> trigger if the bridge is being attached without ever having been added.
> 
> It won't catch cases of bridges attached after having been added and then
> removed, because in that case the bridge will be in
> bridge_lingering_list. However such a case is both more demanding to detect
> and less likely to happen, so it can be left unchecked, at least for now.
> 
> Link: https://lore.kernel.org/all/20250709-sophisticated-loon-of-rain-6ccdd8@houat/
> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
> ---

Reviewed-by: Raphael Gallais-Pou <rgallaispou@gmail.com>

Best regards,
Raphaël>