* [PATCH] leds: pca9532: Fix phantom device registration on missing hardware
@ 2026-07-15 8:07 Cosmo Chou
2026-07-15 8:14 ` Bartosz Golaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Cosmo Chou @ 2026-07-15 8:07 UTC (permalink / raw)
To: lee, pavel, riku.voipio
Cc: linusw, brgl, linux-leds, linux-gpio, linux-kernel, cosmo.chou,
Cosmo Chou
The initial PWM and PSC register writes in pca9532_configure() do not
check the return values of i2c_smbus_write_byte_data(). If the I2C
device is physically absent from the bus, the write fails with -ENXIO.
However, the driver ignores this error and allows probe() to complete
successfully.
This results in the registration of phantom LED class devices and
gpiochips backed by non-existent hardware. Subsequent GPIO reads from
these phantom chips return bogus values (due to -ENXIO being truncated
to an unsigned char in pca9532_gpio_get_value()), silently corrupting
hardware state tracking in userspace.
Propagate the I2C write failures back to probe() so the driver core
can gracefully abort binding and release devres-managed resources.
Fixes: e14fa82439d3 ("leds: Add pca9532 led driver")
Signed-off-by: Cosmo Chou <chou.cosmo@gmail.com>
---
drivers/leds/leds-pca9532.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index f3bf59495b68..9606c5b294ed 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -397,10 +397,14 @@ static int pca9532_configure(struct i2c_client *client,
for (i = 0; i < 2; i++) {
data->pwm[i] = pdata->pwm[i];
data->psc[i] = pdata->psc[i];
- i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(maxleds, i),
- data->pwm[i]);
- i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(maxleds, i),
- data->psc[i]);
+ err = i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(maxleds, i),
+ data->pwm[i]);
+ if (err < 0)
+ return err;
+ err = i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(maxleds, i),
+ data->psc[i]);
+ if (err < 0)
+ return err;
}
data->hw_blink = true;
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] leds: pca9532: Fix phantom device registration on missing hardware
2026-07-15 8:07 [PATCH] leds: pca9532: Fix phantom device registration on missing hardware Cosmo Chou
@ 2026-07-15 8:14 ` Bartosz Golaszewski
0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-07-15 8:14 UTC (permalink / raw)
To: Cosmo Chou
Cc: linusw, brgl, linux-leds, linux-gpio, linux-kernel, cosmo.chou,
lee, pavel, riku.voipio
On Wed, 15 Jul 2026 10:07:47 +0200, Cosmo Chou <chou.cosmo@gmail.com> said:
> The initial PWM and PSC register writes in pca9532_configure() do not
> check the return values of i2c_smbus_write_byte_data(). If the I2C
> device is physically absent from the bus, the write fails with -ENXIO.
> However, the driver ignores this error and allows probe() to complete
> successfully.
>
> This results in the registration of phantom LED class devices and
> gpiochips backed by non-existent hardware. Subsequent GPIO reads from
> these phantom chips return bogus values (due to -ENXIO being truncated
> to an unsigned char in pca9532_gpio_get_value()), silently corrupting
> hardware state tracking in userspace.
>
> Propagate the I2C write failures back to probe() so the driver core
> can gracefully abort binding and release devres-managed resources.
>
> Fixes: e14fa82439d3 ("leds: Add pca9532 led driver")
> Signed-off-by: Cosmo Chou <chou.cosmo@gmail.com>
> ---
> drivers/leds/leds-pca9532.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
> index f3bf59495b68..9606c5b294ed 100644
> --- a/drivers/leds/leds-pca9532.c
> +++ b/drivers/leds/leds-pca9532.c
> @@ -397,10 +397,14 @@ static int pca9532_configure(struct i2c_client *client,
> for (i = 0; i < 2; i++) {
> data->pwm[i] = pdata->pwm[i];
> data->psc[i] = pdata->psc[i];
> - i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(maxleds, i),
> - data->pwm[i]);
> - i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(maxleds, i),
> - data->psc[i]);
> + err = i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(maxleds, i),
> + data->pwm[i]);
> + if (err < 0)
> + return err;
> + err = i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(maxleds, i),
> + data->psc[i]);
> + if (err < 0)
> + return err;
> }
>
> data->hw_blink = true;
> --
> 2.43.0
>
>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-15 8:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-15 8:07 [PATCH] leds: pca9532: Fix phantom device registration on missing hardware Cosmo Chou
2026-07-15 8:14 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox