Skip to content

Commit fc82336

Browse files
Joy Chakrabortyalexandrebelloni
authored andcommitted
rtc: abx80x: Fix return value of nvmem callback on read
Read callbacks registered with nvmem core expect 0 to be returned on success and a negative value to be returned on failure. abx80x_nvmem_xfer() on read calls i2c_smbus_read_i2c_block_data() which returns the number of bytes read on success as per its api description, this return value is handled as an error and returned to nvmem even on success. Fix to handle all possible values that would be returned by i2c_smbus_read_i2c_block_data(). Fixes: e90ff8e ("rtc: abx80x: Add nvmem support") Cc: [email protected] Signed-off-by: Joy Chakraborty <[email protected]> Reviewed-by: Dan Carpenter <[email protected]> Reviewed-by: Sean Anderson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 1c184ba commit fc82336

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/rtc/rtc-abx80x.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,14 +705,18 @@ static int abx80x_nvmem_xfer(struct abx80x_priv *priv, unsigned int offset,
705705
if (ret)
706706
return ret;
707707

708-
if (write)
708+
if (write) {
709709
ret = i2c_smbus_write_i2c_block_data(priv->client, reg,
710710
len, val);
711-
else
711+
if (ret)
712+
return ret;
713+
} else {
712714
ret = i2c_smbus_read_i2c_block_data(priv->client, reg,
713715
len, val);
714-
if (ret)
715-
return ret;
716+
if (ret <= 0)
717+
return ret ? ret : -EIO;
718+
len = ret;
719+
}
716720

717721
offset += len;
718722
val += len;

0 commit comments

Comments
 (0)