linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Yuanjun Gong <ruc_gongyuanjun@163.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>, linux-rtc@vger.kernel.org
Subject: Re: [PATCH 1/1] rtc: use devm_clk_get_enabled() in mv_rtc_probe()
Date: Thu, 10 Aug 2023 10:17:17 +0200	[thread overview]
Message-ID: <202308100817171950180f@mail.local> (raw)
In-Reply-To: <20230720140814.33301-1-ruc_gongyuanjun@163.com>

On 20/07/2023 22:08:14+0800, Yuanjun Gong wrote:
> in mv_rtc_probe(), the return value of function
> clk_prepare_enable() should be checked, since it may fail.
> using devm_clk_get_enabled() instead of devm_clk_get() and
> clk_prepare_enable() can avoid this problem.
> 
> Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>
> ---
>  drivers/rtc/rtc-mv.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c
> index 6c526e2ec56d..8cd33721be03 100644
> --- a/drivers/rtc/rtc-mv.c
> +++ b/drivers/rtc/rtc-mv.c
> @@ -219,17 +219,16 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
>  	if (IS_ERR(pdata->ioaddr))
>  		return PTR_ERR(pdata->ioaddr);
>  
> -	pdata->clk = devm_clk_get(&pdev->dev, NULL);
> +	pdata->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  	/* Not all SoCs require a clock.*/
> -	if (!IS_ERR(pdata->clk))
> -		clk_prepare_enable(pdata->clk);
> +	if (IS_ERR(pdata->clk))
> +		return PTR_ERR(pdata->clk);

Look at the comment, "Not all SoCs require a clock.", you are breaking
the driver for multiple platforms.

>  
>  	/* make sure the 24 hour mode is enabled */
>  	rtc_time = readl(pdata->ioaddr + RTC_TIME_REG_OFFS);
>  	if (rtc_time & RTC_HOURS_12H_MODE) {
>  		dev_err(&pdev->dev, "12 Hour mode is enabled but not supported.\n");
> -		ret = -EINVAL;
> -		goto out;
> +		return -EINVAL;
>  	}
>  
>  	/* make sure it is actually functional */
> @@ -238,8 +237,7 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
>  		rtc_time = readl(pdata->ioaddr + RTC_TIME_REG_OFFS);
>  		if (rtc_time == 0x01000000) {
>  			dev_err(&pdev->dev, "internal RTC not ticking\n");
> -			ret = -ENODEV;
> -			goto out;
> +			return -ENODEV;
>  		}
>  	}
>  
> @@ -249,8 +247,7 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
>  
>  	pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
>  	if (IS_ERR(pdata->rtc)) {
> -		ret = PTR_ERR(pdata->rtc);
> -		goto out;
> +		return PTR_ERR(pdata->rtc);
>  	}
>  
>  	if (pdata->irq >= 0) {
> @@ -275,11 +272,6 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
>  	ret = devm_rtc_register_device(pdata->rtc);
>  	if (!ret)
>  		return 0;
> -out:
> -	if (!IS_ERR(pdata->clk))
> -		clk_disable_unprepare(pdata->clk);
> -
> -	return ret;
>  }
>  
>  static int __exit mv_rtc_remove(struct platform_device *pdev)
> -- 
> 2.17.1
> 

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

      reply	other threads:[~2023-08-10  8:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20 14:08 [PATCH 1/1] rtc: use devm_clk_get_enabled() in mv_rtc_probe() Yuanjun Gong
2023-08-10  8:17 ` Alexandre Belloni [this message]

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=202308100817171950180f@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=a.zummo@towertech.it \
    --cc=linux-rtc@vger.kernel.org \
    --cc=ruc_gongyuanjun@163.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;
as well as URLs for NNTP newsgroup(s).