kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: jz4740: Use devm_clk_get_enabled() helper
@ 2022-08-24  8:42 Christophe JAILLET
  2022-08-25 22:41 ` Paul Cercueil
  2022-10-13 21:31 ` Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-08-24  8:42 UTC (permalink / raw)
  To: Paul Cercueil, Alessandro Zummo, Alexandre Belloni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-mips, linux-rtc

The devm_clk_get_enabled() helper:
   - calls devm_clk_get()
   - calls clk_prepare_enable() and registers what is needed in order to
     call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code, the error handling paths and avoid the need of
a dedicated function used with devm_add_action_or_reset().


As a side effect, some error messages are not logged anymore, so also use
dev_err_probe() instead of dev_err() in case of error.
At least the error code will be logged (and -EPROBE_DEFER will be filtered)

Based on my test with allyesconfig, this reduces the .o size from:
   text	   data	    bss	    dec	    hex	filename
   9025	   2488	    128	  11641	   2d79	drivers/rtc/rtc-jz4740.o
down to:
   8267	   2080	    128	  10475	   28eb	drivers/rtc/rtc-jz4740.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
devm_clk_get_enabled() is new and is part of 6.0-rc1

Some recent changed use "rtc: ingenic". This looks odd to me, so turn back
to "rtc: jz4740"
---
 drivers/rtc/rtc-jz4740.c | 25 +++----------------------
 1 file changed, 3 insertions(+), 22 deletions(-)

diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index 6e51df72fd65..c383719292c7 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -257,11 +257,6 @@ static void jz4740_rtc_power_off(void)
 	kernel_halt();
 }
 
-static void jz4740_rtc_clk_disable(void *data)
-{
-	clk_disable_unprepare(data);
-}
-
 static const struct of_device_id jz4740_rtc_of_match[] = {
 	{ .compatible = "ingenic,jz4740-rtc", .data = (void *)ID_JZ4740 },
 	{ .compatible = "ingenic,jz4760-rtc", .data = (void *)ID_JZ4760 },
@@ -329,23 +324,9 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
 	if (IS_ERR(rtc->base))
 		return PTR_ERR(rtc->base);
 
-	clk = devm_clk_get(dev, "rtc");
-	if (IS_ERR(clk)) {
-		dev_err(dev, "Failed to get RTC clock\n");
-		return PTR_ERR(clk);
-	}
-
-	ret = clk_prepare_enable(clk);
-	if (ret) {
-		dev_err(dev, "Failed to enable clock\n");
-		return ret;
-	}
-
-	ret = devm_add_action_or_reset(dev, jz4740_rtc_clk_disable, clk);
-	if (ret) {
-		dev_err(dev, "Failed to register devm action\n");
-		return ret;
-	}
+	clk = devm_clk_get_enabled(dev, "rtc");
+	if (IS_ERR(clk))
+		return dev_err_probe(dev, PTR_ERR(clk), "Failed to get RTC clock\n");
 
 	spin_lock_init(&rtc->lock);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtc: jz4740: Use devm_clk_get_enabled() helper
  2022-08-24  8:42 [PATCH] rtc: jz4740: Use devm_clk_get_enabled() helper Christophe JAILLET
@ 2022-08-25 22:41 ` Paul Cercueil
  2022-10-13 21:31 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Cercueil @ 2022-08-25 22:41 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Alessandro Zummo, Alexandre Belloni, linux-kernel,
	kernel-janitors, linux-mips, linux-rtc

Hi Christophe,

Le mer., août 24 2022 at 10:42:29 +0200, Christophe JAILLET 
<christophe.jaillet@wanadoo.fr> a écrit :
> The devm_clk_get_enabled() helper:
>    - calls devm_clk_get()
>    - calls clk_prepare_enable() and registers what is needed in order 
> to
>      call clk_disable_unprepare() when needed, as a managed resource.
> 
> This simplifies the code, the error handling paths and avoid the need 
> of
> a dedicated function used with devm_add_action_or_reset().
> 
> 
> As a side effect, some error messages are not logged anymore, so also 
> use
> dev_err_probe() instead of dev_err() in case of error.
> At least the error code will be logged (and -EPROBE_DEFER will be 
> filtered)
> 
> Based on my test with allyesconfig, this reduces the .o size from:
>    text	   data	    bss	    dec	    hex	filename
>    9025	   2488	    128	  11641	   2d79	drivers/rtc/rtc-jz4740.o
> down to:
>    8267	   2080	    128	  10475	   28eb	drivers/rtc/rtc-jz4740.o
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Paul Cercueil <paul@crapouillou.net>

> ---
> devm_clk_get_enabled() is new and is part of 6.0-rc1
> 
> Some recent changed use "rtc: ingenic". This looks odd to me, so turn 
> back
> to "rtc: jz4740"

Yes, the driver basically supports everything Ingenic now, so I 
generally write "rtc: ingenic:", but "rtc: jz4740:" is absolutely fine.

Cheers,
-Paul

> ---
>  drivers/rtc/rtc-jz4740.c | 25 +++----------------------
>  1 file changed, 3 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
> index 6e51df72fd65..c383719292c7 100644
> --- a/drivers/rtc/rtc-jz4740.c
> +++ b/drivers/rtc/rtc-jz4740.c
> @@ -257,11 +257,6 @@ static void jz4740_rtc_power_off(void)
>  	kernel_halt();
>  }
> 
> -static void jz4740_rtc_clk_disable(void *data)
> -{
> -	clk_disable_unprepare(data);
> -}
> -
>  static const struct of_device_id jz4740_rtc_of_match[] = {
>  	{ .compatible = "ingenic,jz4740-rtc", .data = (void *)ID_JZ4740 },
>  	{ .compatible = "ingenic,jz4760-rtc", .data = (void *)ID_JZ4760 },
> @@ -329,23 +324,9 @@ static int jz4740_rtc_probe(struct 
> platform_device *pdev)
>  	if (IS_ERR(rtc->base))
>  		return PTR_ERR(rtc->base);
> 
> -	clk = devm_clk_get(dev, "rtc");
> -	if (IS_ERR(clk)) {
> -		dev_err(dev, "Failed to get RTC clock\n");
> -		return PTR_ERR(clk);
> -	}
> -
> -	ret = clk_prepare_enable(clk);
> -	if (ret) {
> -		dev_err(dev, "Failed to enable clock\n");
> -		return ret;
> -	}
> -
> -	ret = devm_add_action_or_reset(dev, jz4740_rtc_clk_disable, clk);
> -	if (ret) {
> -		dev_err(dev, "Failed to register devm action\n");
> -		return ret;
> -	}
> +	clk = devm_clk_get_enabled(dev, "rtc");
> +	if (IS_ERR(clk))
> +		return dev_err_probe(dev, PTR_ERR(clk), "Failed to get RTC 
> clock\n");
> 
>  	spin_lock_init(&rtc->lock);
> 
> --
> 2.34.1
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtc: jz4740: Use devm_clk_get_enabled() helper
  2022-08-24  8:42 [PATCH] rtc: jz4740: Use devm_clk_get_enabled() helper Christophe JAILLET
  2022-08-25 22:41 ` Paul Cercueil
@ 2022-10-13 21:31 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2022-10-13 21:31 UTC (permalink / raw)
  To: Alessandro Zummo, Christophe JAILLET, Paul Cercueil
  Cc: linux-kernel, linux-rtc, kernel-janitors, linux-mips

On Wed, 24 Aug 2022 10:42:29 +0200, Christophe JAILLET wrote:
> The devm_clk_get_enabled() helper:
>    - calls devm_clk_get()
>    - calls clk_prepare_enable() and registers what is needed in order to
>      call clk_disable_unprepare() when needed, as a managed resource.
> 
> This simplifies the code, the error handling paths and avoid the need of
> a dedicated function used with devm_add_action_or_reset().
> 
> [...]

Applied, thanks!

[1/1] rtc: jz4740: Use devm_clk_get_enabled() helper
      commit: 94e4603d1a262f8d79f6186d0df0379243613b95

Best regards,

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-13 21:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-24  8:42 [PATCH] rtc: jz4740: Use devm_clk_get_enabled() helper Christophe JAILLET
2022-08-25 22:41 ` Paul Cercueil
2022-10-13 21:31 ` Alexandre Belloni

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).