Re: [PATCH v2] clk: rp1: allow the clock provider to be probed again

From: Joshua Covington

Date: Mon Nov 23 2026 - 18:38:44 EST


Hi Brian,

On Mon, Nov 23, 2026 at 12:41:10PM -0500, Brian Masney wrote:
> There's presumably other drivers that will have the same issue as well.
> Rather than having drivers all try to fix this themselves, let's see if
> we can fix this in the core for everyone. Can you try this completely
> untested patch? If that works, then you can take it over. It will need a
> kunit test.

Thanks a lot, it works. I tested it on my Raspberry Pi CM5 (currently
6.18.64 with the Raspberry Pi downstream patches) with your patch
instead of the clk-rp1 change. Unbinding and binding the RP1 PCI device
again, which oopsed in __clk_register() before, now brings all RP1
peripherals back without any warning.

I also wrote three KUnit tests for the following:

- registering, unregistering and registering the same clk_hw again;
- hw->init being restored when registration fails (-EEXIST on a
duplicate name);
- a parent referenced through clk_parent_data.hw being an orphan after
it has been unregistered, and reparented once it is registered again.

They pass on the CM5 and on QEMU x86_64 with KASAN. Without your patch,
the first two oops on the NULL init data, and the third reports a
slab-use-after-free in __clk_register().

I noticed two things while reading it:

- clk_unregister() now writes to the clk_hw. So far it only touched it
through ops->terminate, so a driver that frees its clk_hw before
unregistering it may now write to freed memory.

- hw->init is also restored when the clk_init_data was on the stack of
the registering function, so after unregistering it can point to a
dead stack frame. That only matters for a driver that registers the
clk_hw again without setting hw->init first, as the updated comment
in clk-provider.h says.

On the CM5, clk-rp1 also keeps a cached rate per clock that survives a
rebind, so I added a small clk-rp1 patch that resets it on probe.

I'll rebase on clk-next and send a series with your change, the tests
and the clk-rp1 patch. How would you like to be credited for the core
change? If you add your Signed-off-by, I'll keep you as the author;
otherwise I'll use Suggested-by.

Thanks,
Joshua