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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxxxx>
---
 drivers/rtc/rtc-cros-ec.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

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);
-- 
2.34.1





[Index of Archives]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux