Skip to content

Commit 5bcc578

Browse files
ISCAS-VulabWim Van Sebroeck
authored andcommitted
watchdog: starfive: Fix resource leak in probe error path
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: 8bc22a2 ("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>
1 parent 6fbf541 commit 5bcc578

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/watchdog/starfive-wdt.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,14 @@ static int starfive_wdt_probe(struct platform_device *pdev)
500500
if (pm_runtime_enabled(&pdev->dev)) {
501501
ret = pm_runtime_put_sync(&pdev->dev);
502502
if (ret)
503-
goto err_exit;
503+
goto err_unregister_wdt;
504504
}
505505
}
506506

507507
return 0;
508508

509+
err_unregister_wdt:
510+
watchdog_unregister_device(&wdt->wdd);
509511
err_exit:
510512
starfive_wdt_disable_clock(wdt);
511513
pm_runtime_disable(&pdev->dev);

0 commit comments

Comments
 (0)