aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@bootlin.com>2019-03-20 07:30:09 -0400
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2019-04-04 04:07:09 -0400
commit1097998d27da39578542e79ff865b4d74e755cd0 (patch)
treedbaf06cbb95fd81e353363c4a45c3bd8bb50f9c5
parent9852023d204b97324e7fa84f50f28a9d602b79fb (diff)
rtc: sh: 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. Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
-rw-r--r--drivers/rtc/rtc-sh.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 7fffe6da9478..d9e67ca4b7b9 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -530,6 +530,10 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
530 rtc->clk = NULL; 530 rtc->clk = NULL;
531 } 531 }
532 532
533 rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
534 if (IS_ERR(rtc->rtc_dev))
535 return PTR_ERR(rtc->rtc_dev);
536
533 clk_enable(rtc->clk); 537 clk_enable(rtc->clk);
534 538
535 rtc->capabilities = RTC_DEF_CAPABILITIES; 539 rtc->capabilities = RTC_DEF_CAPABILITIES;
@@ -593,15 +597,13 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
593 sh_rtc_setaie(&pdev->dev, 0); 597 sh_rtc_setaie(&pdev->dev, 0);
594 sh_rtc_setcie(&pdev->dev, 0); 598 sh_rtc_setcie(&pdev->dev, 0);
595 599
596 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "sh", 600 rtc->rtc_dev->ops = &sh_rtc_ops;
597 &sh_rtc_ops, THIS_MODULE);
598 if (IS_ERR(rtc->rtc_dev)) {
599 ret = PTR_ERR(rtc->rtc_dev);
600 goto err_unmap;
601 }
602
603 rtc->rtc_dev->max_user_freq = 256; 601 rtc->rtc_dev->max_user_freq = 256;
604 602
603 ret = rtc_register_device(rtc->rtc_dev);
604 if (ret)
605 goto err_unmap;
606
605 device_init_wakeup(&pdev->dev, 1); 607 device_init_wakeup(&pdev->dev, 1);
606 return 0; 608 return 0;
607 609