From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Alexandre Belloni <alexandre.belloni@bootlin.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Peter Hartley <peter.hartley@sigmatel.com>,
dmitry pervushin <dpervushin@embeddedalley.com>,
Wolfram Sang <kernel@pengutronix.de>,
Andrew Morton <akpm@linux-foundation.org>,
Wim Van Sebroeck <wim@iguana.be>,
linux-rtc@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 07/10] rtc: stmp3xxx: unregister child watchdog platform device on unbind
Date: Mon, 23 Nov 2026 19:59:18 +0000 [thread overview]
Message-ID: <20261123200012.502284-8-lee@kernel.org> (raw)
In-Reply-To: <20261123200012.502284-1-lee@kernel.org>
stmp3xxx_wdt_register() creates and registers the child
"stmp3xxx_rtc_wdt" platform device without tracking or unregistering it
when the parent RTC driver unbinds, and also assigns static wdt_pdata
directly to dev.platform_data where platform_device_release() passes it
to kfree(). After unbind, devres unmaps rtc_data->io and frees
rtc_data while the parent drvdata is cleared, so subsequent watchdog
operations or reboot notifications invoking stmp3xxx_wdt_set_timeout()
dereference torn-down parent state.
Register the child platform device via platform_device_register_data()
so its platform data is heap-allocated, and tie
platform_device_unregister() to the parent device with
devm_add_action_or_reset() so the watchdog device is torn down before
parent resources are released.
Fixes: 1a71fb84fda6 ("rtc: stmp3xxx: add wdt-accessor function")
Closes: https://sashiko.dev/#/bug/linux-4ddbfe9c-a03c-4a01-a3ce-357545121630
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-stmp3xxx.c | 29 +++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index d79e282e3817..a5281b519540 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -92,24 +92,29 @@ static void stmp3xxx_wdt_set_timeout(struct device *dev, u32 timeout)
}
}
-static struct stmp3xxx_wdt_pdata wdt_pdata = {
+static const struct stmp3xxx_wdt_pdata wdt_pdata = {
.wdt_set_timeout = stmp3xxx_wdt_set_timeout,
};
+static void stmp3xxx_wdt_unregister(void *data)
+{
+ platform_device_unregister(data);
+}
+
static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev)
{
- int rc = -1;
- struct platform_device *wdt_pdev =
- platform_device_alloc("stmp3xxx_rtc_wdt", rtc_pdev->id);
-
- if (wdt_pdev) {
- wdt_pdev->dev.parent = &rtc_pdev->dev;
- wdt_pdev->dev.platform_data = &wdt_pdata;
- rc = platform_device_add(wdt_pdev);
- if (rc)
- platform_device_put(wdt_pdev);
- }
+ struct platform_device *wdt_pdev;
+ int rc;
+ wdt_pdev = platform_device_register_data(&rtc_pdev->dev,
+ "stmp3xxx_rtc_wdt",
+ rtc_pdev->id, &wdt_pdata,
+ sizeof(wdt_pdata));
+ rc = PTR_ERR_OR_ZERO(wdt_pdev);
+ if (!rc)
+ rc = devm_add_action_or_reset(&rtc_pdev->dev,
+ stmp3xxx_wdt_unregister,
+ wdt_pdev);
if (rc)
dev_err(&rtc_pdev->dev,
"failed to register stmp3xxx_rtc_wdt\n");
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 20:01 UTC|newest]
Thread overview: 14+ 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 ` [PATCH 03/10] rtc: ma35d1: allocate RTC device before requesting interrupt Lee Jones
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 ` Lee Jones [this message]
2026-11-23 19:59 ` [PATCH 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff() Lee Jones
2026-11-29 16:08 ` Imre Kaloz
2026-11-23 19:59 ` [PATCH 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path Lee Jones
2026-11-24 7:59 ` Johan Hovold
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-8-lee@kernel.org \
--to=lee@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexandre.belloni@bootlin.com \
--cc=alexandre.torgue@foss.st.com \
--cc=dpervushin@embeddedalley.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=peter.hartley@sigmatel.com \
--cc=stable@vger.kernel.org \
--cc=wim@iguana.be \
/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 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.