Skip to contentSkip to conversation

clocksource/drivers/timer-gxp: Add missing error handling in gxp_timer_probe

PATCH Applied Lin Yujun 3 participants 3 messages Sep 14, 2022 – Oct 4, 2022

Subsystems (2)
lore
Share & tools
lore

Lin Yujun

author
#0 lore raw

PATCH 1/1 clocksource/drivers/timer-gxp: Add missing error handling in gxp_timer_probe

Add platform_device_put() to make sure to free the platform device in the event platform_device_add() fails.

Fixes 5184f4bf151b ("clocksource/drivers/timer-gxp: Add HPE GXP Timer")
---
 drivers/clocksource/timer-gxp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/clocksource/timer-gxp.c +6 -1
index 8b38b3212388..fe4fa8d7b3f1 100644
@@ -171,6 +171,7 @@ static int gxp_timer_probe(struct platform_device *pdev)
 {
 	struct platform_device *gxp_watchdog_device;
 	struct device *dev = &pdev->dev;
+	int ret;
 
 	if (!gxp_timer) {
 		pr_err("Gxp Timer not initialized, cannot create watchdog");
@@ -187,7 +188,11 @@ static int gxp_timer_probe(struct platform_device *pdev)
 	gxp_watchdog_device->dev.platform_data = gxp_timer->counter;
 	gxp_watchdog_device->dev.parent = dev;
 
-	return platform_device_add(gxp_watchdog_device);
+	ret = platform_device_add(gxp_watchdog_device);
+	if (ret)
+		platform_device_put(gxp_watchdog_device);
+
+	return ret;
 }
 
 static const struct of_device_id gxp_timer_of_match[] = {
Signature · 1 line
2.17.1
#1 lore raw
Quoted 6 lines · Lin Yujun

Add platform_device_put() to make sure to free the platform device in the event platform_device_add() fails.

Fixes 5184f4bf151b ("clocksource/drivers/timer-gxp: Add HPE GXP Timer")

---

Applied, thanks

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
merge bot Applied
#2 lore raw
In reply to Lin Yujun
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     0e2c8e6d769bcdc4f6634a02c545356282275e68
Gitweb:        https://git.kernel.org/tip/0e2c8e6d769bcdc4f6634a02c545356282275e68
Author:        Lin Yujun <[email protected]>
AuthorDate:    Wed, 14 Sep 2022 11:30:18 +08:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Tue, 20 Sep 2022 10:49:45 +02:00

clocksource/drivers/timer-gxp: Add missing error handling in gxp_timer_probe

Add platform_device_put() to make sure to free the platform device in the event platform_device_add() fails.

Fixes 5184f4bf151b ("clocksource/drivers/timer-gxp: Add HPE GXP Timer")
---
 drivers/clocksource/timer-gxp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/clocksource/timer-gxp.c +6 -1
index 8b38b32..fe4fa8d 100644
@@ -171,6 +171,7 @@ static int gxp_timer_probe(struct platform_device *pdev)
 {
 	struct platform_device *gxp_watchdog_device;
 	struct device *dev = &pdev->dev;
+	int ret;
 
 	if (!gxp_timer) {
 		pr_err("Gxp Timer not initialized, cannot create watchdog");
@@ -187,7 +188,11 @@ static int gxp_timer_probe(struct platform_device *pdev)
 	gxp_watchdog_device->dev.platform_data = gxp_timer->counter;
 	gxp_watchdog_device->dev.parent = dev;
 
-	return platform_device_add(gxp_watchdog_device);
+	ret = platform_device_add(gxp_watchdog_device);
+	if (ret)
+		platform_device_put(gxp_watchdog_device);
+
+	return ret;
 }
 
 static const struct of_device_id gxp_timer_of_match[] = {