mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-28 12:53:14 +01:00
rtc: spacemit: handle regmap_test_bits() error return
p1_rtc_read_time() called if (!regmap_test_bits(regmap, RTC_CTRL, RTC_EN))
to check if the RTC was enabled.
regmap_test_bits() returns 1 if the bit is set, 0 if not set, and a
negative error code (e.g. -EIO) if reading the control register fails.
Using !regmap_test_bits(...) evaluates a negative error code as boolean
false, causing I2C/regmap read failures to be ignored and incorrectly
proceeding to read time registers from a failing device.
Fix this by capturing the return value of regmap_test_bits() and returning
the error code if negative, or -EINVAL if the RTC is disabled.
Fixes: a6de182daa ("rtc: spacemit: support the SpacemiT P1 RTC")
Reviewed-by: Alex Elder <[email protected]>
Signed-off-by: Surendra Singh Chouhan <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Alexandre Belloni <[email protected]>
This commit is contained in:
1 parent
9c48a53685
commit
092755367e
1 file changed
+3
-2
@@ -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 ?: -EINVAL; /* RTC is disabled or error */
|
||||
|
||||
ret = regmap_bulk_read(regmap, RTC_TIME, time, sizeof(time));
|
||||
if (ret)
|
||||
|
||||
Reference in new issue
Block a user