Skip to content

Commit a652e00

Browse files
rtc: xgene: 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: Alexandre Belloni <[email protected]>
1 parent 540a11d commit a652e00

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

drivers/rtc/rtc-xgene.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ static int xgene_rtc_probe(struct platform_device *pdev)
168168
if (IS_ERR(pdata->csr_base))
169169
return PTR_ERR(pdata->csr_base);
170170

171+
pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
172+
if (IS_ERR(pdata->rtc))
173+
return PTR_ERR(pdata->rtc);
174+
171175
irq = platform_get_irq(pdev, 0);
172176
if (irq < 0) {
173177
dev_err(&pdev->dev, "No IRQ resource\n");
@@ -198,15 +202,15 @@ static int xgene_rtc_probe(struct platform_device *pdev)
198202
return ret;
199203
}
200204

201-
pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
202-
&xgene_rtc_ops, THIS_MODULE);
203-
if (IS_ERR(pdata->rtc)) {
204-
clk_disable_unprepare(pdata->clk);
205-
return PTR_ERR(pdata->rtc);
206-
}
207-
208205
/* HW does not support update faster than 1 seconds */
209206
pdata->rtc->uie_unsupported = 1;
207+
pdata->rtc->ops = &xgene_rtc_ops;
208+
209+
ret = rtc_register_device(pdata->rtc);
210+
if (ret) {
211+
clk_disable_unprepare(pdata->clk);
212+
return ret;
213+
}
210214

211215
return 0;
212216
}

0 commit comments

Comments
 (0)