rtc: da9063: fix access ordering error during RTC interrupt at system power on
authorSteve Twiss <stwiss.opensource@diasemi.com>
Tue, 8 Dec 2015 16:28:39 +0000 (16:28 +0000)
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>
Sun, 20 Dec 2015 12:39:29 +0000 (13:39 +0100)
commit77535acedc26627f16a1a39c1471f942689fe11e
treee266f91bdad8c50c71d6cb78e56fdbf422935139
parentf076ef44a44d02ed91543f820c14c2c7dff53716
rtc: da9063: fix access ordering error during RTC interrupt at system power on

This fix alters the ordering of the IRQ and device registrations in the RTC
driver probe function. This change will apply to the RTC driver that supports
both DA9063 and DA9062 PMICs.

A problem could occur with the existing RTC driver if:

A system is started from a cold boot using the PMIC RTC IRQ to initiate a
power on operation. For instance, if an RTC alarm is used to start a
platform from power off.
The existing driver IRQ is requested before the device has been properly
registered.
i.e.
    ret = devm_request_threaded_irq()
comes before
    rtc->rtc_dev = devm_rtc_device_register();

In this case, the interrupt can be called before the device has been
registered and the handler can be called immediately. The IRQ handler
da9063_alarm_event() contains the function call

    rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);

which in turn tries to access the unavailable rtc->rtc_dev.

The fix is to reorder the functions inside the RTC probe. The IRQ is
requested after the RTC device resource has been registered so that
get_irq_byname is the last thing to happen.

Signed-off-by: Steve Twiss <stwiss.opensource@diasemi.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
drivers/rtc/rtc-da9063.c