In fsl_mc_device_add(), device_initialize() is called first.
put_device() should be called to drop the reference if error
occurs. And other resources would be released via put_device
-> fsl_mc_device_release. So remove redundant kfree() in
error handling path.

Fixes: bbf9d17d9875 ("staging: fsl-mc: Freescale Management Complex (fsl-mc) 
bus driver")
Cc: [email protected]
Reported-by: Dan Carpenter <[email protected]>
Closes: 
https://lore.kernel.org/all/[email protected]/
Signed-off-by: Su Hui <[email protected]>
Suggested-by: Christophe Leroy (CS GROUP) <[email protected]>
Signed-off-by: Haoxiang Li <[email protected]>
---
Changes in v2:
- fix a patch error. Thanks, Christophe.
- add specific changelog. Thanks, Dan.
Changes in v3:
- Also call put_device() in other error paths. Thanks, Ioana.
---
 drivers/bus/fsl-mc/fsl-mc-bus.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
index 25845c04e562..6d132144ce25 100644
--- a/drivers/bus/fsl-mc/fsl-mc-bus.c
+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
@@ -905,11 +905,7 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
        return 0;
 
 error_cleanup_dev:
-       kfree(mc_dev->regions);
-       if (mc_bus)
-               kfree(mc_bus);
-       else
-               kfree(mc_dev);
+       put_device(&mc_dev->dev);
 
        return error;
 }
-- 
2.25.1


Reply via email to