Skip to contentSkip to conversation

leds: pca955x: fix return value checking of smbus block read

PATCH In review Potin Lai 2 participants 2 messages Sep 28, 2022 – Sep 29, 2022 LED

lore
Share & tools
lore

Potin Lai

author
#0 lore raw

PATCH 1/1 leds: pca955x: fix return value checking of smbus block read

In i2c_smbus_read_i2c_block_data(), it returns negtive value for error code, otherwise returns data length of reading.
Change the if statement to "if (err < 0)" to indicate the real error returned by i2c_smbus_read_i2c_block_data().

LORE Link: https://lore.kernel.org/all/[email protected]/

---
 drivers/leds/leds-pca955x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/leds/leds-pca955x.c +1 -1
index cf0a9fe20086a..cba9876b11872 100644
@@ -689,7 +689,7 @@ static int pca955x_probe(struct i2c_client *client)
 	err = i2c_smbus_read_i2c_block_data(client,
 					    0x10 | (pca955x_num_input_regs(chip->bits) + 4), nls,
 					    ls1);
-	if (err)
+	if (err < 0)
 		return err;
 
 	for (i = 0; i < nls; ++i)
Signature · 1 line
2.31.1
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 4 lines · Potin Lai

In i2c_smbus_read_i2c_block_data(), it returns negtive value for error code, otherwise returns data length of reading.
Change the if statement to "if (err < 0)" to indicate the real error returned by i2c_smbus_read_i2c_block_data().

Thanks! My mistake here.

Quoted 21 lines

LORE Link: https://lore.kernel.org/all/[email protected]/

---
  drivers/leds/leds-pca955x.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/leds/leds-pca955x.c +1 -1
index cf0a9fe20086a..cba9876b11872 100644
@@ -689,7 +689,7 @@ static int pca955x_probe(struct i2c_client *client)
  	err = i2c_smbus_read_i2c_block_data(client,
  					    0x10 | (pca955x_num_input_regs(chip->bits) + 4), nls,
  					    ls1);
-	if (err)
+	if (err < 0)
  		return err;
 
  	for (i = 0; i < nls; ++i)