* [PATCH] clk: allow clocks without parents to change rate
@ 2012-07-04 22:09 Linus Walleij
2012-07-11 23:42 ` Mike Turquette
0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2012-07-04 22:09 UTC (permalink / raw)
To: linux-arm-kernel
The clk_change_rate() code would dereference clk->parent
to get clk->parent->rate without first checking that clk->parent
was valid. This doesn't work if the clock is (A) a root clock
and (B) can change rate. Such is the case with a VCO clock
like the ICST which consequently crash like this without
this patch:
Unable to handle kernel NULL pointer dereference at virtual address 0000001c
pgd = c0004000
[0000001c] *pgd=00000000
Internal error: Oops: 5 [#1] PREEMPT ARM
Modules linked in:
CPU: 0 Not tainted (3.5.0-rc3-00003-g8156866-dirty #193)
PC is at clk_change_rate+0x34/0xd8
LR is at clk_change_rate+0x18/0xd8
Cc: stable at kernel.org
Cc: Mike Turquette <mturquette@linaro.org>
Cc: Ulf Hansson <ulf.hansson@stericsson.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/clk/clk.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 687b00d..032d79c 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -854,14 +854,22 @@ static void clk_change_rate(struct clk *clk)
old_rate = clk->rate;
- if (clk->ops->set_rate)
- clk->ops->set_rate(clk->hw, clk->new_rate, clk->parent->rate);
+ if (clk->ops->set_rate) {
+ if (clk->parent)
+ clk->ops->set_rate(clk->hw, clk->new_rate,
+ clk->parent->rate);
+ else
+ clk->ops->set_rate(clk->hw, clk->new_rate, 0);
+ }
- if (clk->ops->recalc_rate)
- clk->rate = clk->ops->recalc_rate(clk->hw,
- clk->parent->rate);
- else
- clk->rate = clk->parent->rate;
+ if (clk->ops->recalc_rate) {
+ if (clk->parent)
+ clk->rate = clk->ops->recalc_rate(clk->hw,
+ clk->parent->rate);
+ else
+ clk->rate = clk->ops->recalc_rate(clk->hw, 0);
+ } else
+ clk->rate = clk->parent ? clk->parent->rate : 0;
if (clk->notifier_count && old_rate != clk->rate)
__clk_notify(clk, POST_RATE_CHANGE, old_rate, clk->rate);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] clk: allow clocks without parents to change rate
2012-07-04 22:09 [PATCH] clk: allow clocks without parents to change rate Linus Walleij
@ 2012-07-11 23:42 ` Mike Turquette
2012-07-12 10:50 ` Linus Walleij
0 siblings, 1 reply; 4+ messages in thread
From: Mike Turquette @ 2012-07-11 23:42 UTC (permalink / raw)
To: linux-arm-kernel
On 20120705-00:09, Linus Walleij wrote:
> The clk_change_rate() code would dereference clk->parent
> to get clk->parent->rate without first checking that clk->parent
> was valid. This doesn't work if the clock is (A) a root clock
> and (B) can change rate. Such is the case with a VCO clock
> like the ICST which consequently crash like this without
> this patch:
>
> Unable to handle kernel NULL pointer dereference at virtual address 0000001c
> pgd = c0004000
> [0000001c] *pgd=00000000
> Internal error: Oops: 5 [#1] PREEMPT ARM
> Modules linked in:
> CPU: 0 Not tainted (3.5.0-rc3-00003-g8156866-dirty #193)
> PC is at clk_change_rate+0x34/0xd8
> LR is at clk_change_rate+0x18/0xd8
>
> Cc: stable at kernel.org
> Cc: Mike Turquette <mturquette@linaro.org>
> Cc: Ulf Hansson <ulf.hansson@stericsson.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Hi Linus,
This has been fixed in Pawell's patch, "clk: Check parent for NULL in
clk_change_rate".
Thanks,
Mike
> ---
> drivers/clk/clk.c | 22 +++++++++++++++-------
> 1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 687b00d..032d79c 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -854,14 +854,22 @@ static void clk_change_rate(struct clk *clk)
>
> old_rate = clk->rate;
>
> - if (clk->ops->set_rate)
> - clk->ops->set_rate(clk->hw, clk->new_rate, clk->parent->rate);
> + if (clk->ops->set_rate) {
> + if (clk->parent)
> + clk->ops->set_rate(clk->hw, clk->new_rate,
> + clk->parent->rate);
> + else
> + clk->ops->set_rate(clk->hw, clk->new_rate, 0);
> + }
>
> - if (clk->ops->recalc_rate)
> - clk->rate = clk->ops->recalc_rate(clk->hw,
> - clk->parent->rate);
> - else
> - clk->rate = clk->parent->rate;
> + if (clk->ops->recalc_rate) {
> + if (clk->parent)
> + clk->rate = clk->ops->recalc_rate(clk->hw,
> + clk->parent->rate);
> + else
> + clk->rate = clk->ops->recalc_rate(clk->hw, 0);
> + } else
> + clk->rate = clk->parent ? clk->parent->rate : 0;
>
> if (clk->notifier_count && old_rate != clk->rate)
> __clk_notify(clk, POST_RATE_CHANGE, old_rate, clk->rate);
> --
> 1.7.10.4
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] clk: allow clocks without parents to change rate
2012-07-11 23:42 ` Mike Turquette
@ 2012-07-12 10:50 ` Linus Walleij
2012-07-12 16:54 ` Mike Turquette
0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2012-07-12 10:50 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Jul 12, 2012 at 1:42 AM, Mike Turquette <mturquette@ti.com> wrote:
> This has been fixed in Pawell's patch, "clk: Check parent for NULL in
> clk_change_rate".
Yes, that'll probably work.
A small nitpick though:
I have slightly different semantics, Pawel's patch assigns zero if
parent is NULL, then use that as fallback, whereas I check for the
parent being NULL all the way. I was worried that the old sematics
could change like this:
So here it takes that:
+ if (clk->parent)
+ best_parent_rate = clk->parent->rate;
+
And I was cautious that if this changes the parent rate:
+ clk->ops->set_rate(clk->hw, clk->new_rate, best_parent_rate);
Then this passes the old parent rate to the recalc function:
+ clk->rate = clk->ops->recalc_rate(clk->hw, best_parent_rate);
It has no side-effects on my system but I worried about
others, so I just left the behaviour to re-read the rate from the parent
every time if possible.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] clk: allow clocks without parents to change rate
2012-07-12 10:50 ` Linus Walleij
@ 2012-07-12 16:54 ` Mike Turquette
0 siblings, 0 replies; 4+ messages in thread
From: Mike Turquette @ 2012-07-12 16:54 UTC (permalink / raw)
To: linux-arm-kernel
On 20120712-12:50, Linus Walleij wrote:
> On Thu, Jul 12, 2012 at 1:42 AM, Mike Turquette <mturquette@ti.com> wrote:
>
> > This has been fixed in Pawell's patch, "clk: Check parent for NULL in
> > clk_change_rate".
>
> Yes, that'll probably work.
>
> A small nitpick though:
>
> I have slightly different semantics, Pawel's patch assigns zero if
> parent is NULL, then use that as fallback, whereas I check for the
> parent being NULL all the way. I was worried that the old sematics
> could change like this:
>
> So here it takes that:
>
> + if (clk->parent)
> + best_parent_rate = clk->parent->rate;
> +
>
> And I was cautious that if this changes the parent rate:
>
> + clk->ops->set_rate(clk->hw, clk->new_rate, best_parent_rate);
>
> Then this passes the old parent rate to the recalc function:
>
> + clk->rate = clk->ops->recalc_rate(clk->hw, best_parent_rate);
>
> It has no side-effects on my system but I worried about
> others, so I just left the behaviour to re-read the rate from the parent
> every time if possible.
>
Thanks for looking into it. I think for now let's keep what we have and
we'll patch it up if bugs are reported.
Thanks again,
Mike
> Yours,
> Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-07-12 16:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-04 22:09 [PATCH] clk: allow clocks without parents to change rate Linus Walleij
2012-07-11 23:42 ` Mike Turquette
2012-07-12 10:50 ` Linus Walleij
2012-07-12 16:54 ` Mike Turquette
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).