[PATCH] bus: fsl-mc: fix an error handling in fsl_mc_device_add()

Christophe Leroy (CS GROUP) chleroy at kernel.org
Wed Dec 24 02:34:44 AEDT 2025



Le 22/12/2025 à 08:49, Haoxiang Li a écrit :
> If device_add() fails, call put_device() to drop the device
> reference and do the cleanp.
> 
> Reported-by: Dan Carpenter <dan.carpenter at linaro.org>
> Closes: https://lore.kernel.org/all/b767348e-d89c-416e-acea-1ebbff3bea20@stanley.mountain/
> Signed-off-by: Su Hui <suhui at nfschina.com>
> Signed-off-by: Haoxiang Li <lihaoxiang at isrc.iscas.ac.cn>
> ---
>   drivers/bus/fsl-mc/fsl-mc-bus.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
> index 25845c04e562..90a2107a9905 100644
> --- a/drivers/bus/fsl-mc/fsl-mc-bus.c
> +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
> @@ -896,7 +896,8 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
>   		dev_err(parent_dev,
>   			"device_add() failed for device %s: %d\n",
>   			dev_name(&mc_dev->dev), error);
> -		goto error_cleanup_dev;
> +		put_device(&mc_dev->dev)

This change has obviously not been tested, not even built.

And by droping the goto, the kfree() are not done anymore, leaking 
mc_bus/mc_dev p kzalloced areas.

> +		return error;
>   	}
>   
>   	dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev));



More information about the Linuxppc-dev mailing list