Skip to contentSkip to conversation

drm/vc4: dsi: Register the PHY clock provider with devm

PATCH In review Henry Zhang 2 participants 2 messages Nov 17 – Nov 18

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vc4: dsi: Register the PHY clock provider with devm

vc4_dsi_init_phy_clocks() is called from the component bind. It allocates the clock data with devm_kzalloc() and registers the clocks with devm_clk_hw_register(), so both are released with the devres group that the component framework opens for the bind, when the bind fails later or the component is unbound. The OF clock provider that points at that data is added with of_clk_add_hw_provider() and never removed:
after an unbind it stays registered with the freed data, and each new bind adds another provider for the same node. A later lookup of one of these clocks, such as <&dsi1 0>, would call of_clk_hw_onecell_get() on freed memory.

Use devm_of_clk_add_hw_provider(), so that the provider is removed with the same devres group, before the clocks and their data.

The analysis, this change and this description were prepared with the help of an AI coding assistant (Claude Code).

Fixes 4078f5757144 ("drm/vc4: Add DSI driver")

---
Found by the Sashiko review of <[email protected]>; independent of that patch.

Testing:

- On this base (drm-misc-next 467ac0b56aeb): arm64, DRM_VC4=m, W=1, no new warnings.

- On a Raspberry Pi 4 with a downstream 6.18.34 kernel and an out-of-tree modular DSI panel driver, with kprobes on the provider functions, reloading the panel driver (which unbinds and binds vc4):
- without the change, each bind adds a provider for the DSI node and

    nothing removes it;

- with the change, each unbind removes it (from devres_release_group() in component_unbind()), each bind adds one, and the DSI PHY clocks are back after each bind;
- a bind that fails after the provider is added (with the old DRM device held open, on a kernel that also has a backport of "drm/vc4:
dsi: Allocate the encoder per DRM device", where the bind fails in drm_bridge_attach()) removes it again (devres_release_group() in component_bind_all()), and binding again after the old DRM device is closed works.
No warnings. In these tests no clock lookup went to the DSI node, so a lookup on a stale provider was not reproduced.

 drivers/gpu/drm/vc4/vc4_dsi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/vc4/vc4_dsi.c +2 -3
index ec008f766..ed99cec9f 100644
@@ -1592,9 +1592,8 @@ vc4_dsi_init_phy_clocks(struct vc4_dsi *dsi)
 		dsi->clk_onecell->hws[i] = &fix->hw;
 	}
 
-	return of_clk_add_hw_provider(dev->of_node,
-				      of_clk_hw_onecell_get,
-				      dsi->clk_onecell);
+	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+					   dsi->clk_onecell);
 }
 
 static void vc4_dsi_dma_mem_release(void *ptr)

base-commit: 467ac0b56aebc804360f276feffbc9032c265a6e

Signature · 1 line
2.47.3
reviewer
#1 lore raw
Quoted 11 lines · Henry Zhang

vc4_dsi_init_phy_clocks() is called from the component bind. It allocates the clock data with devm_kzalloc() and registers the clocks with devm_clk_hw_register(), so both are released with the devres group that the component framework opens for the bind, when the bind fails later or the component is unbound. The OF clock provider that points at that data is added with of_clk_add_hw_provider() and never removed:
after an unbind it stays registered with the freed data, and each new bind adds another provider for the same node. A later lookup of one of these clocks, such as <&dsi1 0>, would call of_clk_hw_onecell_get() on freed memory.

Quoted 1 line

[...]

Applied with the AI-assistance note in the commit message removed, thanks!

[1/1] drm/vc4: dsi: Register the PHY clock provider with devm

      commit: db9a489077cbe9217b7bc2b47ebf0fabc5f1a56f

Best regards,
- Maíra