linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clocksource: sun5i: fail gracefully when clock rate is unavailable
@ 2019-01-10  6:22 Chen-Yu Tsai
  2019-01-10  6:59 ` Maxime Ripard
  2019-01-10  9:19 ` Daniel Lezcano
  0 siblings, 2 replies; 7+ messages in thread
From: Chen-Yu Tsai @ 2019-01-10  6:22 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, Maxime Ripard
  Cc: Chen-Yu Tsai, linux-arm-kernel, linux-kernel

If the clock tree is not fully populated when the timer-sun5i init code
is called, attempts to get the clock rate for the timer would fail and
return 0.

Make the init code for both clock events and clocksource check the
returned clock rate and fail gracefully if the result is 0, instead of
causing a divide by 0 exception later on.

Fixes: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code")
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/clocksource/timer-sun5i.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c
index 3b56ea3f52af..552c5254390c 100644
--- a/drivers/clocksource/timer-sun5i.c
+++ b/drivers/clocksource/timer-sun5i.c
@@ -202,6 +202,11 @@ static int __init sun5i_setup_clocksource(struct device_node *node,
 	}
 
 	rate = clk_get_rate(clk);
+	if (!rate) {
+		pr_err("Couldn't get parent clock rate\n");
+		ret = -EINVAL;
+		goto err_disable_clk;
+	}
 
 	cs->timer.base = base;
 	cs->timer.clk = clk;
@@ -275,6 +280,11 @@ static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem
 	}
 
 	rate = clk_get_rate(clk);
+	if (!rate) {
+		pr_err("Couldn't get parent clock rate\n");
+		ret = -EINVAL;
+		goto err_disable_clk;
+	}
 
 	ce->timer.base = base;
 	ce->timer.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
-- 
2.20.1


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

* Re: [PATCH] clocksource: sun5i: fail gracefully when clock rate is unavailable
  2019-01-10  6:22 [PATCH] clocksource: sun5i: fail gracefully when clock rate is unavailable Chen-Yu Tsai
@ 2019-01-10  6:59 ` Maxime Ripard
  2019-01-10  9:19 ` Daniel Lezcano
  1 sibling, 0 replies; 7+ messages in thread
From: Maxime Ripard @ 2019-01-10  6:59 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Daniel Lezcano, Thomas Gleixner, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 714 bytes --]

On Thu, Jan 10, 2019 at 02:22:07PM +0800, Chen-Yu Tsai wrote:
> If the clock tree is not fully populated when the timer-sun5i init code
> is called, attempts to get the clock rate for the timer would fail and
> return 0.
> 
> Make the init code for both clock events and clocksource check the
> returned clock rate and fail gracefully if the result is 0, instead of
> causing a divide by 0 exception later on.
> 
> Fixes: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code")
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>

Thanks!
Maxime

-- 
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH] clocksource: sun5i: fail gracefully when clock rate is unavailable
  2019-01-10  6:22 [PATCH] clocksource: sun5i: fail gracefully when clock rate is unavailable Chen-Yu Tsai
  2019-01-10  6:59 ` Maxime Ripard
@ 2019-01-10  9:19 ` Daniel Lezcano
  2019-01-24  8:56   ` Chen-Yu Tsai
  1 sibling, 1 reply; 7+ messages in thread
From: Daniel Lezcano @ 2019-01-10  9:19 UTC (permalink / raw)
  To: Chen-Yu Tsai, Thomas Gleixner, Maxime Ripard
  Cc: linux-arm-kernel, linux-kernel

On 10/01/2019 07:22, Chen-Yu Tsai wrote:
> If the clock tree is not fully populated when the timer-sun5i init code
> is called, attempts to get the clock rate for the timer would fail and
> return 0.
> 
> Make the init code for both clock events and clocksource check the
> returned clock rate and fail gracefully if the result is 0, instead of
> causing a divide by 0 exception later on.
> 
> Fixes: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code")
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---

Applied thanks.
-- 
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


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

* Re: [PATCH] clocksource: sun5i: fail gracefully when clock rate is unavailable
  2019-01-10  9:19 ` Daniel Lezcano
@ 2019-01-24  8:56   ` Chen-Yu Tsai
  2019-01-24  9:38     ` Daniel Lezcano
  0 siblings, 1 reply; 7+ messages in thread
From: Chen-Yu Tsai @ 2019-01-24  8:56 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: Thomas Gleixner, Maxime Ripard, linux-arm-kernel, linux-kernel

On Thu, Jan 10, 2019 at 5:19 PM Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:
>
> On 10/01/2019 07:22, Chen-Yu Tsai wrote:
> > If the clock tree is not fully populated when the timer-sun5i init code
> > is called, attempts to get the clock rate for the timer would fail and
> > return 0.
> >
> > Make the init code for both clock events and clocksource check the
> > returned clock rate and fail gracefully if the result is 0, instead of
> > causing a divide by 0 exception later on.
> >
> > Fixes: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code")
> > Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> > ---
>
> Applied thanks.

I'm not seeing this in linux-next, nor the patch

    arm64: arch_timer: Workaround for Allwinner A64 timer instability

Any idea where these ended up?


Thanks
ChenYu

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

* Re: [PATCH] clocksource: sun5i: fail gracefully when clock rate is unavailable
  2019-01-24  8:56   ` Chen-Yu Tsai
@ 2019-01-24  9:38     ` Daniel Lezcano
  2019-01-24  9:59       ` linux-next not picking up latest clockevents/next Chen-Yu Tsai
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Lezcano @ 2019-01-24  9:38 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Thomas Gleixner, Maxime Ripard, linux-arm-kernel, linux-kernel

On 24/01/2019 09:56, Chen-Yu Tsai wrote:
> On Thu, Jan 10, 2019 at 5:19 PM Daniel Lezcano
> <daniel.lezcano@linaro.org> wrote:
>>
>> On 10/01/2019 07:22, Chen-Yu Tsai wrote:
>>> If the clock tree is not fully populated when the timer-sun5i init code
>>> is called, attempts to get the clock rate for the timer would fail and
>>> return 0.
>>>
>>> Make the init code for both clock events and clocksource check the
>>> returned clock rate and fail gracefully if the result is 0, instead of
>>> causing a divide by 0 exception later on.
>>>
>>> Fixes: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code")
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>> ---
>>
>> Applied thanks.
> 
> I'm not seeing this in linux-next, nor the patch
> 
>     arm64: arch_timer: Workaround for Allwinner A64 timer instability
> 
> Any idea where these ended up?

Yeah, I have a rough idea. They are now in linux-next via the
clockevents/next branch.




-- 
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


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

* linux-next not picking up latest clockevents/next
  2019-01-24  9:38     ` Daniel Lezcano
@ 2019-01-24  9:59       ` Chen-Yu Tsai
  2019-01-24 10:01         ` Daniel Lezcano
  0 siblings, 1 reply; 7+ messages in thread
From: Chen-Yu Tsai @ 2019-01-24  9:59 UTC (permalink / raw)
  To: Stephen Rothwell, Daniel Lezcano; +Cc: linux-kernel

On Thu, Jan 24, 2019 at 5:39 PM Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:
>
> On 24/01/2019 09:56, Chen-Yu Tsai wrote:
> > On Thu, Jan 10, 2019 at 5:19 PM Daniel Lezcano
> > <daniel.lezcano@linaro.org> wrote:
> >>
> >> On 10/01/2019 07:22, Chen-Yu Tsai wrote:
> >>> If the clock tree is not fully populated when the timer-sun5i init code
> >>> is called, attempts to get the clock rate for the timer would fail and
> >>> return 0.
> >>>
> >>> Make the init code for both clock events and clocksource check the
> >>> returned clock rate and fail gracefully if the result is 0, instead of
> >>> causing a divide by 0 exception later on.
> >>>
> >>> Fixes: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code")
> >>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> >>> ---
> >>
> >> Applied thanks.
> >
> > I'm not seeing this in linux-next, nor the patch
> >
> >     arm64: arch_timer: Workaround for Allwinner A64 timer instability
> >
> > Any idea where these ended up?
>
> Yeah, I have a rough idea. They are now in linux-next via the
> clockevents/next branch.

Thanks, Daniel.

Stephen,

Looks like linux-next is not picking up the latest clockevents/next.

The merge log for linux-next-20190124 shows:

    Merging clockevents/clockevents/next (bd2bcaa565a2 Merge branch
'clockevents/4.21' of
http://git.linaro.org/people/daniel.lezcano/linux into timers/core)
    $ git merge clockevents/clockevents/next

The merged clockevents/next looks outdated compared to

    http://git.linaro.org/people/daniel.lezcano/linux.git/log/?h=clockevents/next

Regards
ChenYu

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

* Re: linux-next not picking up latest clockevents/next
  2019-01-24  9:59       ` linux-next not picking up latest clockevents/next Chen-Yu Tsai
@ 2019-01-24 10:01         ` Daniel Lezcano
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Lezcano @ 2019-01-24 10:01 UTC (permalink / raw)
  To: Chen-Yu Tsai, Stephen Rothwell; +Cc: linux-kernel

On 24/01/2019 10:59, Chen-Yu Tsai wrote:
> On Thu, Jan 24, 2019 at 5:39 PM Daniel Lezcano
> <daniel.lezcano@linaro.org> wrote:
>>
>> On 24/01/2019 09:56, Chen-Yu Tsai wrote:
>>> On Thu, Jan 10, 2019 at 5:19 PM Daniel Lezcano
>>> <daniel.lezcano@linaro.org> wrote:
>>>>
>>>> On 10/01/2019 07:22, Chen-Yu Tsai wrote:
>>>>> If the clock tree is not fully populated when the timer-sun5i init code
>>>>> is called, attempts to get the clock rate for the timer would fail and
>>>>> return 0.
>>>>>
>>>>> Make the init code for both clock events and clocksource check the
>>>>> returned clock rate and fail gracefully if the result is 0, instead of
>>>>> causing a divide by 0 exception later on.
>>>>>
>>>>> Fixes: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code")
>>>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>>>> ---
>>>>
>>>> Applied thanks.
>>>
>>> I'm not seeing this in linux-next, nor the patch
>>>
>>>     arm64: arch_timer: Workaround for Allwinner A64 timer instability
>>>
>>> Any idea where these ended up?
>>
>> Yeah, I have a rough idea. They are now in linux-next via the
>> clockevents/next branch.
> 
> Thanks, Daniel.
> 
> Stephen,
> 
> Looks like linux-next is not picking up the latest clockevents/next.
> 
> The merge log for linux-next-20190124 shows:
> 
>     Merging clockevents/clockevents/next (bd2bcaa565a2 Merge branch
> 'clockevents/4.21' of
> http://git.linaro.org/people/daniel.lezcano/linux into timers/core)
>     $ git merge clockevents/clockevents/next
> 
> The merged clockevents/next looks outdated compared to
> 
>     http://git.linaro.org/people/daniel.lezcano/linux.git/log/?h=clockevents/next


I just updated the branch, so there will be a delay before it gets
reflected in linux-next.


-- 
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


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

end of thread, other threads:[~2019-01-24 10:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-10  6:22 [PATCH] clocksource: sun5i: fail gracefully when clock rate is unavailable Chen-Yu Tsai
2019-01-10  6:59 ` Maxime Ripard
2019-01-10  9:19 ` Daniel Lezcano
2019-01-24  8:56   ` Chen-Yu Tsai
2019-01-24  9:38     ` Daniel Lezcano
2019-01-24  9:59       ` linux-next not picking up latest clockevents/next Chen-Yu Tsai
2019-01-24 10:01         ` Daniel Lezcano

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