From: sashiko-bot@kernel.org
To: "Geert Uytterhoeven" <geert+renesas@glider.be>
Cc: linux-clk@vger.kernel.org, linux-rtc@vger.kernel.org,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH 2/5] rtc: m41t80: Make sure clk_init_data is fully initialized
Date: Fri, 21 Aug 2026 10:25:04 +0000 [thread overview]
Message-ID: <20260821102504.79ADA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <c5290fb9a28b45d6bcec724d5897f8bcbf96ea50.1787241693.git.geert+renesas@glider.be>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing cleanup of clock registration and OF provider on probe failure and device unbind leads to memory leaks and Use-After-Free.
- [High] Missing cleanup of watchdog device and reboot notifier on probe failure causes resource leaks and Use-After-Free.
- [High] The seconds register is corrupted with the flags register value during time setting.
- [High] Clock operations race with RTC operations causing I2C register corruption.
--
--- Patch [2]: [PATCH 2/5] rtc: m41t80: Make sure clk_init_data is fully initialized ---
commit 11533c947dd31e7928f8df0ec766e6dae1e6ced8
Author: Geert Uytterhoeven <geert+renesas@glider.be>
rtc: m41t80: Make sure clk_init_data is fully initialized
The clk_init_data structure contains several mutually-exclusive members for
different methods to specify the possible parents of a clock, prompting
drivers to initialize only the members they need. Make sure all members are
fully initialized, to avoid bugs and prevent future breakage.
> diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
> index 3c8c379392c14..ec86ca3f2c4c8 100644
> --- a/drivers/rtc/rtc-m41t80.c
> +++ b/drivers/rtc/rtc-m41t80.c
> @@ -574,8 +574,8 @@ static struct clk *m41t80_sqw_register_clk(struct m41t80_data *m41t80)
> struct i2c_client *client = m41t80->client;
> struct device_node *node = client->dev.of_node;
> struct device_node *fixed_clock;
> + struct clk_init_data init = {};
> struct clk *clk;
> - struct clk_init_data init;
> int ret;
[Severity: High]
This is a pre-existing issue, but does m41t80_sqw_register_clk() leak the
registered clock and OF provider?
If devm_rtc_register_device() fails in m41t80_probe(), or when the driver
unbinds and calls m41t80_remove(), the m41t80_data struct is freed. However,
the clock and its OF provider remain registered:
m41t80_sqw_register_clk() {
...
clk = clk_register(&client->dev, &m41t80->sqw);
if (!IS_ERR(clk))
of_clk_add_provider(node, of_clk_src_simple_get, clk);
...
}
Will subsequent clock operations dereference the freed m41t80->sqw field?
[Severity: High]
This is a pre-existing issue, but is there a missing cleanup of the watchdog
device and reboot notifier on probe failure?
In m41t80_probe(), the watchdog device and reboot notifier are registered:
m41t80_probe() {
...
rc = misc_register(&wdt_dev);
if (rc)
return rc;
rc = register_reboot_notifier(&wdt_notifier);
...
}
If devm_rtc_register_device() subsequently fails, the driver returns the
error directly without deregistering the watchdog device or the reboot
notifier:
m41t80_probe() {
...
rc = devm_rtc_register_device(m41t80_data->rtc);
if (rc)
return rc;
...
}
Could this lead to a use-after-free if userspace then accesses /dev/watchdog,
causing wdt_ping() to dereference the freed clientdata memory?
[Severity: High]
This is a pre-existing issue, but does m41t80_rtc_set_time() inadvertently
corrupt the seconds register?
During time setting, when attempting to clear the STOP bit in the seconds
register, it writes the flags variable instead:
m41t80_rtc_set_time() {
...
err = i2c_smbus_write_byte_data(client, M41T80_REG_SEC,
flags & ~M41T80_SEC_ST);
...
}
Since flags is populated earlier by reading the FLAGS register
(M41T80_REG_FLAGS), would this write the raw value of the FLAGS register into
the seconds register, overwriting the previously set time?
[Severity: High]
This is a pre-existing issue, but can clock operations race with RTC
operations and corrupt I2C registers?
The CCF clock callbacks perform read-modify-write sequences on the
M41T80_REG_ALARM_MON and M41T80_REG_WDAY registers without holding a lock
that protects against concurrent time-setting operations:
m41t80_sqw_control() {
...
int ret = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);
...
ret = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, ret);
...
}
m41t80_sqw_set_rate() {
...
reg = i2c_smbus_read_byte_data(client, reg_sqw);
...
ret = i2c_smbus_write_byte_data(client, reg_sqw, reg);
...
}
Meanwhile, the RTC core callbacks modify these same registers under the
protection of the RTC subsystem's rtc_lock.
Since the CCF operations execute asynchronously under clock framework locks
and do not acquire the rtc_lock, could concurrent modifications by both
subsystems clobber the shared I2C registers?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1787241693.git.geert+renesas@glider.be?part=2
next prev parent reply other threads:[~2026-08-21 10:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 10:09 [PATCH 0/5] rtc: Make sure clk_init_data is fully initialized Geert Uytterhoeven
2026-08-21 10:09 ` [PATCH 1/5] rtc: hym8563: " Geert Uytterhoeven
2026-08-21 10:16 ` sashiko-bot
2026-08-21 10:09 ` [PATCH 2/5] rtc: m41t80: " Geert Uytterhoeven
2026-08-21 10:25 ` sashiko-bot [this message]
2026-08-21 10:09 ` [PATCH 3/5] rtc: nct3018y: " Geert Uytterhoeven
2026-08-21 10:37 ` sashiko-bot
2026-08-21 10:09 ` [PATCH 4/5] rtc: philips: " Geert Uytterhoeven
2026-08-21 10:45 ` sashiko-bot
2026-08-21 10:09 ` [PATCH 5/5] rtc: microcrystal: " Geert Uytterhoeven
2026-08-21 10:54 ` 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=20260821102504.79ADA1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=geert+renesas@glider.be \
--cc=linux-clk@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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