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 - 11:36:49 EST
On 2026-12-03 15:19 +0000, Joshua Covington wrote:
> 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.
I'm not too the sure the WARN() condition is needed though.
It is very late for such a consistency check and what it is checking should
be guaranteed by the registration code, no ? Can't we just skip the check ?
--
Jerome