Skip to contentSkip to conversation

pxa: Release platform device in case of platform_device_add() fails.

PATCH In review Lin Yujun 1 participant 2 messages Sep 14, 2022 – Sep 26, 2022

Subsystems (3)
lore
Share & tools
lore

Lin Yujun

author
#0 lore raw

PATCH 1/1 pxa: Release platform device in case of platform_device_add() fails.

The platform device is not released when platform_device_add() fails. Use platform_device_put() to release these resource.

Fixes 49cbe78637eb ("[ARM] pxa: add base support for Marvell's PXA168 processor line")
---
 arch/arm/mach-mmp/devices.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
arch/arm/mach-mmp/devices.c +12 -9
index 79f4a2aa5475..e918f419bc4c 100644
@@ -53,20 +53,23 @@ int __init mmp_register_device(struct mmp_device_desc *desc,
 	}
 
 	ret = platform_device_add_resources(pdev, res, nres);
-	if (ret) {
-		platform_device_put(pdev);
-		return ret;
-	}
+	if (ret)
+		goto err_put_pdev;
 
 	if (data && size) {
 		ret = platform_device_add_data(pdev, data, size);
-		if (ret) {
-			platform_device_put(pdev);
-			return ret;
-		}
+		if (ret)
+			goto err_put_pdev;
 	}
 
-	return platform_device_add(pdev);
+	ret = platform_device_add(pdev);
+	if (ret)
+		goto err_put_pdev;
+	return ret;
+
+err_put_pdev:
+	platform_device_put(pdev);
+	return ret;
 }
 
 #if IS_ENABLED(CONFIG_USB) || IS_ENABLED(CONFIG_USB_GADGET)
Signature · 1 line
2.17.1
#1 lore raw

kindly ping

Quoted 46 lines · Lin Yujun

The platform device is not released when platform_device_add() fails. Use platform_device_put() to release these resource.

Fixes 49cbe78637eb ("[ARM] pxa: add base support for Marvell's PXA168 processor line")
---
  arch/arm/mach-mmp/devices.c | 21 ++++++++++++---------
  1 file changed, 12 insertions(+), 9 deletions(-)
arch/arm/mach-mmp/devices.c +12 -9
index 79f4a2aa5475..e918f419bc4c 100644
@@ -53,20 +53,23 @@ int __init mmp_register_device(struct mmp_device_desc *desc,
  	}
 
  	ret = platform_device_add_resources(pdev, res, nres);
-	if (ret) {
-		platform_device_put(pdev);
-		return ret;
-	}
+	if (ret)
+		goto err_put_pdev;
 
  	if (data && size) {
  		ret = platform_device_add_data(pdev, data, size);
-		if (ret) {
-			platform_device_put(pdev);
-			return ret;
-		}
+		if (ret)
+			goto err_put_pdev;
  	}
 
-	return platform_device_add(pdev);
+	ret = platform_device_add(pdev);
+	if (ret)
+		goto err_put_pdev;
+	return ret;
+
+err_put_pdev:
+	platform_device_put(pdev);
+	return ret;
  }
 
  #if IS_ENABLED(CONFIG_USB) || IS_ENABLED(CONFIG_USB_GADGET)