[PATCH v2 3/4] leds: pca9532: check return value in pca9532_gpio_get_value()
From: haibo . chen
Date: Wed Jul 29 2026 - 03:49:16 EST
From: Haibo Chen <haibo.chen@xxxxxxx>
pca9532_gpio_get_value() reads the input register with
i2c_smbus_read_byte_data() but stores the result in an unsigned char and
never checks for failure. On an I2C read error the negative error code
(e.g. -EIO) is truncated to an unsigned byte, and a bit is extracted and
returned as a valid GPIO level. This masks hardware errors and lets
kernel or userspace consumers silently receive corrupt data.
The gpio_chip .get callback may return a negative error code, so store
the read result in an int and propagate the error on failure.
Fixes: 3c1ab50d0a31 ("drivers/leds/leds-pca9532.c: add gpio capability")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: VeroCoder:claude-sonnet-4
Signed-off-by: Haibo Chen <haibo.chen@xxxxxxx>
---
drivers/leds/leds-pca9532.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index adfb5aa50e8e1f3ca0deb9261d8c9103903ef928..cee398d8275b8953b5dbdb741c36161f34bba029 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -345,9 +345,14 @@ static int pca9532_gpio_set_value(struct gpio_chip *gc, unsigned int offset,
static int pca9532_gpio_get_value(struct gpio_chip *gc, unsigned offset)
{
struct pca9532_data *data = gpiochip_get_data(gc);
- unsigned char reg;
+ int reg;
reg = i2c_smbus_read_byte_data(data->client, PCA9532_REG_INPUT(offset));
+ if (reg < 0) {
+ dev_warn(&data->client->dev,
+ "failed to read input register: %d\n", reg);
+ return reg;
+ }
return !!(reg & (1 << (offset % 8)));
}
--
2.34.1