Commit 607f9578 authored by Anson Huang's avatar Anson Huang Committed by Greg Kroah-Hartman

rtc: snvs: fix possible race condition

[ Upstream commit 6fd4fe9b ]

The RTC IRQ is requested before the struct rtc_device is allocated,
this may lead to a NULL pointer dereference in 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.
Signed-off-by: default avatarAnson Huang <Anson.Huang@nxp.com>
Reviewed-by: default avatarDong Aisheng <aisheng.dong@nxp.com>
Link: https://lore.kernel.org/r/20190716071858.36750-1-Anson.Huang@nxp.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 07893754
...@@ -273,6 +273,10 @@ static int snvs_rtc_probe(struct platform_device *pdev) ...@@ -273,6 +273,10 @@ static int snvs_rtc_probe(struct platform_device *pdev)
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
data->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(data->rtc))
return PTR_ERR(data->rtc);
data->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "regmap"); data->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "regmap");
if (IS_ERR(data->regmap)) { if (IS_ERR(data->regmap)) {
...@@ -335,10 +339,9 @@ static int snvs_rtc_probe(struct platform_device *pdev) ...@@ -335,10 +339,9 @@ static int snvs_rtc_probe(struct platform_device *pdev)
goto error_rtc_device_register; goto error_rtc_device_register;
} }
data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, data->rtc->ops = &snvs_rtc_ops;
&snvs_rtc_ops, THIS_MODULE); ret = rtc_register_device(data->rtc);
if (IS_ERR(data->rtc)) { if (ret) {
ret = PTR_ERR(data->rtc);
dev_err(&pdev->dev, "failed to register rtc: %d\n", ret); dev_err(&pdev->dev, "failed to register rtc: %d\n", ret);
goto error_rtc_device_register; goto error_rtc_device_register;
} }
......
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