aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorSteve Twiss <stwiss.opensource@diasemi.com>2015-12-08 11:28:39 -0500
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2015-12-20 07:39:29 -0500
commit77535acedc26627f16a1a39c1471f942689fe11e (patch)
treee266f91bdad8c50c71d6cb78e56fdbf422935139 /drivers/rtc
parentf076ef44a44d02ed91543f820c14c2c7dff53716 (diff)
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>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-da9063.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/drivers/rtc/rtc-da9063.c b/drivers/rtc/rtc-da9063.c
index 284b587da65c..d6c853bbfa9f 100644
--- a/drivers/rtc/rtc-da9063.c
+++ b/drivers/rtc/rtc-da9063.c
@@ -483,24 +483,23 @@ static int da9063_rtc_probe(struct platform_device *pdev)
483 483
484 platform_set_drvdata(pdev, rtc); 484 platform_set_drvdata(pdev, rtc);
485 485
486 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, DA9063_DRVNAME_RTC,
487 &da9063_rtc_ops, THIS_MODULE);
488 if (IS_ERR(rtc->rtc_dev))
489 return PTR_ERR(rtc->rtc_dev);
490
491 da9063_data_to_tm(data, &rtc->alarm_time, rtc);
492 rtc->rtc_sync = false;
493
486 irq_alarm = platform_get_irq_byname(pdev, "ALARM"); 494 irq_alarm = platform_get_irq_byname(pdev, "ALARM");
487 ret = devm_request_threaded_irq(&pdev->dev, irq_alarm, NULL, 495 ret = devm_request_threaded_irq(&pdev->dev, irq_alarm, NULL,
488 da9063_alarm_event, 496 da9063_alarm_event,
489 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 497 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
490 "ALARM", rtc); 498 "ALARM", rtc);
491 if (ret) { 499 if (ret)
492 dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n", 500 dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n",
493 irq_alarm, ret); 501 irq_alarm, ret);
494 return ret;
495 }
496
497 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, DA9063_DRVNAME_RTC,
498 &da9063_rtc_ops, THIS_MODULE);
499 if (IS_ERR(rtc->rtc_dev))
500 return PTR_ERR(rtc->rtc_dev);
501 502
502 da9063_data_to_tm(data, &rtc->alarm_time, rtc);
503 rtc->rtc_sync = false;
504 return ret; 503 return ret;
505} 504}
506 505