From ffe60fcfda98a3e4f51bc1e02ff5412a7e1c9c79 Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Tue, 28 Jul 2015 21:46:15 +0200 Subject: rtc: at91sam9: properly handle error case In case of a probe error, it is possible to abort after issuing clk_prepare_enable(). Ensure the clock is disabled and unprepared in that case. Signed-off-by: Alexandre Belloni Acked-by: Boris Brezillon Acked-by: Nicolas Ferre --- drivers/rtc/rtc-at91sam9.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'drivers/rtc/rtc-at91sam9.c') diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 5ccaee32df72..152cd816cc43 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c @@ -451,8 +451,10 @@ static int at91_rtc_probe(struct platform_device *pdev) rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name, &at91_rtc_ops, THIS_MODULE); - if (IS_ERR(rtc->rtcdev)) - return PTR_ERR(rtc->rtcdev); + if (IS_ERR(rtc->rtcdev)) { + ret = PTR_ERR(rtc->rtcdev); + goto err_clk; + } /* register irq handler after we know what name we'll use */ ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt, @@ -460,7 +462,7 @@ static int at91_rtc_probe(struct platform_device *pdev) dev_name(&rtc->rtcdev->dev), rtc); if (ret) { dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq); - return ret; + goto err_clk; } /* NOTE: sam9260 rev A silicon has a ROM bug which resets the @@ -474,6 +476,11 @@ static int at91_rtc_probe(struct platform_device *pdev) dev_name(&rtc->rtcdev->dev)); return 0; + +err_clk: + clk_disable_unprepare(rtc->sclk); + + return ret; } /* -- cgit v1.2.3 From 73ab31ce1bbc64c590b2a2d58364942adfa11a3f Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Tue, 28 Jul 2015 21:47:57 +0200 Subject: rtc: at91sam9: remove useless check rtc->sclk necessarily points to a valid clocks at this point. Else the probe would have aborted. Signed-off-by: Alexandre Belloni Acked-by: Boris Brezillon Acked-by: Nicolas Ferre --- drivers/rtc/rtc-at91sam9.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/rtc/rtc-at91sam9.c') diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 152cd816cc43..0a8485ac3864 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c @@ -494,8 +494,7 @@ static int at91_rtc_remove(struct platform_device *pdev) /* disable all interrupts */ rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)); - if (!IS_ERR(rtc->sclk)) - clk_disable_unprepare(rtc->sclk); + clk_disable_unprepare(rtc->sclk); return 0; } -- cgit v1.2.3 From 6932ff5395e3a2541fba696b38dc71393cf7ce57 Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Tue, 28 Jul 2015 21:49:24 +0200 Subject: rtc: at91sam9: sort headers alphabetically Sort included headers alphabetically. Signed-off-by: Alexandre Belloni Acked-by: Boris Brezillon Acked-by: Nicolas Ferre --- drivers/rtc/rtc-at91sam9.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers/rtc/rtc-at91sam9.c') diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 0a8485ac3864..23f721d049b2 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c @@ -11,20 +11,20 @@ * 2 of the License, or (at your option) any later version. */ -#include -#include -#include -#include -#include +#include #include #include -#include -#include #include +#include #include +#include +#include +#include #include +#include +#include #include -#include +#include /* * This driver uses two configurable hardware resources that live in the -- cgit v1.2.3 From 8918bd8a5f6c37963ba04ae79ad6488108894ab9 Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Tue, 28 Jul 2015 21:51:10 +0200 Subject: rtc: at91sam9: get sclk rate after enabling it See help for clk_get_rate(): "obtain the current clock rate (in Hz) for a clock source. This is only valid once the clock source has been enabled." It currently returns the correct value but that may not stay that way. Signed-off-by: Alexandre Belloni Acked-by: Boris Brezillon Acked-by: Nicolas Ferre --- drivers/rtc/rtc-at91sam9.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'drivers/rtc/rtc-at91sam9.c') diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 23f721d049b2..f9e85ace5e71 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c @@ -425,18 +425,19 @@ static int at91_rtc_probe(struct platform_device *pdev) if (IS_ERR(rtc->sclk)) return PTR_ERR(rtc->sclk); - sclk_rate = clk_get_rate(rtc->sclk); - if (!sclk_rate || sclk_rate > AT91_RTT_RTPRES) { - dev_err(&pdev->dev, "Invalid slow clock rate\n"); - return -EINVAL; - } - ret = clk_prepare_enable(rtc->sclk); if (ret) { dev_err(&pdev->dev, "Could not enable slow clock\n"); return ret; } + sclk_rate = clk_get_rate(rtc->sclk); + if (!sclk_rate || sclk_rate > AT91_RTT_RTPRES) { + dev_err(&pdev->dev, "Invalid slow clock rate\n"); + ret = -EINVAL; + goto err_clk; + } + mr = rtt_readl(rtc, MR); /* unless RTT is counting at 1 Hz, re-initialize it */ -- cgit v1.2.3 From 1955f213a68323f7348fc06461017c7675efe6c1 Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Mon, 10 Aug 2015 16:33:39 +0200 Subject: rtc: at91sam9: include linux/of.h This driver is using device tree but is not including of.h Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-at91sam9.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/rtc/rtc-at91sam9.c') diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index f9e85ace5e71..16492e2baf5e 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3 From 80e274e96e5bc4ddf9ee4b31ab6f4a2a9fa08040 Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Mon, 10 Aug 2015 16:33:40 +0200 Subject: rtc: at91sam9: remove useless include Definitions from linux/platform_data/atmel.h are not used, remove the include. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-at91sam9.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/rtc/rtc-at91sam9.c') diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index 16492e2baf5e..7206e2fa4383 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3