Skip to content

Commit f078634

Browse files
Liu Yinglucaceresoli
authored andcommitted
drm/bridge: Fix refcount shown via debugfs for encoder_bridges_show()
A typical bridge refcount value is 3 after a bridge chain is formed: - devm_drm_bridge_alloc() initializes the refcount value to be 1. - drm_bridge_add() gets an additional reference hence 2. - drm_bridge_attach() gets the third reference hence 3. This typical refcount value aligns with allbridges_show()'s behaviour. However, since encoder_bridges_show() uses drm_for_each_bridge_in_chain_scoped() to automatically get/put the bridge reference while iterating, a bogus reference is accidentally got when showing the wrong typical refcount value as 4 to users via debugfs. Fix this by caching the refcount value returned from kref_read() while iterating and explicitly decreasing the cached refcount value by 1 before showing it to users. Fixes: bd57048 ("drm/bridge: use drm_for_each_bridge_in_chain_scoped()") Signed-off-by: Liu Ying <victor.liu@nxp.com> Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Tested-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Link: https://patch.msgid.link/20260318-drm-misc-next-2026-03-05-fix-encoder-bridges-refcount-v3-1-147fea581279@nxp.com Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
1 parent 87a7001 commit f078634

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

drivers/gpu/drm/drm_bridge.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,11 +1569,17 @@ EXPORT_SYMBOL(devm_drm_put_bridge);
15691569
static void drm_bridge_debugfs_show_bridge(struct drm_printer *p,
15701570
struct drm_bridge *bridge,
15711571
unsigned int idx,
1572-
bool lingering)
1572+
bool lingering,
1573+
bool scoped)
15731574
{
1575+
unsigned int refcount = kref_read(&bridge->refcount);
1576+
1577+
if (scoped)
1578+
refcount--;
1579+
15741580
drm_printf(p, "bridge[%u]: %ps\n", idx, bridge->funcs);
15751581

1576-
drm_printf(p, "\trefcount: %u%s\n", kref_read(&bridge->refcount),
1582+
drm_printf(p, "\trefcount: %u%s\n", refcount,
15771583
lingering ? " [lingering]" : "");
15781584

15791585
drm_printf(p, "\ttype: [%d] %s\n",
@@ -1607,10 +1613,10 @@ static int allbridges_show(struct seq_file *m, void *data)
16071613
mutex_lock(&bridge_lock);
16081614

16091615
list_for_each_entry(bridge, &bridge_list, list)
1610-
drm_bridge_debugfs_show_bridge(&p, bridge, idx++, false);
1616+
drm_bridge_debugfs_show_bridge(&p, bridge, idx++, false, false);
16111617

16121618
list_for_each_entry(bridge, &bridge_lingering_list, list)
1613-
drm_bridge_debugfs_show_bridge(&p, bridge, idx++, true);
1619+
drm_bridge_debugfs_show_bridge(&p, bridge, idx++, true, false);
16141620

16151621
mutex_unlock(&bridge_lock);
16161622

@@ -1625,7 +1631,7 @@ static int encoder_bridges_show(struct seq_file *m, void *data)
16251631
unsigned int idx = 0;
16261632

16271633
drm_for_each_bridge_in_chain_scoped(encoder, bridge)
1628-
drm_bridge_debugfs_show_bridge(&p, bridge, idx++, false);
1634+
drm_bridge_debugfs_show_bridge(&p, bridge, idx++, false, true);
16291635

16301636
return 0;
16311637
}

0 commit comments

Comments
 (0)