Re: [PATCH v4 1/3] regcache: Move HW readback after cache initialisation

From: Andy Shevchenko

Date: Mon Mar 02 2026 - 10:19:44 EST


On Mon, Mar 02, 2026 at 02:49:49PM +0000, Mark Brown wrote:
> On Mon, Mar 02, 2026 at 10:56:55AM +0100, Andy Shevchenko wrote:

...

> > + /*
> > + * Some devices such as PMICs don't have cache defaults,
> > + * we cope with this by reading back the HW registers and
> > + * crafting the cache defaults by hand.
> > + */
> > + ret = regcache_hw_init(map, count);
> > + if (ret)
> > + goto err_exit;
> > +
>
> We need to delete the free of reg_defaults from regcache_hw_init() when
> it fails, the error handling for err_exit also frees that so we'd end up
> with a double free. Which is awfully error prone and part of what
> you're trying to fix here :/

Ah, looking again at it I see your point.

Indeed, in the error path of regcache_hw_init() we free the reg_defaults,
but the same is also done at err_free label of regcache_init().

NULLifying it at regcache_hw_init() doesn't sound like a good idea as
you pointed out as error prone case. I will think more about it, thanks
for catching this (I dunno why I missed that one)!

--
With Best Regards,
Andy Shevchenko