null pointer dereference error in timer-sun5i.c

From: ëìë
Date: Mon Feb 16 2015 - 03:20:48 EST

Hello. My name is Yongbae Park.

I would like to report a possible null pointer dereference error at
sun5i_timer_interrupt() in drivers/clocksource/timer-sun5i.c (version:
3.19-rc5). The null pointer dereference error occurs if the interrupt
handler sun5i_timer_interrupt() accesses evt->event_handler (line 128)
when evt->event_handler is null and not defined by sun5i_timer_init().

sun5i_timer_init() first registers sun5i_timer_interrupt() as the
interrupt handler at line 181, and then defines the clockevent handler
at line 192. As a consequence, the interrupt handler can be executed
before the clockevent handler definition when an interrupt occurs
between line 181 and line 192. The detail error scenario is the

145: static void __init sun5i_timer_init(struct device_node *node) {
181: ret = setup_irq(irq, &sun5i_timer_irq);d
------ An interrupt is fired and the interrupt handler is called -------
123: static irqreturn_t sun5i_timer_interrupt(int irq, void *dev_id)
124: {
125: struct clock_event_device *evt = (struct clock_event_device *)dev_id;
127: writel(0x1, timer_base + TIMER_IRQ_ST_REG);
128: evt->event_handler(evt); // evt->event_handler is not defined
130: return IRQ_HANDLED;
131: }
------ The execution of the interrupt handler is finished ------
192: clockevents_config_and_register(&sun5i_clockevent, rate,
193: TIMER_SYNC_TICKS, 0xffffffff);

To resolve the problem, I think that the interrupt handler should be
registered after the clock handler registration.

For your information, I give you the references to similar issues from
the previous bug reports:

Thank you.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at