If device_add() fails, call put_device() to drop the device reference. And put_device() triggers fsl_mc_device_release() which does the free. Thus just return after call put_device().
Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Su Hui <[email protected]> Signed-off-by: Haoxiang Li <[email protected]> --- Changes in v2: - fix a patch error. Thanks, Christophe. - add specific changelog. Thanks, Dan. --- 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..f976c5a24151 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); + return error; } dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev)); -- 2.25.1
