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@xxxxxxxxxxxxxxxxxxxxx> --- drivers/rtc/rtc-cpcap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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[] = { -- 2.34.1