From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Alexandre Belloni <alexandre.belloni@bootlin.com>,
Alexander Bigga <ab@mycable.de>,
"Mark A. Greer" <mgreer@mvista.com>,
Gary Bisson <gary.bisson@boundarydevices.com>,
linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 05/10] rtc: m41t80: use devm helpers for square-wave clock registration
Date: Mon, 23 Nov 2026 19:59:16 +0000 [thread overview]
Message-ID: <20261123200012.502284-6-lee@kernel.org> (raw)
In-Reply-To: <20261123200012.502284-1-lee@kernel.org>
m41t80_sqw_register_clk() registers m41t80->sqw and its OF clock
provider using unmanaged clk_register() and of_clk_add_provider(), and
neither probe failure nor driver unbind unregisters them. Because
m41t80->sqw is embedded inside the devm-allocated m41t80_data
structure, unbinding the device or failing devm_rtc_register_device()
frees m41t80_data while leaving the clock and OF provider registered,
causing a resource leak and a use-after-free when clock callbacks or
debugfs clk_summary access sqw_to_m41t80_data().
Use devm_clk_register() and devm_of_clk_add_hw_provider() tied to the
I2C client device so both the provider and clock are automatically
unregistered before m41t80_data is freed.
Fixes: 1373e77b4f10 ("rtc: m41t80: add clock provider support")
Closes: https://sashiko.dev/#/bug/linux-4d3dfb5c-0f65-4bb5-94e8-653bc0543df5
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/rtc/rtc-m41t80.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index cfab27aaa518..5f8d6dcdeb5b 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -604,9 +604,10 @@ static struct clk *m41t80_sqw_register_clk(struct m41t80_data *m41t80)
of_property_read_string(node, "clock-output-names", &init.name);
/* register the clock */
- clk = clk_register(&client->dev, &m41t80->sqw);
+ clk = devm_clk_register(&client->dev, &m41t80->sqw);
if (!IS_ERR(clk))
- of_clk_add_provider(node, of_clk_src_simple_get, clk);
+ devm_of_clk_add_hw_provider(&client->dev, of_clk_hw_simple_get,
+ &m41t80->sqw);
return clk;
}
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 20:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261123200012.502284-1-lee@kernel.org>
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 ` Lee Jones [this message]
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
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-6-lee@kernel.org \
--to=lee@kernel.org \
--cc=ab@mycable.de \
--cc=alexandre.belloni@bootlin.com \
--cc=gary.bisson@boundarydevices.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=mgreer@mvista.com \
--cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox