Re: [PATCH v1 1/1] clk: devres: Simplify devres handling functions

From: Andy Shevchenko
Date: Wed Aug 28 2024 - 09:08:32 EST


On Tue, Aug 27, 2024 at 05:19:04PM -0700, Stephen Boyd wrote:
> Quoting Andy Shevchenko (2024-08-22 08:58:22)

...

> > - state = devres_alloc(devm_clk_release, sizeof(*state), GFP_KERNEL);
> > + state = devm_kmalloc(dev, sizeof(*state), GFP_KERNEL);
>
> When is this allocation freed if the get() fails? When the calling
> device driver detaches?

At device unbinding. Is it a problem?

...

> > + ret = devm_add_action_or_reset(dev, devm_clk_release, state);
> > + if (ret)
> > + goto err_clk_init;
>
> Shouldn't we return an error here? Otherwise we call clk_put() twice?

Or use devm_add_action().
Thanks for catching this!

> > return clk;
> >
> > err_clk_init:
> > clk_put(clk);
> > return ERR_PTR(ret);
> > }

...

> I stopped reading, sorry! If you want to do this, please add a bunch of
> KUnit tests.

Sure. It's a good idea.

--
With Best Regards,
Andy Shevchenko