]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
rtc: xgene: fix possible race condition
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Wed, 20 Mar 2019 12:32:27 +0000 (13:32 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 13 Aug 2019 12:11:36 +0000 (14:11 +0200)
BugLink: https://bugs.launchpad.net/bugs/1837517
[ Upstream commit a652e00ee1233e251a337c28e18a1da59224e5ce ]

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 <alexandre.belloni@bootlin.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/rtc/rtc-xgene.c

index 153820876a820033cfebaf9cee45c5ae0162f8a6..2f741f455c30a9909706e25fe2a76d424cf66fb3 100644 (file)
@@ -168,6 +168,10 @@ static int xgene_rtc_probe(struct platform_device *pdev)
        if (IS_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);
        if (irq < 0) {
                dev_err(&pdev->dev, "No IRQ resource\n");
@@ -198,15 +202,15 @@ static int xgene_rtc_probe(struct platform_device *pdev)
                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 */
        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;
 }