Skip to content

Commit

Permalink
clocksource: mtk: Fix race conditions in probe code
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Matthias Brugger authored and Daniel Lezcano committed Feb 25, 2015
1 parent a8b1b9f commit d4a19eb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/clocksource/mtk_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -232,19 +234,18 @@ 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),
node->name, rate, 300, 32, clocksource_mmio_readl_up);

/* 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:
Expand Down

0 comments on commit d4a19eb

Please sign in to comment.