diff mbox series

ARM: mmp: fix platform-device leak on registration errors

Message ID 20220303180900.3371-1-johan@kernel.org (mailing list archive)
State New, archived
Headers show
Series ARM: mmp: fix platform-device leak on registration errors | expand

Commit Message

Johan Hovold March 3, 2022, 6:09 p.m. UTC
Make sure to free the platform device also in the event that
registration fails.

Fixes: 49cbe78637eb ("[ARM] pxa: add base support for Marvell's PXA168 processor line")
Cc: stable@vger.kernel.org      # 2.6.30
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 arch/arm/mach-mmp/devices.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/arch/arm/mach-mmp/devices.c b/arch/arm/mach-mmp/devices.c
index 18bee66a671f..0b99aa1d5350 100644
--- a/arch/arm/mach-mmp/devices.c
+++ b/arch/arm/mach-mmp/devices.c
@@ -53,20 +53,25 @@  int __init pxa_register_device(struct pxa_device_desc *desc,
 	}
 
 	ret = platform_device_add_resources(pdev, res, nres);
-	if (ret) {
-		platform_device_put(pdev);
-		return ret;
-	}
+	if (ret)
+		goto err_put_device;
 
 	if (data && size) {
 		ret = platform_device_add_data(pdev, data, size);
-		if (ret) {
-			platform_device_put(pdev);
-			return ret;
-		}
+		if (ret)
+			goto err_put_device;
 	}
 
-	return platform_device_add(pdev);
+	ret = platform_device_add(pdev);
+	if (ret)
+		goto err_put_device;
+
+	return 0;
+
+err_put_device:
+	platform_device_put(pdev);
+
+	return ret;
 }
 
 #if IS_ENABLED(CONFIG_USB) || IS_ENABLED(CONFIG_USB_GADGET)