* [PATCH] clocksource: mtk: Fix race conditions in probe code
@ 2015-02-19 10:41 Matthias Brugger
2015-02-24 7:16 ` Daniel Lezcano
0 siblings, 1 reply; 2+ messages in thread
From: Matthias Brugger @ 2015-02-19 10:41 UTC (permalink / raw)
To: daniel.lezcano, tglx, matthias.bgg
Cc: yongbae2, linux-kernel, linux-arm-kernel, linux-mediatek, stable
We have two race conditions in the probe code which could lead to a null
pointer dereference in the interrupt handler.
The interrupt handler accesses the clockevent device, which may not yet be
registered.
First race condition happens when the interrupt handler gets registered before
the interrupts get disabled. The second race condition happens when the
interrupts get enabled, but the clockevent device is not yet registered.
Fix that by disabling the interrupts before we register the interrupt and enable
the interrupts after the clockevent device got registered.
Reported-by: Gongbae Park <yongbae2@gmail.com>
Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Cc: stable@vger.kernel.org
---
drivers/clocksource/mtk_timer.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/clocksource/mtk_timer.c b/drivers/clocksource/mtk_timer.c
index 32a3d25..68ab423 100644
--- a/drivers/clocksource/mtk_timer.c
+++ b/drivers/clocksource/mtk_timer.c
@@ -224,6 +224,8 @@ static void __init mtk_timer_init(struct device_node *node)
}
rate = clk_get_rate(clk);
+ mtk_timer_global_reset(evt);
+
if (request_irq(evt->dev.irq, mtk_timer_interrupt,
IRQF_TIMER | IRQF_IRQPOLL, "mtk_timer", evt)) {
pr_warn("failed to setup irq %d\n", evt->dev.irq);
@@ -232,8 +234,6 @@ static void __init mtk_timer_init(struct device_node *node)
evt->ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
- mtk_timer_global_reset(evt);
-
/* Configure clock source */
mtk_timer_setup(evt, GPT_CLK_SRC, TIMER_CTRL_OP_FREERUN);
clocksource_mmio_init(evt->gpt_base + TIMER_CNT_REG(GPT_CLK_SRC),
@@ -241,10 +241,11 @@ static void __init mtk_timer_init(struct device_node *node)
/* Configure clock event */
mtk_timer_setup(evt, GPT_CLK_EVT, TIMER_CTRL_OP_REPEAT);
- mtk_timer_enable_irq(evt, GPT_CLK_EVT);
-
clockevents_config_and_register(&evt->dev, rate, 0x3,
0xffffffff);
+
+ mtk_timer_enable_irq(evt, GPT_CLK_EVT);
+
return;
err_clk_disable:
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] clocksource: mtk: Fix race conditions in probe code
2015-02-19 10:41 [PATCH] clocksource: mtk: Fix race conditions in probe code Matthias Brugger
@ 2015-02-24 7:16 ` Daniel Lezcano
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Lezcano @ 2015-02-24 7:16 UTC (permalink / raw)
To: Matthias Brugger, tglx
Cc: yongbae2, linux-kernel, linux-arm-kernel, linux-mediatek, stable
On 02/19/2015 11:41 AM, Matthias Brugger wrote:
> We have two race conditions in the probe code which could lead to a null
> pointer dereference in the interrupt handler.
>
> The interrupt handler accesses the clockevent device, which may not yet be
> registered.
>
> First race condition happens when the interrupt handler gets registered before
> the interrupts get disabled. The second race condition happens when the
> interrupts get enabled, but the clockevent device is not yet registered.
>
> Fix that by disabling the interrupts before we register the interrupt and enable
> the interrupts after the clockevent device got registered.
>
> Reported-by: Gongbae Park <yongbae2@gmail.com>
> Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: stable@vger.kernel.org
> ---
Applied to my tree as a fix for 3.20.
Thanks !
-- Daniel
--
<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] 2+ messages in thread
end of thread, other threads:[~2015-02-24 7:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-19 10:41 [PATCH] clocksource: mtk: Fix race conditions in probe code Matthias Brugger
2015-02-24 7:16 ` Daniel Lezcano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox