[PATCH v6 2/9] rtc: abx80x: fix error check after i2c_smbus_read in read_alarm()
From: Antoni Pokusinski
Date: Mon Sep 07 2026 - 16:43:17 EST
i2c_smbus_read_i2c_block_data() returns the number of bytes read on
success and a negative error code on failure. The existing code treated
any non-zero return value as an error.
Fix the error handling by checking only for negative return values.
Fixes: 718a820a303c ("rtc: abx80x: add alarm support")
Signed-off-by: Antoni Pokusinski <apokusinski01@xxxxxxxxx>
---
drivers/rtc/rtc-abx80x.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index 5486d9d0b1e5..e4fd7b5d4b11 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -294,8 +294,10 @@ static int abx80x_read_alarm(struct device *dev, struct rtc_wkalrm *t)
err = i2c_smbus_read_i2c_block_data(client, ABX8XX_REG_ASC,
sizeof(buf), buf);
- if (err)
+ if (err < 0)
return err;
+ if (err < ARRAY_SIZE(buf))
+ return -EIO;
irq_mask = i2c_smbus_read_byte_data(client, ABX8XX_REG_IRQ);
if (irq_mask < 0)
@@ -311,7 +313,7 @@ static int abx80x_read_alarm(struct device *dev, struct rtc_wkalrm *t)
t->enabled = !!(irq_mask & ABX8XX_IRQ_AIE);
t->pending = (buf[6] & ABX8XX_STATUS_AF) && t->enabled;
- return err;
+ return 0;
}
static int abx80x_set_alarm(struct device *dev, struct rtc_wkalrm *t)
--
2.55.0