Commit b8541798 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: zynqmp: 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
struct before requesting the IRQ.
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 30adde6b
...@@ -222,6 +222,12 @@ static int xlnx_rtc_probe(struct platform_device *pdev) ...@@ -222,6 +222,12 @@ static int xlnx_rtc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, xrtcdev); platform_set_drvdata(pdev, xrtcdev);
xrtcdev->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(xrtcdev->rtc))
return PTR_ERR(xrtcdev->rtc);
xrtcdev->rtc->ops = &xlnx_rtc_ops;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
xrtcdev->reg_base = devm_ioremap_resource(&pdev->dev, res); xrtcdev->reg_base = devm_ioremap_resource(&pdev->dev, res);
...@@ -263,9 +269,7 @@ static int xlnx_rtc_probe(struct platform_device *pdev) ...@@ -263,9 +269,7 @@ static int xlnx_rtc_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
xrtcdev->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, return rtc_register_device(xrtcdev->rtc);
&xlnx_rtc_ops, THIS_MODULE);
return PTR_ERR_OR_ZERO(xrtcdev->rtc);
} }
static int xlnx_rtc_remove(struct platform_device *pdev) static int xlnx_rtc_remove(struct platform_device *pdev)
......
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