mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Henry Zhang <henryzhang62@gmail.com>
To: mripard@kernel.org, dave.stevenson@raspberrypi.com, mcanal@igalia.com
Cc: kernel-list@raspberrypi.com, maarten.lankhorst@linux.intel.com,
	tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	henryzhang62@gmail.com
Subject: [PATCH] drm/vc4: dsi: Register the PHY clock provider with devm
Date: Tue, 17 Nov 2026 15:41:07 -0800	[thread overview]
Message-ID: <20261117234107.1298575-1-henryzhang62@gmail.com> (raw)

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")
Signed-off-by: Henry Zhang <henryzhang62@gmail.com>
---
Found by the Sashiko review of
<20261117205902.1293962-1-henryzhang62@gmail.com>; 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(-)

diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
index ec008f766..ed99cec9f 100644
--- a/drivers/gpu/drm/vc4/vc4_dsi.c
+++ b/drivers/gpu/drm/vc4/vc4_dsi.c
@@ -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
-- 
2.47.3


                 reply	other threads:[~2026-11-17 23:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117234107.1298575-1-henryzhang62@gmail.com \
    --to=henryzhang62@gmail.com \
    --cc=airlied@gmail.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel-list@raspberrypi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mcanal@igalia.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®