Commit 9cf4789e authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: 88pm860x: fix possible race condition

The RTC IRQ is 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 RTC IRQ using devm_rtc_allocate_device, and use rtc_register_device
to register the RTC device.

Also remove the unnecessary error message as the core already prints the
info.

Link: https://lore.kernel.org/r/20200311223956.51352-1-alexandre.belloni@bootlin.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 7863bd07
...@@ -336,6 +336,10 @@ static int pm860x_rtc_probe(struct platform_device *pdev) ...@@ -336,6 +336,10 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
info->dev = &pdev->dev; info->dev = &pdev->dev;
dev_set_drvdata(&pdev->dev, info); dev_set_drvdata(&pdev->dev, info);
info->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(info->rtc_dev))
return PTR_ERR(info->rtc_dev);
ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
rtc_update_handler, IRQF_ONESHOT, "rtc", rtc_update_handler, IRQF_ONESHOT, "rtc",
info); info);
...@@ -377,13 +381,11 @@ static int pm860x_rtc_probe(struct platform_device *pdev) ...@@ -377,13 +381,11 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
} }
} }
info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm860x-rtc", info->rtc_dev->ops = &pm860x_rtc_ops;
&pm860x_rtc_ops, THIS_MODULE);
ret = PTR_ERR(info->rtc_dev); ret = rtc_register_device(info->rtc_dev);
if (IS_ERR(info->rtc_dev)) { if (ret)
dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
return ret; return ret;
}
/* /*
* enable internal XO instead of internal 3.25MHz clock since it can * enable internal XO instead of internal 3.25MHz clock since it can
......
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