Skip to content

Commit 6bab4a8

Browse files
mriparddlezcano
authored andcommitted
clockevent: sun4i: Fix race condition in the probe code
The interrupts were activated and the handler registered before the clockevent was registered in the probe function. The interrupt handler, however, was making the assumption that the clockevent device was registered. That could cause a null pointer dereference if the timer interrupt was firing during this narrow window. Fix that by moving the clockevent registration before the interrupt is enabled. Reported-by: Roman Byshko <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Cc: [email protected] Signed-off-by: Daniel Lezcano <[email protected]>
1 parent 59aa896 commit 6bab4a8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/clocksource/sun4i_timer.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,19 @@ static void __init sun4i_timer_init(struct device_node *node)
182182
/* Make sure timer is stopped before playing with interrupts */
183183
sun4i_clkevt_time_stop(0);
184184

185+
sun4i_clockevent.cpumask = cpu_possible_mask;
186+
sun4i_clockevent.irq = irq;
187+
188+
clockevents_config_and_register(&sun4i_clockevent, rate,
189+
TIMER_SYNC_TICKS, 0xffffffff);
190+
185191
ret = setup_irq(irq, &sun4i_timer_irq);
186192
if (ret)
187193
pr_warn("failed to setup irq %d\n", irq);
188194

189195
/* Enable timer0 interrupt */
190196
val = readl(timer_base + TIMER_IRQ_EN_REG);
191197
writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG);
192-
193-
sun4i_clockevent.cpumask = cpu_possible_mask;
194-
sun4i_clockevent.irq = irq;
195-
196-
clockevents_config_and_register(&sun4i_clockevent, rate,
197-
TIMER_SYNC_TICKS, 0xffffffff);
198198
}
199199
CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer",
200200
sun4i_timer_init);

0 commit comments

Comments
 (0)