linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/7] rtc: xgene: fix possible race condition
@ 2019-03-20 12:32 Alexandre Belloni
  2019-03-20 12:32 ` [PATCH 2/7] rtc: xgene: set range Alexandre Belloni
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Alexandre Belloni @ 2019-03-20 12:32 UTC (permalink / raw)
  To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni

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>
---
 drivers/rtc/rtc-xgene.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/rtc/rtc-xgene.c b/drivers/rtc/rtc-xgene.c
index 153820876a82..2f741f455c30 100644
--- a/drivers/rtc/rtc-xgene.c
+++ b/drivers/rtc/rtc-xgene.c
@@ -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;
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-04-01  7:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-20 12:32 [PATCH 1/7] rtc: xgene: fix possible race condition Alexandre Belloni
2019-03-20 12:32 ` [PATCH 2/7] rtc: xgene: set range Alexandre Belloni
2019-03-20 12:32 ` [PATCH 3/7] rtc: xgene: convert to SPDX identifier Alexandre Belloni
2019-04-01  5:50   ` Mukesh Ojha
2019-04-01  7:56     ` Alexandre Belloni
2019-03-20 12:32 ` [PATCH 4/7] rtc: xgene: correct checkpatch issues Alexandre Belloni
2019-03-20 12:32 ` [PATCH 5/7] rtc: xgene: stop caching alarm_time Alexandre Belloni
2019-03-20 12:32 ` [PATCH 6/7] rtc: xgene: switch to rtc_time64_to_tm/rtc_tm_to_time64 Alexandre Belloni
2019-03-20 12:32 ` [PATCH 7/7] rtc: xgene: use .set_time Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).