mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] watchdog: starfive: Fix resource leak in probe error path
@ 2025-11-05  8:42 Haotian Zhang
  2025-11-05 10:45 ` Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Haotian Zhang @ 2025-11-05  8:42 UTC (permalink / raw)
  To: linux-watchdog, xingyu.wu, ziv.xu, wim; +Cc: linux, linux-kernel, Haotian Zhang

If pm_runtime_put_sync() fails after watchdog_register_device()
succeeds, the probe function jumps to err_exit without
unregistering the watchdog device. This leaves the watchdog
registered in the subsystem while the driver fails to load,
resulting in a resource leak.

Add a new error label err_unregister_wdt to properly unregister
the watchdog device.

Fixes: 8bc22a2f1bf0 ("watchdog: starfive: Check pm_runtime_enabled() before decrementing usage counter")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/watchdog/starfive-wdt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/starfive-wdt.c b/drivers/watchdog/starfive-wdt.c
index 355918d62f63..ed71d3960a0f 100644
--- a/drivers/watchdog/starfive-wdt.c
+++ b/drivers/watchdog/starfive-wdt.c
@@ -500,12 +500,14 @@ static int starfive_wdt_probe(struct platform_device *pdev)
 		if (pm_runtime_enabled(&pdev->dev)) {
 			ret = pm_runtime_put_sync(&pdev->dev);
 			if (ret)
-				goto err_exit;
+				goto err_unregister_wdt;
 		}
 	}
 
 	return 0;
 
+err_unregister_wdt:
+	watchdog_unregister_device(&wdt->wdd);
 err_exit:
 	starfive_wdt_disable_clock(wdt);
 	pm_runtime_disable(&pdev->dev);
-- 
2.50.1.windows.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] watchdog: starfive: Fix resource leak in probe error path
  2025-11-05  8:42 [PATCH] watchdog: starfive: Fix resource leak in probe error path Haotian Zhang
@ 2025-11-05 10:45 ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-11-05 10:45 UTC (permalink / raw)
  To: vulab, linux-watchdog
  Cc: LKML, Günter Röck, Wim Van Sebroeck, Xingyu Wu, Ziv Xu

> If pm_runtime_put_sync() fails after watchdog_register_device()
> succeeds, the probe function jumps to err_exit without
…

Would an other word wrapping be a bit nicer for such a change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc4#n658

Regards,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-05 10:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-05  8:42 [PATCH] watchdog: starfive: Fix resource leak in probe error path Haotian Zhang
2025-11-05 10:45 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®