From: sashiko-bot@kernel.org
To: kr494167@gmail.com
Cc: "Alexandre Belloni" <alexandre.belloni@bootlin.com>,
linux-rtc@vger.kernel.org
Subject: Re: [PATCH] rtc: spacemit: handle regmap_test_bits() error return
Date: Fri, 24 Jul 2026 02:48:57 +0000 [thread overview]
Message-ID: <20260724024857.CA4291F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724024220.10113-1-kr494167@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The anti-tearing retry loop in `p1_rtc_read_time()` is flawed and can silently accept corrupted time readings because it only compares the seconds byte between reads.
--
--- Patch [1]: [PATCH] rtc: spacemit: handle regmap_test_bits() error return ---
commit 8fa251c335a9b68b25f44d335129e65501d1e159
Author: Surendra Singh Chouhan <kr494167@gmail.com>
rtc: spacemit: handle regmap_test_bits() error return
This commit fixes the error handling when reading the RTC control register.
It ensures that if regmap_test_bits() returns a negative error code, that
error is propagated instead of being incorrectly treated as boolean false.
> diff --git a/drivers/rtc/rtc-spacemit-p1.c b/drivers/rtc/rtc-spacemit-p1.c
> index 43ab62494bb4b..c1820c920ba3d 100644
> --- a/drivers/rtc/rtc-spacemit-p1.c
> +++ b/drivers/rtc/rtc-spacemit-p1.c
> @@ -57,8 +57,9 @@ static int p1_rtc_read_time(struct device *dev, struct rtc_time *t)
> u8 time[6];
> int ret;
>
> - if (!regmap_test_bits(regmap, RTC_CTRL, RTC_EN))
> - return -EINVAL; /* RTC is disabled */
> + ret = regmap_test_bits(regmap, RTC_CTRL, RTC_EN);
> + if (ret <= 0)
> + return ret ? ret : -EINVAL; /* RTC is disabled or error */
>
> ret = regmap_bulk_read(regmap, RTC_TIME, time, sizeof(time));
> if (ret)
[Severity: High]
This is a pre-existing issue, but does the anti-tearing retry loop in
p1_rtc_read_time() fully protect against corrupted time readings?
Looking just below this diff in p1_rtc_read_time(), the loop checks for time
tearing by only comparing the seconds byte:
do {
seconds = time[0];
ret = regmap_bulk_read(regmap, RTC_TIME, time, sizeof(time));
if (ret)
return ret;
} while (time[0] != seconds && --count);
If a hardware time rollover occurs exactly after the seconds byte (time[0])
is read during the second regmap_bulk_read(), the read could return the
pre-rollover seconds but post-rollover minutes, hours, or days.
Since the seconds byte matches the previous read, the loop would incorrectly
terminate and accept the torn time array. Can this lead to corrupted time
being returned to the RTC subsystem?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724024220.10113-1-kr494167@gmail.com?part=1
next prev parent reply other threads:[~2026-07-24 2:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 2:42 [PATCH] rtc: spacemit: handle regmap_test_bits() error return kr494167
2026-07-24 2:42 ` kr494167
2026-07-24 2:48 ` sashiko-bot [this message]
2026-07-24 13:32 ` Alex Elder
2026-07-24 13:32 ` Alex Elder
2026-07-24 13:39 ` Alexandre Belloni
2026-07-24 13:39 ` Alexandre Belloni
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=20260724024857.CA4291F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=kr494167@gmail.com \
--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.