Commit e6000a43 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: tps65910: fix possible race condition

The IRQ is requested before the struct rtc is allocated and registered, but
this struct is used in the IRQ handler. This may lead to a NULL pointer
dereference.

Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
before requesting the IRQ.
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent c402f8ea
...@@ -380,6 +380,10 @@ static int tps65910_rtc_probe(struct platform_device *pdev) ...@@ -380,6 +380,10 @@ static int tps65910_rtc_probe(struct platform_device *pdev)
if (!tps_rtc) if (!tps_rtc)
return -ENOMEM; return -ENOMEM;
tps_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(tps_rtc->rtc))
return PTR_ERR(tps_rtc->rtc);
/* Clear pending interrupts */ /* Clear pending interrupts */
ret = regmap_read(tps65910->regmap, TPS65910_RTC_STATUS, &rtc_reg); ret = regmap_read(tps65910->regmap, TPS65910_RTC_STATUS, &rtc_reg);
if (ret < 0) if (ret < 0)
...@@ -421,10 +425,10 @@ static int tps65910_rtc_probe(struct platform_device *pdev) ...@@ -421,10 +425,10 @@ static int tps65910_rtc_probe(struct platform_device *pdev)
tps_rtc->irq = irq; tps_rtc->irq = irq;
device_set_wakeup_capable(&pdev->dev, 1); device_set_wakeup_capable(&pdev->dev, 1);
tps_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, tps_rtc->rtc->ops = &tps65910_rtc_ops;
&tps65910_rtc_ops, THIS_MODULE);
if (IS_ERR(tps_rtc->rtc)) { ret = rtc_register_device(tps_rtc->rtc);
ret = PTR_ERR(tps_rtc->rtc); if (ret) {
dev_err(&pdev->dev, "RTC device register: err %d\n", ret); dev_err(&pdev->dev, "RTC device register: err %d\n", ret);
return ret; return 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