Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: e90ff8ede777 ("rtc: abx80x: Add nvmem support")
Cc: stable@vger.kernel.org
Signed-off-by: Joy Chakraborty <joychakr@google.com>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Sean Anderson <sean.anderson@seco.com>
Link: https://lore.kernel.org/r/20240613120750.1455209-1-joychakr@google.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

Joy Chakraborty and committed by
Alexandre Belloni
fc82336b 1c184bac

+8 -4
+8 -4
drivers/rtc/rtc-abx80x.c
··· 705 705 if (ret) 706 706 return ret; 707 707 708 - if (write) 708 + if (write) { 709 709 ret = i2c_smbus_write_i2c_block_data(priv->client, reg, 710 710 len, val); 711 - else 711 + if (ret) 712 + return ret; 713 + } else { 712 714 ret = i2c_smbus_read_i2c_block_data(priv->client, reg, 713 715 len, val); 714 - if (ret) 715 - return ret; 716 + if (ret <= 0) 717 + return ret ? ret : -EIO; 718 + len = ret; 719 + } 716 720 717 721 offset += len; 718 722 val += len;