[PATCH] rtc: ds1307: Check the calibration register read result
From: Zhu Jun
Date: Thu Nov 12 2026 - 02:27:21 EST
m41txx_rtc_read_offset() ignores regmap_read() failures and calculates
the calibration offset from an uninitialized control register value.
An I2C transfer error can therefore be reported as a successful offset
read with an arbitrary result.
Return the read error before decoding the register or updating the
caller's offset.
Fixes: 79230ff64167 ("rtc: ds1307: add offset sysfs for mt41txx chips.")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
drivers/rtc/rtc-ds1307.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 8ab28cc2f181..2e9f0b3d2a93 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -853,9 +853,12 @@ static int m41txx_rtc_read_offset(struct device *dev, long *offset)
{
struct ds1307 *ds1307 = dev_get_drvdata(dev);
unsigned int ctrl_reg;
+ int ret;
u8 val;
- regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg);
+ ret = regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg);
+ if (ret)
+ return ret;
val = ctrl_reg & M41TXX_M_CALIBRATION;
--
2.51.0