From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Jacky Huang <ychuang3@nuvoton.com>,
Shan-Chun Hung <schung@nuvoton.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Ming-Jen Chen <mjchen@nuvoton.com>,
linux-arm-kernel@lists.infradead.org, linux-rtc@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 03/10] rtc: ma35d1: allocate RTC device before requesting interrupt
Date: Mon, 23 Nov 2026 19:59:14 +0000 [thread overview]
Message-ID: <20261123200012.502284-4-lee@kernel.org> (raw)
In-Reply-To: <20261123200012.502284-1-lee@kernel.org>
ma35d1_rtc_probe() registers ma35d1_rtc_interrupt() via
devm_request_irq() before allocating rtc->rtcdev via
devm_rtc_allocate_device(). During driver unbind or if
devm_rtc_register_device() fails, devres unwinds in reverse order and
frees struct rtc_device in devm_rtc_release_device() before
devm_irq_release() unregisters the interrupt handler. An RTC interrupt
arriving in that teardown window passes a dangling rtc->rtcdev pointer
to rtc_update_irq(), dereferencing freed memory and scheduling a freed
work_struct.
Allocate and initialise rtc->rtcdev before requesting the IRQ so that
devres frees the interrupt handler before releasing the RTC device.
Fixes: dc0684adf3b6 ("rtc: Add driver for Nuvoton ma35d1 rtc controller")
Closes: https://sashiko.dev/#/bug/linux-26674087-baed-4ef2-83a0-78888ea8d16a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-ma35d1.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/rtc/rtc-ma35d1.c b/drivers/rtc/rtc-ma35d1.c
index eb0da8b091dc..beeef6db92d9 100644
--- a/drivers/rtc/rtc-ma35d1.c
+++ b/drivers/rtc/rtc-ma35d1.c
@@ -235,13 +235,6 @@ static int ma35d1_rtc_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, ret, "rtc init failed\n");
}
- rtc->irq_num = platform_get_irq(pdev, 0);
-
- ret = devm_request_irq(&pdev->dev, rtc->irq_num, ma35d1_rtc_interrupt,
- IRQF_NO_SUSPEND, "ma35d1rtc", rtc);
- if (ret)
- return dev_err_probe(&pdev->dev, ret, "Failed to request rtc irq\n");
-
platform_set_drvdata(pdev, rtc);
device_init_wakeup(&pdev->dev, true);
@@ -254,6 +247,13 @@ static int ma35d1_rtc_probe(struct platform_device *pdev)
rtc->rtcdev->range_min = RTC_TIMESTAMP_BEGIN_2000;
rtc->rtcdev->range_max = RTC_TIMESTAMP_END_2099;
+ rtc->irq_num = platform_get_irq(pdev, 0);
+
+ ret = devm_request_irq(&pdev->dev, rtc->irq_num, ma35d1_rtc_interrupt,
+ IRQF_NO_SUSPEND, "ma35d1rtc", rtc);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Failed to request rtc irq\n");
+
ret = devm_rtc_register_device(rtc->rtcdev);
if (ret)
return dev_err_probe(&pdev->dev, ret, "Failed to register rtc device\n");
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 20:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
2026-11-23 19:59 ` [PATCH 01/10] rtc: rx8025: pass parent I2C device in clock_adjust_ppb sysfs callbacks Lee Jones
2026-11-23 19:59 ` [PATCH 02/10] rtc: mt6397: handle non-DT platform device matching in probe Lee Jones
2026-11-23 19:59 ` Lee Jones [this message]
2026-11-23 19:59 ` [PATCH 04/10] rtc: mpc5121: get interrupts via platform_get_irq() Lee Jones
2026-11-23 19:59 ` [PATCH 05/10] rtc: m41t80: use devm helpers for square-wave clock registration Lee Jones
2026-11-23 19:59 ` [PATCH 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind Lee Jones
2026-11-23 19:59 ` [PATCH 07/10] rtc: stmp3xxx: unregister child watchdog platform device " Lee Jones
2026-11-23 19:59 ` [PATCH 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff() Lee Jones
2026-11-23 19:59 ` [PATCH 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path Lee Jones
2026-11-23 19:59 ` [PATCH 10/10] rtc: bq32k: use u8 register buffer in trickle_charge_bypass sysfs Lee Jones
2026-11-23 20:16 ` [PATCH 00/10] rtc: assorted bug fixes across RTC drivers sashiko-bot
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=20261123200012.502284-4-lee@kernel.org \
--to=lee@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=mjchen@nuvoton.com \
--cc=schung@nuvoton.com \
--cc=stable@vger.kernel.org \
--cc=ychuang3@nuvoton.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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox