All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	dmitry pervushin <dpervushin@embeddedalley.com>,
	linux-arm-kernel@lists.infradead.org, linux-rtc@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Peter Hartley <peter.hartley@sigmatel.com>,
	Wim Van Sebroeck <wim@iguana.be>, Wolfram Sang <wsa@kernel.org>
Subject: [PATCH v2 07/10] rtc: stmp3xxx: unregister child watchdog platform device on unbind
Date: Wed,  2 Dec 2026 20:22:36 +0000	[thread overview]
Message-ID: <e055dc62e1d7f3a802d0373bee59fcdfc2cfdade.1796242916.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796242916.git.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>
---

v1 => v2:
 - No changes

Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: dmitry pervushin <dpervushin@embeddedalley.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-rtc@vger.kernel.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Peter Hartley <peter.hartley@sigmatel.com>
Cc: Wim Van Sebroeck <wim@iguana.be>
Cc: Wolfram Sang <wsa@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 7afcd14aeee5..98c2f8579689 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.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-02 20:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 20:22 [PATCH v2 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
2026-12-02 20:22 ` [PATCH v2 01/10] rtc: rx8025: pass parent I2C device in clock_adjust_ppb sysfs callbacks Lee Jones
2026-12-02 20:22 ` [PATCH v2 02/10] rtc: mt6397: handle non-DT platform device matching in probe Lee Jones
2026-12-02 20:22 ` [PATCH v2 03/10] rtc: ma35d1: allocate RTC device before requesting interrupt Lee Jones
2026-12-02 20:22 ` [PATCH v2 04/10] rtc: mpc5121: get interrupts via platform_get_irq() Lee Jones
2026-12-02 20:22 ` [PATCH v2 05/10] rtc: m41t80: use devm helpers for square-wave clock registration Lee Jones
2026-12-02 20:22 ` [PATCH v2 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind Lee Jones
2026-12-02 20:22 ` Lee Jones [this message]
2026-12-02 20:22 ` [PATCH v2 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff() Lee Jones
2026-12-02 20:22 ` [PATCH v2 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path Lee Jones
2026-12-02 20:22 ` [PATCH v2 10/10] rtc: bq32k: use u8 register buffer in trickle_charge_bypass sysfs Lee Jones
2026-12-02 20:30 ` [PATCH v2 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=e055dc62e1d7f3a802d0373bee59fcdfc2cfdade.1796242916.git.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=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 \
    --cc=wsa@kernel.org \
    /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.