]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/debugfs: show lingering bridges
authorLuca Ceresoli <luca.ceresoli@bootlin.com>
Mon, 15 Sep 2025 10:12:47 +0000 (12:12 +0200)
committerLuca Ceresoli <luca.ceresoli@bootlin.com>
Tue, 23 Sep 2025 20:20:05 +0000 (22:20 +0200)
The usefulness of /sys/kernel/debug/dri/bridges is limited as it only shows
bridges between drm_bridge_add() and drm_bridge_remove(). However
refcounted bridges can stay allocated and lingering for a long time after
drm_bridge_remove(), and a memory leak due to a missing drm_bridge_put()
would not be visible in this debugfs file.

Add lingering bridges to the /sys/kernel/debug/dri/bridges output.

Reviewed-by: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/r/20250915-drm-bridge-debugfs-removed-v9-2-6e5c0aff5de9@bootlin.com
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
drivers/gpu/drm/drm_bridge.c

index 034dbe7203bfc21ebf157ae1d9d4167086220a5c..4d959a34ee46fb3af08c927acc264a0a1be3f077 100644 (file)
@@ -1447,17 +1447,20 @@ EXPORT_SYMBOL(devm_drm_put_bridge);
 
 static void drm_bridge_debugfs_show_bridge(struct drm_printer *p,
                                           struct drm_bridge *bridge,
-                                          unsigned int idx)
+                                          unsigned int idx,
+                                          bool lingering)
 {
        drm_printf(p, "bridge[%u]: %ps\n", idx, bridge->funcs);
 
-       drm_printf(p, "\trefcount: %u\n", kref_read(&bridge->refcount));
+       drm_printf(p, "\trefcount: %u%s\n", kref_read(&bridge->refcount),
+                  lingering ? " [lingering]" : "");
 
        drm_printf(p, "\ttype: [%d] %s\n",
                   bridge->type,
                   drm_get_connector_type_name(bridge->type));
 
-       if (bridge->of_node)
+       /* The OF node could be freed after drm_bridge_remove() */
+       if (bridge->of_node && !lingering)
                drm_printf(p, "\tOF: %pOFfc\n", bridge->of_node);
 
        drm_printf(p, "\tops: [0x%x]", bridge->ops);
@@ -1483,7 +1486,10 @@ static int allbridges_show(struct seq_file *m, void *data)
        mutex_lock(&bridge_lock);
 
        list_for_each_entry(bridge, &bridge_list, list)
-               drm_bridge_debugfs_show_bridge(&p, bridge, idx++);
+               drm_bridge_debugfs_show_bridge(&p, bridge, idx++, false);
+
+       list_for_each_entry(bridge, &bridge_lingering_list, list)
+               drm_bridge_debugfs_show_bridge(&p, bridge, idx++, true);
 
        mutex_unlock(&bridge_lock);
 
@@ -1498,7 +1504,7 @@ static int encoder_bridges_show(struct seq_file *m, void *data)
        unsigned int idx = 0;
 
        drm_for_each_bridge_in_chain_scoped(encoder, bridge)
-               drm_bridge_debugfs_show_bridge(&p, bridge, idx++);
+               drm_bridge_debugfs_show_bridge(&p, bridge, idx++, false);
 
        return 0;
 }