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

Luca Ceresoli posted 6 patches 1 month, 2 weeks ago
[PATCH v3 4/6] drm/bridge: add warning for bridges attached without being added
Posted by Luca Ceresoli 1 month, 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.

Suggested-by: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/all/20250709-sophisticated-loon-of-rain-6ccdd8@houat/
Reviewed-by: Raphael Gallais-Pou <rgallaispou@gmail.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>

---

Changes in v3:
- added 'Suggested-by: Maxime Ripard' which was missing in v1 and v2 by
  mistake
---
 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 v3 4/6] drm/bridge: add warning for bridges attached without being added
Posted by Maxime Ripard 1 month, 2 weeks ago
On Tue, 28 Oct 2025 11:15:45 +0100, Luca Ceresoli wrote:
> 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.
> 
> [ ... ]

Reviewed-by: Maxime Ripard <mripard@kernel.org>

Thanks!
Maxime