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

From: Joshua Covington

Date: Thu Dec 03 2026 - 10:22:09 EST


Hi Jerome,

Thanks for the review.

On Thu, Dec 03, 2026 at 11:26:39AM +0100, Jerome Brunet wrote:
> 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.

That works for me, and it will remove the new clk_core member and the
object_is_on_stack() check. So far I have tried it on top of v3, with
__clk_register() no longer clearing hw->init. The tests for registering
again after unregistration and after a failed registration pass. In v4
I will also add to the clk_hw kernel-doc that providers must not use
@init after registration, as it may point to init data that is gone.

The other half of the patch still needs to stay, though. clk_unregister()
leaves hw->core and hw->clk pointing to the clk_core and clk it
releases. Without clearing them, a clk_parent_data.hw reference to an
unregistered clk_hw resolves to the freed clk_core, and KASAN reports a
slab-use-after-free in __clk_register() in the parent test. That part
costs no memory, so I would keep it.

Stephen, the hw->init poisoning was added by 0214f33c4e0e. Are you fine
with dropping it? If so, I will send a v4 that does the above, with the
test for init data on the stack removed.

> 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.

Agreed. That is beyond the scope of this fix, and the decision on it is
for you and Stephen.

Thanks,
Joshua