Re: [PATCH v4 phy-next 1/9] soc: fsl: guts: perform fsl_guts_init() error teardown in reverse order of setup
Ioana Ciornei <[email protected]>
| Newsgroups | gmane.linux.ports.ppc.embedded |
|---|---|
| Message-ID | <u7ihkf5cwaijzwkpf2mezokjfb2f77gqycn4p64drzj5lxa7zd__47065.9503176407$1784711756$gmane$org@5irimzukasw4> |
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/[email protected]/ > > Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Ioana Ciornei <[email protected]>