From: Alexandre Belloni <alexandre.belloni@bootlin.com> To: linux-rtc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Patrice Chotard <patrice.chotard@st.com>, linux-arm-kernel@lists.infradead.org, Alexandre Belloni <alexandre.belloni@bootlin.com> Subject: [PATCH 1/2] rtc: st-lpc: fix possible race condition Date: Sun, 20 May 2018 14:33:36 +0200 [thread overview] Message-ID: <20180520123337.14856-1-alexandre.belloni@bootlin.com> (raw) 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: Alexandre Belloni <alexandre.belloni@bootlin.com> --- drivers/rtc/rtc-st-lpc.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c index d5222667f892..2f1ef2c28740 100644 --- a/drivers/rtc/rtc-st-lpc.c +++ b/drivers/rtc/rtc-st-lpc.c @@ -212,6 +212,10 @@ static int st_rtc_probe(struct platform_device *pdev) if (!rtc) return -ENOMEM; + rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(rtc->rtc_dev)) + return PTR_ERR(rtc->rtc_dev); + spin_lock_init(&rtc->lock); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -253,26 +257,17 @@ static int st_rtc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rtc); - rtc->rtc_dev = rtc_device_register("st-lpc-rtc", &pdev->dev, - &st_rtc_ops, THIS_MODULE); - if (IS_ERR(rtc->rtc_dev)) { + rtc->rtc_dev->ops = &st_rtc_ops; + + ret = rtc_register_device(rtc->rtc_dev); + if (ret) { clk_disable_unprepare(rtc->clk); - return PTR_ERR(rtc->rtc_dev); + return ret; } return 0; } -static int st_rtc_remove(struct platform_device *pdev) -{ - struct st_rtc *rtc = platform_get_drvdata(pdev); - - if (likely(rtc->rtc_dev)) - rtc_device_unregister(rtc->rtc_dev); - - return 0; -} - #ifdef CONFIG_PM_SLEEP static int st_rtc_suspend(struct device *dev) { @@ -325,7 +320,6 @@ static struct platform_driver st_rtc_platform_driver = { .of_match_table = st_rtc_match, }, .probe = st_rtc_probe, - .remove = st_rtc_remove, }; module_platform_driver(st_rtc_platform_driver); -- 2.17.0
WARNING: multiple messages have this Message-ID (diff)
From: alexandre.belloni@bootlin.com (Alexandre Belloni) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] rtc: st-lpc: fix possible race condition Date: Sun, 20 May 2018 14:33:36 +0200 [thread overview] Message-ID: <20180520123337.14856-1-alexandre.belloni@bootlin.com> (raw) 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: Alexandre Belloni <alexandre.belloni@bootlin.com> --- drivers/rtc/rtc-st-lpc.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c index d5222667f892..2f1ef2c28740 100644 --- a/drivers/rtc/rtc-st-lpc.c +++ b/drivers/rtc/rtc-st-lpc.c @@ -212,6 +212,10 @@ static int st_rtc_probe(struct platform_device *pdev) if (!rtc) return -ENOMEM; + rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(rtc->rtc_dev)) + return PTR_ERR(rtc->rtc_dev); + spin_lock_init(&rtc->lock); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -253,26 +257,17 @@ static int st_rtc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rtc); - rtc->rtc_dev = rtc_device_register("st-lpc-rtc", &pdev->dev, - &st_rtc_ops, THIS_MODULE); - if (IS_ERR(rtc->rtc_dev)) { + rtc->rtc_dev->ops = &st_rtc_ops; + + ret = rtc_register_device(rtc->rtc_dev); + if (ret) { clk_disable_unprepare(rtc->clk); - return PTR_ERR(rtc->rtc_dev); + return ret; } return 0; } -static int st_rtc_remove(struct platform_device *pdev) -{ - struct st_rtc *rtc = platform_get_drvdata(pdev); - - if (likely(rtc->rtc_dev)) - rtc_device_unregister(rtc->rtc_dev); - - return 0; -} - #ifdef CONFIG_PM_SLEEP static int st_rtc_suspend(struct device *dev) { @@ -325,7 +320,6 @@ static struct platform_driver st_rtc_platform_driver = { .of_match_table = st_rtc_match, }, .probe = st_rtc_probe, - .remove = st_rtc_remove, }; module_platform_driver(st_rtc_platform_driver); -- 2.17.0
next reply other threads:[~2018-05-20 12:33 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-05-20 12:33 Alexandre Belloni [this message] 2018-05-20 12:33 ` [PATCH 1/2] rtc: st-lpc: fix possible race condition Alexandre Belloni 2018-05-20 12:33 ` [PATCH 2/2] rtc: st-lpc: add range Alexandre Belloni 2018-05-20 12:33 ` Alexandre Belloni 2018-05-21 14:42 ` kbuild test robot 2018-05-21 14:42 ` kbuild test robot 2018-05-23 7:19 ` [PATCH 1/2] rtc: st-lpc: fix possible race condition Patrice CHOTARD 2018-05-23 7:19 ` Patrice CHOTARD 2018-05-23 7:19 ` Patrice CHOTARD
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180520123337.14856-1-alexandre.belloni@bootlin.com \ --to=alexandre.belloni@bootlin.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-rtc@vger.kernel.org \ --cc=patrice.chotard@st.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.