[PATCH v3 phy-next 2/8] soc: fsl: guts: add a global structure to hold state

Vladimir Oltean vladimir.oltean at nxp.com
Mon Jul 20 07:01:39 PDT 2026


On Mon, Jul 20, 2026 at 01:50:49PM +0000, sashiko-bot at kernel.org wrote:
> [Severity: High]
> Will jumping to err_nomem cause a NULL pointer dereference?
> 
> If the allocation of soc_dev_attr fails, the code now jumps to the error
> handling path which dereferences soc_dev_attr to free its members:
> 
> > @@ -269,6 +271,8 @@ static int __init fsl_guts_init(void)
> >  	kfree(soc_dev_attr->revision);
> >  	kfree(soc_dev_attr->serial_number);
> 
> Since soc_dev_attr is NULL when this allocation fails, won't evaluating
> soc_dev_attr->revision and other members result in a kernel panic?

yeah.

I tried to be nice and play with the existing "err_nomem" and "err"
error handling labels, but the truth is that a single error cleanup path
is just an antipattern that doesn't scale as code becomes more complex.

Instead of having a single error handling procedure which needs to
carefully fend off from various invalid contexts from all the goto
sites, the standard convention is to have an incremental set of labels
which undo just the setup that was done up to the goto jump site.

I'll refactor fsl_guts_init() to use that convention for v4.



More information about the linux-phy mailing list