diff mbox series

rtc: cros-ec: disable wakeup in the error path of .probe()

Message ID 20241212121107.3903967-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive)
State New
Headers show
Series rtc: cros-ec: disable wakeup in the error path of .probe() | expand

Commit Message

Joe Hattori Dec. 12, 2024, 12:11 p.m. UTC
Current code leaves the device's wakeup enabled in the error path of
.probe(), which results in a memory leak. Fix it by calling
devm_add_action_or_reset() with a callback which calls
device_init_wakeup(dev, false).

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

Fixes: 6f2a71a31afd ("rtc: cros-ec: add cros-ec-rtc driver.")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/rtc/rtc-cros-ec.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c
index 60a48c3ba3ca..4cd6eab0fd8c 100644
--- a/drivers/rtc/rtc-cros-ec.c
+++ b/drivers/rtc/rtc-cros-ec.c
@@ -314,6 +314,13 @@  static int cros_ec_rtc_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(cros_ec_rtc_pm_ops, cros_ec_rtc_suspend,
 			 cros_ec_rtc_resume);
 
+static void cros_ec_disable_wakeup(void *data)
+{
+	struct device *dev = data;
+
+	device_init_wakeup(dev, false);
+}
+
 static int cros_ec_rtc_probe(struct platform_device *pdev)
 {
 	struct cros_ec_dev *ec_dev = dev_get_drvdata(pdev->dev.parent);
@@ -343,6 +350,11 @@  static int cros_ec_rtc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = devm_add_action_or_reset(&pdev->dev, cros_ec_disable_wakeup,
+				       &pdev->dev);
+	if (ret)
+		return ret;
+
 	cros_ec_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(cros_ec_rtc->rtc))
 		return PTR_ERR(cros_ec_rtc->rtc);