Linux RTC
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Cc: mazziesaccount@gmail.com, linux-rtc@vger.kernel.org
Subject: Re: [PATCH v3] rtc: bd70528: enable the device's wakeup in the last step of .probe()
Date: Thu, 12 Dec 2024 11:34:59 +0100	[thread overview]
Message-ID: <20241212103459276170c1@mail.local> (raw)
In-Reply-To: <20241212100403.3799667-1-joe@pf.is.s.u-tokyo.ac.jp>

On 12/12/2024 19:04:03+0900, Joe Hattori wrote:
> 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.

Do you have more info on where the memory is allocated?

Coudln't we have a devm_ version of device_init_wakeup instead?

> 
> This bug was found by an experimental static analysis tool that I am
> developing.
> 
> Fixes: 32a4a4ebf768 ("rtc: bd70528: Initial support for ROHM bd70528 RTC")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
> ---
> Changes in V2:
> - Move the device_init_wakeup() to the last step of the .probe() to make
>   the cleanup simpler.
> ---
>  drivers/rtc/rtc-bd70528.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-bd70528.c b/drivers/rtc/rtc-bd70528.c
> index 954ac4ef53e8..d5cc4993f918 100644
> --- a/drivers/rtc/rtc-bd70528.c
> +++ b/drivers/rtc/rtc-bd70528.c
> @@ -312,9 +312,6 @@ static int bd70528_probe(struct platform_device *pdev)
>  		}
>  	}
>  
> -	device_set_wakeup_capable(&pdev->dev, true);
> -	device_wakeup_enable(&pdev->dev);
> -
>  	rtc = devm_rtc_allocate_device(&pdev->dev);
>  	if (IS_ERR(rtc)) {
>  		dev_err(&pdev->dev, "RTC device creation failed\n");
> @@ -331,7 +328,12 @@ static int bd70528_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	return devm_rtc_register_device(rtc);
> +	ret = devm_rtc_register_device(rtc);
> +	if (ret)
> +		return ret;
> +
> +	device_init_wakeup(&pdev->dev, true);
> +	return 0;
>  }
>  
>  static const struct platform_device_id bd718x7_rtc_id[] = {
> -- 
> 2.34.1
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2024-12-12 10:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-12 10:04 [PATCH v3] rtc: bd70528: enable the device's wakeup in the last step of .probe() Joe Hattori
2024-12-12 10:34 ` Alexandre Belloni [this message]
2024-12-12 12:04   ` Joe Hattori
2024-12-12 12:43     ` Matti Vaittinen
2024-12-12 17:52     ` Alexandre Belloni
2024-12-14  2:18       ` Joe Hattori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241212103459276170c1@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=joe@pf.is.s.u-tokyo.ac.jp \
    --cc=linux-rtc@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox