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

rtc: xgene: fix possible race condition

[ Upstream commit a652e00e ]

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>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 335e7c03
...@@ -168,6 +168,10 @@ static int xgene_rtc_probe(struct platform_device *pdev) ...@@ -168,6 +168,10 @@ static int xgene_rtc_probe(struct platform_device *pdev)
if (IS_ERR(pdata->csr_base)) if (IS_ERR(pdata->csr_base))
return PTR_ERR(pdata->csr_base); return PTR_ERR(pdata->csr_base);
pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(pdata->rtc))
return PTR_ERR(pdata->rtc);
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
dev_err(&pdev->dev, "No IRQ resource\n"); dev_err(&pdev->dev, "No IRQ resource\n");
...@@ -198,15 +202,15 @@ static int xgene_rtc_probe(struct platform_device *pdev) ...@@ -198,15 +202,15 @@ static int xgene_rtc_probe(struct platform_device *pdev)
return ret; return ret;
} }
pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&xgene_rtc_ops, THIS_MODULE);
if (IS_ERR(pdata->rtc)) {
clk_disable_unprepare(pdata->clk);
return PTR_ERR(pdata->rtc);
}
/* HW does not support update faster than 1 seconds */ /* HW does not support update faster than 1 seconds */
pdata->rtc->uie_unsupported = 1; pdata->rtc->uie_unsupported = 1;
pdata->rtc->ops = &xgene_rtc_ops;
ret = rtc_register_device(pdata->rtc);
if (ret) {
clk_disable_unprepare(pdata->clk);
return ret;
}
return 0; return 0;
} }
......
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