* [PATCH 1/1] rtc: use devm_clk_get_enabled() in mv_rtc_probe()
@ 2023-07-20 14:08 Yuanjun Gong
2023-08-10 8:17 ` Alexandre Belloni
0 siblings, 1 reply; 2+ messages in thread
From: Yuanjun Gong @ 2023-07-20 14:08 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, linux-rtc; +Cc: Yuanjun Gong
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);
/* 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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] rtc: use devm_clk_get_enabled() in mv_rtc_probe()
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
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2023-08-10 8:17 UTC (permalink / raw)
To: Yuanjun Gong; +Cc: Alessandro Zummo, linux-rtc
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-10 8:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).