linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: ftrtc010: Fix error handling in ftrtc010_rtc_probe
@ 2022-04-03  5:49 Miaoqian Lin
  2022-04-19 22:55 ` Linus Walleij
  2022-05-19 10:11 ` Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Miaoqian Lin @ 2022-04-03  5:49 UTC (permalink / raw)
  To: Hans Ulli Kroll, Linus Walleij, Alessandro Zummo,
	Alexandre Belloni, linux-arm-kernel, linux-rtc, linux-kernel
  Cc: linmq006

In the error handling path, the clk_prepare_enable() function
call should be balanced by a corresponding 'clk_disable_unprepare()'
call , as already done in the remove function.

clk_disable_unprepare calls clk_disable() and clk_unprepare().
They will use IS_ERR_OR_NULL to check the argument.

Fixes: ac05fba39cc5 ("rtc: gemini: Add optional clock handling")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/rtc/rtc-ftrtc010.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/drivers/rtc/rtc-ftrtc010.c b/drivers/rtc/rtc-ftrtc010.c
index 53bb08fe1cd4..25c6e7d9570f 100644
--- a/drivers/rtc/rtc-ftrtc010.c
+++ b/drivers/rtc/rtc-ftrtc010.c
@@ -137,26 +137,34 @@ static int ftrtc010_rtc_probe(struct platform_device *pdev)
 		ret = clk_prepare_enable(rtc->extclk);
 		if (ret) {
 			dev_err(dev, "failed to enable EXTCLK\n");
-			return ret;
+			goto err_disable_pclk;
 		}
 	}
 
 	rtc->rtc_irq = platform_get_irq(pdev, 0);
-	if (rtc->rtc_irq < 0)
-		return rtc->rtc_irq;
+	if (rtc->rtc_irq < 0) {
+		ret = rtc->rtc_irq;
+		goto err_disable_extclk;
+	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENODEV;
+	if (!res) {
+		ret = -ENODEV;
+		goto err_disable_extclk;
+	}
 
 	rtc->rtc_base = devm_ioremap(dev, res->start,
 				     resource_size(res));
-	if (!rtc->rtc_base)
-		return -ENOMEM;
+	if (!rtc->rtc_base) {
+		ret = -ENOMEM;
+		goto err_disable_extclk;
+	}
 
 	rtc->rtc_dev = devm_rtc_allocate_device(dev);
-	if (IS_ERR(rtc->rtc_dev))
-		return PTR_ERR(rtc->rtc_dev);
+	if (IS_ERR(rtc->rtc_dev)) {
+		ret = PTR_ERR(rtc->rtc_dev);
+		goto err_disable_extclk;
+	}
 
 	rtc->rtc_dev->ops = &ftrtc010_rtc_ops;
 
@@ -172,9 +180,15 @@ static int ftrtc010_rtc_probe(struct platform_device *pdev)
 	ret = devm_request_irq(dev, rtc->rtc_irq, ftrtc010_rtc_interrupt,
 			       IRQF_SHARED, pdev->name, dev);
 	if (unlikely(ret))
-		return ret;
+		goto err_disable_extclk;
 
 	return devm_rtc_register_device(rtc->rtc_dev);
+
+err_disable_extclk:
+	clk_disable_unprepare(rtc->extclk);
+err_disable_pclk:
+	clk_disable_unprepare(rtc->pclk);
+	return ret;
 }
 
 static int ftrtc010_rtc_remove(struct platform_device *pdev)
-- 
2.17.1


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

* Re: [PATCH] rtc: ftrtc010: Fix error handling in ftrtc010_rtc_probe
  2022-04-03  5:49 [PATCH] rtc: ftrtc010: Fix error handling in ftrtc010_rtc_probe Miaoqian Lin
@ 2022-04-19 22:55 ` Linus Walleij
  2022-05-19 10:11 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2022-04-19 22:55 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Hans Ulli Kroll, Alessandro Zummo, Alexandre Belloni,
	linux-arm-kernel, linux-rtc, linux-kernel

On Sun, Apr 3, 2022 at 7:49 AM Miaoqian Lin <linmq006@gmail.com> wrote:

> In the error handling path, the clk_prepare_enable() function
> call should be balanced by a corresponding 'clk_disable_unprepare()'
> call , as already done in the remove function.
>
> clk_disable_unprepare calls clk_disable() and clk_unprepare().
> They will use IS_ERR_OR_NULL to check the argument.
>
> Fixes: ac05fba39cc5 ("rtc: gemini: Add optional clock handling")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Looks correct!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH] rtc: ftrtc010: Fix error handling in ftrtc010_rtc_probe
  2022-04-03  5:49 [PATCH] rtc: ftrtc010: Fix error handling in ftrtc010_rtc_probe Miaoqian Lin
  2022-04-19 22:55 ` Linus Walleij
@ 2022-05-19 10:11 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2022-05-19 10:11 UTC (permalink / raw)
  To: linux-arm-kernel, linux-rtc, linux-kernel, Miaoqian Lin,
	Linus Walleij, Alessandro Zummo, Hans Ulli Kroll

On Sun, 3 Apr 2022 05:49:12 +0000, Miaoqian Lin wrote:
> In the error handling path, the clk_prepare_enable() function
> call should be balanced by a corresponding 'clk_disable_unprepare()'
> call , as already done in the remove function.
> 
> clk_disable_unprepare calls clk_disable() and clk_unprepare().
> They will use IS_ERR_OR_NULL to check the argument.
> 
> [...]

Applied, thanks!

[1/1] rtc: ftrtc010: Fix error handling in ftrtc010_rtc_probe
      commit: b520cbe5be37b1b9b401c0b6ecbdae32575273db

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-05-19 10:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03  5:49 [PATCH] rtc: ftrtc010: Fix error handling in ftrtc010_rtc_probe Miaoqian Lin
2022-04-19 22:55 ` Linus Walleij
2022-05-19 10:11 ` 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).