]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
watchdog: starfive: Fix resource leak in probe error path
authorHaotian Zhang <vulab@iscas.ac.cn>
Wed, 5 Nov 2025 08:42:20 +0000 (16:42 +0800)
committerWim Van Sebroeck <wim@linux-watchdog.org>
Sat, 15 Nov 2025 14:29:01 +0000 (15:29 +0100)
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>
Reviewed-by: Wim Van Sebroeck <wim@linux-watchdog.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
drivers/watchdog/starfive-wdt.c

index 355918d62f63d54ae1efd804c575a655e9d3587d..ed71d3960a0f2622b85d71a6dc7252b5b6e69105 100644 (file)
@@ -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);