mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joshua Covington <joshuacov@gmail.com>
To: Stephen Boyd <sboyd@kernel.org>, Brian Masney <masneyb@kernel.org>
Cc: Brian Masney <bmasney+clk@redhat.com>,
	Jerome Brunet <jbrunet+clk@baylibre.com>,
	Andrea della Porta <andrea.porta@suse.com>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Joshua Covington <joshuacov@gmail.com>
Subject: [PATCH v3 0/3] clk: allow a clk_hw to be registered again after unregistering it
Date: Tue, 24 Nov 2026 23:17:48 +0000	[thread overview]
Message-ID: <20261124231751.83938-1-joshuacov@gmail.com> (raw)

Drivers with statically allocated clk_hw structures cannot register
their clocks again once they have been unregistered, e.g. when the
device is unbound and bound again. __clk_register() sets hw->init to
NULL, so the second registration has no init data and oopses, and
clk_unregister() leaves hw->core and hw->clk pointing to the clk_core
and clk it releases. On the Raspberry Pi 5 / CM5 this is hit by
unbinding and binding the RP1 southbridge, whose clk-rp1 driver uses
static descriptors.

v2 worked around this in clk-rp1 alone. Following Brian's review, v3
fixes it in the clk core instead, so that the other drivers with
static clk_hw structures benefit as well:

1/3 keeps the init pointer in the clk_core and puts it back into the
    clk_hw when the registration fails and when the clock is
    unregistered, and clears hw->core and hw->clk on unregistration.
    Init data on the stack of the registering function is not handed
    back. This is decided at registration, as object_is_on_stack()
    only looks at the stack of the current task.
2/3 adds KUnit tests for this.
3/3 resets the cached rates of the clk-rp1 descriptors on probe, which
    is the part of the v2 fix that is still needed in the driver.

Testing:
- CM5 hardware (arm64), 6.18.64 backport: the new KUnit tests pass, and
  repeated RP1 unbind/bind with all RP1 drivers loaded runs without an
  oops.
- x86_64 QEMU with KASAN: the clk KUnit suites pass (138 tests,
  134 passed, 4 skipped as before), no KASAN reports. Without 1/3 all
  four new tests fail and KASAN reports a slab-use-after-free in
  __clk_register(). With init data on the stack handed back on
  unregistration, the stack test fails.
- arm64 defconfig with CLK_KUNIT_TEST, MISC_RP1 and COMMON_CLK_RP1,
  W=1, GCC and clang: no new warnings. checkpatch --strict and
  kernel-doc are clean.

Claude Opus 5.5 (Anthropic) was used to help write the tests, the
changelogs and the clk-rp1 change, and to run the testing above apart
from the CM5 runs. I have reviewed all of it and tested it on CM5
hardware.

Changes in v3:
- Fix this in the clk core (Brian Masney), with Brian as
  Co-developed-by
- Do not hand back init data that was on the stack
- Add KUnit tests
- Reduce the clk-rp1 change to resetting the cached rates
- Add Fixes: and Cc: stable tags

v2: https://lore.kernel.org/all/20261121181650.143474-1-joshuacov@gmail.com/
v1: https://lore.kernel.org/all/20261121163915.86681-1-joshuacov@gmail.com/

Joshua Covington (3):
  clk: allow a clk_hw to be registered again after unregistering it
  clk: tests: add tests for registering a clk_hw again
  clk: rp1: reset cached rates on probe

 drivers/clk/clk-rp1.c        |   6 ++
 drivers/clk/clk.c            |  23 +++++
 drivers/clk/clk_test.c       | 191 +++++++++++++++++++++++++++++++++++
 include/linux/clk-provider.h |   5 +-
 4 files changed, 224 insertions(+), 1 deletion(-)


base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
-- 
2.56.0


             reply	other threads:[~2026-11-24 23:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 23:17 Joshua Covington [this message]
2026-11-24 23:17 ` [PATCH v3 1/3] " Joshua Covington
2026-11-24 23:17 ` [PATCH v3 2/3] clk: tests: add tests for registering a clk_hw again Joshua Covington
2026-11-24 23:17 ` [PATCH v3 3/3] clk: rp1: reset cached rates on probe Joshua Covington

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=20261124231751.83938-1-joshuacov@gmail.com \
    --to=joshuacov@gmail.com \
    --cc=andrea.porta@suse.com \
    --cc=bmasney+clk@redhat.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=jbrunet+clk@baylibre.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=masneyb@kernel.org \
    --cc=s.nawrocki@samsung.com \
    --cc=sboyd@kernel.org \
    /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®