Re: [PATCH v4 phy-next 1/9] soc: fsl: guts: perform fsl_guts_init() error teardown in reverse order of setup
From: Ioana Ciornei
Date: Wed Jul 22 2026 - 05:24:17 EST
On Wed, Jul 22, 2026 at 02:15:55AM +0300, Vladimir Oltean wrote:
> fsl_guts_init() is about to get much more complicated and the central
> error handling procedure cannot scale in its current design, unless we
> add a lot of "if" conditions to detect what has been allocated and what
> hasn't.
>
> Currently the code relies on the fact that kfree(NULL) is safe, but this
> doesn't scale to the case where "soc_dev_attr" itself is NULL, because
> this would dereference "soc_dev_attr->family" and friends of a NULL
> pointer.
>
> Convert to the more typical error handling pattern where the teardown is
> in the strict reverse order of setup, and a teardown step is only called
> if its corresponding setup step was executed.
>
> At the same time, maintain the optionality of soc_dev_attr->serial_number
> by not checking whether that kasprintf() has returned NULL. In the error
> path, kfree(NULL) is safe, so we don't need to add an "if" condition for
> it. Michael Walle has confirmed that ignoring the error was intentional,
> and we preserve that:
> https://lore.kernel.org/linux-phy/DK44809N7Y8I.J2Z3U4N32H0Q@xxxxxxxxxx/
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@xxxxxxx>
Reviewed-by: Ioana Ciornei <ioana.ciornei@xxxxxxx>