>>From 67329417c32b6e4f9f0253fe1976d8cb2ca67996 Mon Sep 17 00:00:00 2001 From: Stefan Bader Date: Tue, 3 Jan 2012 17:53:14 +0100 Subject: [PATCH] rtc: Delay calling rtc_initialize_alarm Commit 93b2ec0128c431148b216b8f7337c1a52131ef03 added a schedule_work call to rtc_initialize_alarm. However this seems to be called before having completed the setup. At least running under Xen, I could see the following crash: BUG: unable to handle kernel NULL pointer dereference at 00000294 IP: [] queue_work_on+0x13/0x40 ... Call Trace: [] queue_work+0x1a/0x20 [] schedule_work+0x14/0x20 [] rtc_update_irq+0x12/0x20 [] cmos_checkintr.isra.2+0x5c/0x70 [] cmos_irq_disable+0x4a/0x60 [] cmos_set_alarm+0xdc/0x190 [] __rtc_set_alarm+0x87/0xa0 [] rtc_timer_do_work+0x160/0x200 [] process_one_work+0x101/0x3a0 [] worker_thread+0x124/0x2d0 [] kthread+0x6d/0x80 Moving the call farther down the function seems like avoiding this. That still may be only because the timing is better, but on the other hand it sounds better to run any handler really after all the setup is complete. Signed-off-by: Stefan Bader Cc: stable@vger.kernel.org --- drivers/rtc/class.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index dc4c274..28b8b44 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -181,12 +181,6 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, rtc->pie_timer.function = rtc_pie_update_irq; rtc->pie_enabled = 0; - /* Check to see if there is an ALARM already set in hw */ - err = __rtc_read_alarm(rtc, &alrm); - - if (!err && !rtc_valid_tm(&alrm.time)) - rtc_initialize_alarm(rtc, &alrm); - strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); dev_set_name(&rtc->dev, "rtc%d", id); @@ -202,6 +196,12 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, rtc_sysfs_add_device(rtc); rtc_proc_add_device(rtc); + /* Check to see if there is an ALARM already set in hw */ + err = __rtc_read_alarm(rtc, &alrm); + + if (!err && !rtc_valid_tm(&alrm.time)) + rtc_initialize_alarm(rtc, &alrm); + dev_info(dev, "rtc core: registered %s as %s\n", rtc->name, dev_name(&rtc->dev)); -- 1.7.5.4