Commit 5490a1e0 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: mxc_v2: 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
before requesting the IRQ.
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent d7599245
...@@ -343,6 +343,12 @@ static int mxc_rtc_probe(struct platform_device *pdev) ...@@ -343,6 +343,12 @@ static int mxc_rtc_probe(struct platform_device *pdev)
return ret; return ret;
} }
pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(pdata->rtc))
return PTR_ERR(pdata->rtc);
pdata->rtc->ops = &mxc_rtc_ops;
clk_disable(pdata->clk); clk_disable(pdata->clk);
platform_set_drvdata(pdev, pdata); platform_set_drvdata(pdev, pdata);
ret = ret =
...@@ -354,15 +360,11 @@ static int mxc_rtc_probe(struct platform_device *pdev) ...@@ -354,15 +360,11 @@ static int mxc_rtc_probe(struct platform_device *pdev)
return ret; return ret;
} }
pdata->rtc = ret = rtc_register_device(pdata->rtc);
devm_rtc_device_register(&pdev->dev, pdev->name, &mxc_rtc_ops, if (ret < 0)
THIS_MODULE);
if (IS_ERR(pdata->rtc)) {
clk_unprepare(pdata->clk); clk_unprepare(pdata->clk);
return PTR_ERR(pdata->rtc);
}
return 0; return ret;
} }
static int mxc_rtc_remove(struct platform_device *pdev) static int mxc_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