Re: [PATCH] leds: pca9532: Fix phantom device registration on missing hardware
Bartosz Golaszewski <[email protected]> Wed, 15 Jul 2026 01:14:14 -0700
| Newsgroups | org.kernel.vger.linux-leds,org.kernel.vger.linux-gpio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAMRc=McauRSXGQfCSDCQD6bM78f91yxPGFGn+QE4oJG=KfmUkw@mail.gmail.com> |
On Wed, 15 Jul 2026 10:07:47 +0200, Cosmo Chou <[email protected]> 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 <[email protected]> > --- > 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 <[email protected]>