linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] rtc: st-lpc: Release some resources in st_rtc_probe() in case of error
@ 2023-06-08 19:11 Christophe JAILLET
  2023-06-08 19:12 ` [PATCH 2/2] rtc: st-lpc: Simplify clk handling in st_rtc_probe() Christophe JAILLET
  2023-06-25 22:53 ` [PATCH 1/2] rtc: st-lpc: Release some resources in st_rtc_probe() in case of error Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2023-06-08 19:11 UTC (permalink / raw)
  To: Patrice Chotard, Alessandro Zummo, Alexandre Belloni, Lee Jones
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	linux-arm-kernel, linux-rtc

If an error occurs after clk_get(), the corresponding resources should be
released.

Use devm_clk_get() to fix it.

Fixes: b5b2bdfc2893 ("rtc: st: Add new driver for ST's LPC RTC")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/rtc/rtc-st-lpc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c
index 0f8e4231098e..d04d46f9cc65 100644
--- a/drivers/rtc/rtc-st-lpc.c
+++ b/drivers/rtc/rtc-st-lpc.c
@@ -228,7 +228,7 @@ static int st_rtc_probe(struct platform_device *pdev)
 	enable_irq_wake(rtc->irq);
 	disable_irq(rtc->irq);
 
-	rtc->clk = clk_get(&pdev->dev, NULL);
+	rtc->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(rtc->clk)) {
 		dev_err(&pdev->dev, "Unable to request clock\n");
 		return PTR_ERR(rtc->clk);
-- 
2.34.1


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

* [PATCH 2/2] rtc: st-lpc: Simplify clk handling in st_rtc_probe()
  2023-06-08 19:11 [PATCH 1/2] rtc: st-lpc: Release some resources in st_rtc_probe() in case of error Christophe JAILLET
@ 2023-06-08 19:12 ` Christophe JAILLET
  2023-06-25 22:53 ` [PATCH 1/2] rtc: st-lpc: Release some resources in st_rtc_probe() in case of error Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2023-06-08 19:12 UTC (permalink / raw)
  To: Patrice Chotard, Alessandro Zummo, Alexandre Belloni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	linux-arm-kernel, linux-rtc

Use devm_clk_get_enabled() instead of hand writing it. This simplifies
error handling and removes some lines of code.

Also use dev_err_probe() which filters -EPROBE_DEFER.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/rtc/rtc-st-lpc.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c
index d04d46f9cc65..d492a2d26600 100644
--- a/drivers/rtc/rtc-st-lpc.c
+++ b/drivers/rtc/rtc-st-lpc.c
@@ -228,17 +228,13 @@ static int st_rtc_probe(struct platform_device *pdev)
 	enable_irq_wake(rtc->irq);
 	disable_irq(rtc->irq);
 
-	rtc->clk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(rtc->clk)) {
-		dev_err(&pdev->dev, "Unable to request clock\n");
-		return PTR_ERR(rtc->clk);
-	}
-
-	clk_prepare_enable(rtc->clk);
+	rtc->clk = devm_clk_get_enabled(&pdev->dev, NULL);
+	if (IS_ERR(rtc->clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(rtc->clk),
+				     "Unable to request clock\n");
 
 	rtc->clkrate = clk_get_rate(rtc->clk);
 	if (!rtc->clkrate) {
-		clk_disable_unprepare(rtc->clk);
 		dev_err(&pdev->dev, "Unable to fetch clock rate\n");
 		return -EINVAL;
 	}
@@ -252,10 +248,8 @@ static int st_rtc_probe(struct platform_device *pdev)
 	do_div(rtc->rtc_dev->range_max, rtc->clkrate);
 
 	ret = devm_rtc_register_device(rtc->rtc_dev);
-	if (ret) {
-		clk_disable_unprepare(rtc->clk);
+	if (ret)
 		return ret;
-	}
 
 	return 0;
 }
-- 
2.34.1


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

* Re: [PATCH 1/2] rtc: st-lpc: Release some resources in st_rtc_probe() in case of error
  2023-06-08 19:11 [PATCH 1/2] rtc: st-lpc: Release some resources in st_rtc_probe() in case of error Christophe JAILLET
  2023-06-08 19:12 ` [PATCH 2/2] rtc: st-lpc: Simplify clk handling in st_rtc_probe() Christophe JAILLET
@ 2023-06-25 22:53 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2023-06-25 22:53 UTC (permalink / raw)
  To: Patrice Chotard, Alessandro Zummo, Lee Jones, Christophe JAILLET
  Cc: linux-kernel, kernel-janitors, linux-arm-kernel, linux-rtc


On Thu, 08 Jun 2023 21:11:42 +0200, Christophe JAILLET wrote:
> If an error occurs after clk_get(), the corresponding resources should be
> released.
> 
> Use devm_clk_get() to fix it.
> 
> 

Applied, thanks!

[1/2] rtc: st-lpc: Release some resources in st_rtc_probe() in case of error
      commit: 06c6e1b01d9261f03629cefd1f3553503291e6cf
[2/2] rtc: st-lpc: Simplify clk handling in st_rtc_probe()
      commit: 0e6f36cca1bd3f5257315b55d9f31519ea4cc059

-- 
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:[~2023-06-25 22:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08 19:11 [PATCH 1/2] rtc: st-lpc: Release some resources in st_rtc_probe() in case of error Christophe JAILLET
2023-06-08 19:12 ` [PATCH 2/2] rtc: st-lpc: Simplify clk handling in st_rtc_probe() Christophe JAILLET
2023-06-25 22:53 ` [PATCH 1/2] rtc: st-lpc: Release some resources in st_rtc_probe() in case of error 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).