diff options
author | Matthias Brugger <matthias.bgg@gmail.com> | 2015-02-19 05:41:33 -0500 |
---|---|---|
committer | Daniel Lezcano <daniel.lezcano@linaro.org> | 2015-02-25 04:28:49 -0500 |
commit | d4a19eb3b15a4ba98f627182f48d5bc0cffae670 (patch) | |
tree | ba55b0edb3f786383a00f7700906ea455e141075 /drivers/clocksource/mtk_timer.c | |
parent | a8b1b9fc927400045fb7631d5b12093aaf5d939d (diff) |
clocksource: mtk: Fix race conditions in probe code
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
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Diffstat (limited to 'drivers/clocksource/mtk_timer.c')
-rw-r--r-- | drivers/clocksource/mtk_timer.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/clocksource/mtk_timer.c b/drivers/clocksource/mtk_timer.c index 32a3d25795d3..68ab42356d0e 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) | |||
224 | } | 224 | } |
225 | rate = clk_get_rate(clk); | 225 | rate = clk_get_rate(clk); |
226 | 226 | ||
227 | mtk_timer_global_reset(evt); | ||
228 | |||
227 | if (request_irq(evt->dev.irq, mtk_timer_interrupt, | 229 | if (request_irq(evt->dev.irq, mtk_timer_interrupt, |
228 | IRQF_TIMER | IRQF_IRQPOLL, "mtk_timer", evt)) { | 230 | IRQF_TIMER | IRQF_IRQPOLL, "mtk_timer", evt)) { |
229 | pr_warn("failed to setup irq %d\n", evt->dev.irq); | 231 | 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) | |||
232 | 234 | ||
233 | evt->ticks_per_jiffy = DIV_ROUND_UP(rate, HZ); | 235 | evt->ticks_per_jiffy = DIV_ROUND_UP(rate, HZ); |
234 | 236 | ||
235 | mtk_timer_global_reset(evt); | ||
236 | |||
237 | /* Configure clock source */ | 237 | /* Configure clock source */ |
238 | mtk_timer_setup(evt, GPT_CLK_SRC, TIMER_CTRL_OP_FREERUN); | 238 | mtk_timer_setup(evt, GPT_CLK_SRC, TIMER_CTRL_OP_FREERUN); |
239 | clocksource_mmio_init(evt->gpt_base + TIMER_CNT_REG(GPT_CLK_SRC), | 239 | 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) | |||
241 | 241 | ||
242 | /* Configure clock event */ | 242 | /* Configure clock event */ |
243 | mtk_timer_setup(evt, GPT_CLK_EVT, TIMER_CTRL_OP_REPEAT); | 243 | mtk_timer_setup(evt, GPT_CLK_EVT, TIMER_CTRL_OP_REPEAT); |
244 | mtk_timer_enable_irq(evt, GPT_CLK_EVT); | ||
245 | |||
246 | clockevents_config_and_register(&evt->dev, rate, 0x3, | 244 | clockevents_config_and_register(&evt->dev, rate, 0x3, |
247 | 0xffffffff); | 245 | 0xffffffff); |
246 | |||
247 | mtk_timer_enable_irq(evt, GPT_CLK_EVT); | ||
248 | |||
248 | return; | 249 | return; |
249 | 250 | ||
250 | err_clk_disable: | 251 | err_clk_disable: |