Commit e934a66d authored by Alexandre Belloni's avatar Alexandre Belloni Committed by Greg Kroah-Hartman

rtc: sa1100: fix possible race condition

[ Upstream commit f2997775 ]

Both RTC IRQs are requested before the struct rtc_device is allocated,
this may lead to a NULL pointer dereference in the IRQ handler.

To fix this issue, allocating the rtc_device struct before requesting
the IRQs using devm_rtc_allocate_device, and use rtc_register_device
to register the RTC device.

Link: https://lore.kernel.org/r/20200306010146.39762-1-alexandre.belloni@bootlin.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent abc5b427
...@@ -186,7 +186,6 @@ static const struct rtc_class_ops sa1100_rtc_ops = { ...@@ -186,7 +186,6 @@ static const struct rtc_class_ops sa1100_rtc_ops = {
int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info) int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info)
{ {
struct rtc_device *rtc;
int ret; int ret;
spin_lock_init(&info->lock); spin_lock_init(&info->lock);
...@@ -215,15 +214,14 @@ int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info) ...@@ -215,15 +214,14 @@ int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info)
writel_relaxed(0, info->rcnr); writel_relaxed(0, info->rcnr);
} }
rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops, info->rtc->ops = &sa1100_rtc_ops;
THIS_MODULE); info->rtc->max_user_freq = RTC_FREQ;
if (IS_ERR(rtc)) {
ret = rtc_register_device(info->rtc);
if (ret) {
clk_disable_unprepare(info->clk); clk_disable_unprepare(info->clk);
return PTR_ERR(rtc); return ret;
} }
info->rtc = rtc;
rtc->max_user_freq = RTC_FREQ;
/* Fix for a nasty initialization problem the in SA11xx RTSR register. /* Fix for a nasty initialization problem the in SA11xx RTSR register.
* See also the comments in sa1100_rtc_interrupt(). * See also the comments in sa1100_rtc_interrupt().
...@@ -272,6 +270,10 @@ static int sa1100_rtc_probe(struct platform_device *pdev) ...@@ -272,6 +270,10 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
info->irq_1hz = irq_1hz; info->irq_1hz = irq_1hz;
info->irq_alarm = irq_alarm; info->irq_alarm = irq_alarm;
info->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(info->rtc))
return PTR_ERR(info->rtc);
ret = devm_request_irq(&pdev->dev, irq_1hz, sa1100_rtc_interrupt, 0, ret = devm_request_irq(&pdev->dev, irq_1hz, sa1100_rtc_interrupt, 0,
"rtc 1Hz", &pdev->dev); "rtc 1Hz", &pdev->dev);
if (ret) { if (ret) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment