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 3/5] rtc: nct3018y: Make sure clk_init_data is fully initialized
Date: Fri, 21 Aug 2026 10:37:01 +0000 [thread overview]
Message-ID: <20260821103702.544741F000E9@smtp.kernel.org> (raw)
In-Reply-To: <6dba18b645aeea279a67f4625d5ec48037c76f0c.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] Unmanaged OF clock provider registration causes a resource leak and potential use-after-free on probe failure or driver unbind.
- [High] Missing restore of NCT3018Y_REG_CTRL state on error paths in nct3018y_rtc_set_time.
- [High] Data race due to missing lock for read-modify-write sequences on NCT3018Y_REG_CTRL.
- [High] Unhandled I2C short block reads lead to uninitialized kernel stack memory being used and potentially leaked to userspace.
--
--- Patch [3]: [PATCH 3/5] rtc: nct3018y: Make sure clk_init_data is fully initialized ---
commit 3afc7c4d645666922e04824eeba8803bb2dbf8c0
Author: Geert Uytterhoeven <geert+renesas@glider.be>
rtc: nct3018y: Make sure clk_init_data is fully initialized
This commit fixes a potential issue where uninitialized members in the
clk_init_data structure could cause subtle bugs depending on stack
initialization configs. It fully initializes the structure to avoid
future breakage.
> diff --git a/drivers/rtc/rtc-nct3018y.c b/drivers/rtc/rtc-nct3018y.c
> index 700a395fad3a6..2f7ad57057a4b 100644
> --- a/drivers/rtc/rtc-nct3018y.c
> +++ b/drivers/rtc/rtc-nct3018y.c
> @@ -459,8 +459,8 @@ static struct clk *nct3018y_clkout_register_clk(struct nct3018y *nct3018y)
> {
> struct i2c_client *client = nct3018y->client;
> struct device_node *node = client->dev.of_node;
> + struct clk_init_data init = {};
> struct clk *clk;
> - struct clk_init_data init;
>
> init.name = "nct3018y-clkout";
> init.ops = &nct3018y_clkout_ops;
[Severity: High]
This isn't a bug introduced by this patch, but does this function leak the
clock provider on probe failure or driver unbind?
Further down in nct3018y_clkout_register_clk():
of_clk_add_provider(node, of_clk_src_simple_get, clk);
When of_clk_add_provider() is called without a corresponding remove path or
devres wrapper like devm_of_clk_add_hw_provider, it looks like a dangling
pointer could be left in the global of_clk_providers list. If the memory
backing the clock is freed via devres and another device queries the clock,
can this lead to a use-after-free?
[Severity: High]
This is a pre-existing issue, but is there a missing restore of the
register state on error paths in nct3018y_rtc_set_time?
drivers/rtc/rtc-nct3018y.c:nct3018y_rtc_set_time() {
...
err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_SC, buf[0]);
if (err < 0) {
dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_SC\n");
return err;
}
...
}
If an I2C write error occurs during time setting, the driver returns early
without restoring NCT3018Y_REG_CTRL. Does this leave the hardware in an
inconsistent state with the NCT3018Y_BIT_TWO flag set incorrectly?
[Severity: High]
This isn't a bug introduced by this patch, but is there a data race on
NCT3018Y_REG_CTRL?
nct3018y_rtc_set_time() executes in process context and performs a
read-modify-write:
drivers/rtc/rtc-nct3018y.c:nct3018y_rtc_set_time() {
...
flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL);
...
flags |= NCT3018Y_BIT_TWO;
err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags);
...
}
Simultaneously, the threaded IRQ handler can call nct3018y_set_alarm_mode()
which does the same:
drivers/rtc/rtc-nct3018y.c:nct3018y_set_alarm_mode() {
...
flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL);
...
flags |= NCT3018Y_BIT_CIE;
err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags);
...
}
Since the RTC core's ops_lock doesn't serialize against the threaded IRQ
handler, can concurrent operations overwrite each other's register state
and lead to missed alarms?
[Severity: High]
This is a pre-existing issue, but could unhandled short reads leak
uninitialized kernel stack memory to userspace?
drivers/rtc/rtc-nct3018y.c:nct3018y_rtc_read_time() {
...
err = i2c_smbus_read_i2c_block_data(client, NCT3018Y_REG_SC,
sizeof(buf), buf);
if (err < 0)
return err;
tm->tm_sec = bcd2bin(buf[0] & 0x7F);
...
}
i2c_smbus_read_i2c_block_data() returns the number of bytes read on success.
If it returns fewer bytes than requested, the remainder of the stack buffer
remains uninitialized but is still parsed into the rtc_time struct.
Can this uninitialized memory then be read by userspace via the RTC_RD_TIME
ioctl?
The same pattern appears to exist in nct3018y_rtc_read_alarm():
drivers/rtc/rtc-nct3018y.c:nct3018y_rtc_read_alarm() {
...
err = i2c_smbus_read_i2c_block_data(client, NCT3018Y_REG_SCA,
sizeof(buf), buf);
if (err < 0) {
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1787241693.git.geert+renesas@glider.be?part=3
next prev parent reply other threads:[~2026-08-21 10:37 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
2026-08-21 10:09 ` [PATCH 3/5] rtc: nct3018y: " Geert Uytterhoeven
2026-08-21 10:37 ` sashiko-bot [this message]
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=20260821103702.544741F000E9@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 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.