Re: [PATCH v3 1/3] clk: allow a clk_hw to be registered again after unregistering it

From: Jerome Brunet

Date: Thu Dec 03 2026 - 05:26:52 EST


> __clk_register() sets hw->init to NULL, and clk_unregister() leaves
> hw->core and hw->clk pointing to the clk_core and clk it is about to
> release. A driver with statically allocated clk_hw structures can
> therefore not register them again, e.g. when its device is unbound and
> bound again. The second registration has no init data and oopses. A
> clk_parent_data.hw reference to such a clk_hw also resolves to the
> freed clk_core of the previous registration.
>
> Keep the init pointer in the clk_core, and put it back into the clk_hw
> when the registration fails and when the clock is unregistered. Init
> data on the stack of the registering function is gone by the time the
> clock is unregistered, so leave hw->init NULL in that case. This has to
> be checked at registration, as object_is_on_stack() only looks at the
> stack of the current task. Also clear hw->core and hw->clk on
> unregistration, so that a reference to an unregistered clk_hw is
> treated as an orphan.
>
> Fixes: 0214f33c4e0e ("clk: Overwrite clk_hw::init with NULL during clk_register()")
> Link: https://lore.kernel.org/all/179545567027.246915.947299820828330388.b4-review@b4/
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Brian Masney <masneyb@xxxxxxxxxx>
> Signed-off-by: Brian Masney <masneyb@xxxxxxxxxx>
> Signed-off-by: Joshua Covington <joshuacov@xxxxxxxxx>

I understand what you are fixing here but it feels like we are not addressing the
actual problem here, more hiding it under more complexity. It also eats more memory
for every single clock on every platforms, for something we could still be storing
elsewhere.

The problem is clk_hw stores data it really should not. Because it should
not, CCF poison it to make sure nobody does uses it afterward.

IMO, the short term solution to the problem explained in this series is to
stop poisoning the init data in clk_hw. The framework did not allocate the
data, arguably it should not be wrecking it on purpose or otherwise touch it.
Just leave it be.

We should however put clear comment/warning that provider driver should NOT
be using that or count on it being valid.

We could maybe teach sashiko to pick up on this in reviews

The longer term solution would be stop it storing altogther. I think that
would mean adding a new registration API that takes the init data as parameter
and provide the clk_hw in return ... them slowly convert everything, then drop it.

--
Jerome