diff mbox series

rtc: cpcap: enable the device's wakeup in the last step of .probe()

Message ID 20241212102403.3821014-1-joe@pf.is.s.u-tokyo.ac.jp
State Superseded
Headers show
Series rtc: cpcap: enable the device's wakeup in the last step of .probe() | expand

Commit Message

Joe Hattori Dec. 12, 2024, 10:24 a.m. UTC
Current code leaves the device's wakeup enabled in the error path of
.probe(), which results in a memory leak. Call device_init_wakeup() as
the last step in the .probe() to avoid this leak.

This bug was found by an experimental static analysis tool that I am
developing.

Fixes: fdcfd854333b ("rtc: rework rtc_register_device() resource management")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/rtc/rtc-cpcap.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-cpcap.c b/drivers/rtc/rtc-cpcap.c
index afc8fcba8f88..f174dcd0b34f 100644
--- a/drivers/rtc/rtc-cpcap.c
+++ b/drivers/rtc/rtc-cpcap.c
@@ -295,13 +295,16 @@  static int cpcap_rtc_probe(struct platform_device *pdev)
 	}
 	disable_irq(rtc->update_irq);
 
+	err = devm_rtc_register_device(rtc->rtc_dev);
+	if (err)
+		return err;
+
 	err = device_init_wakeup(dev, 1);
 	if (err) {
 		dev_err(dev, "wakeup initialization failed (%d)\n", err);
 		/* ignore error and continue without wakeup support */
 	}
-
-	return devm_rtc_register_device(rtc->rtc_dev);
+	return 0;
 }
 
 static const struct of_device_id cpcap_rtc_of_match[] = {