[PATCH v2 0/4] leds: pca9532: fix unchecked I2C reads and unbind use-after-free
[email protected] Wed, 29 Jul 2026 15:43:26 +0800
| Newsgroups | org.kernel.vger.linux-leds,dev.linux.lists.imx,org.kernel.vger.linux-kernel,org.kernel.vger.stable |
|---|---|
| Message-ID | <[email protected]> |
This series hardens the pca9532 LED driver against unchecked i2c_smbus_read_byte_data() return values and fixes a use-after-free that can happen on device unbind. Patch 1 (the only patch in v1) checks the return value of i2c_smbus_read_byte_data() in pca9532_getled(), fixing a Coverity INTEGER_OVERFLOW report where an I2C error code was cast into a char and used to compute a bogus LED state. While reviewing v1, Sashiko AI review pointed out three additional pre-existing issues in the same driver. Patches 2-4 address them: - Patch 2: pca9532_setled() has the identical unchecked-read flaw, but it is worse: one register controls four LEDs, so writing the truncated error code back corrupts the state of the other three LEDs sharing the register. The return value is now checked and propagated to callers. - Patch 3: pca9532_gpio_get_value() stores the read result in an unsigned char, so an I2C error is truncated and returned as a valid GPIO level, silently handing corrupt data to kernel/userspace consumers. The read is now stored in an int and the error propagated. - Patch 4: on unbind, the input device allocated with devm_input_allocate_device() stays registered until devres cleanup runs after .remove(). pca9532_destroy_devices() only cancels the work, so an EV_SND event arriving after cancel_work_sync() can re-queue the work and dereference the freed driver data. The input device is now explicitly unregistered before the work is cancelled. All patches build cleanly with CONFIG_LEDS_PCA9532 and CONFIG_LEDS_PCA9532_GPIO enabled and pass checkpatch. Signed-off-by: Haibo Chen <[email protected]> --- Changes in v2: - Patch 1: reworded the commit log and added an Assisted-by trailer. No functional change. - New Patch 2: check pca9532_setled() I2C read return value (pre-existing issue reported by Sashiko AI review of v1). Cc: stable. - New Patch 3: check pca9532_gpio_get_value() I2C read return value (pre-existing issue reported by Sashiko AI review of v1). Cc: stable. - New Patch 4: fix use-after-free on unbind with the N2100 beeper (pre-existing issue reported by Sashiko AI review of v1). Cc: stable. - Link to v1: https://lore.kernel.org/r/[email protected] --- Haibo Chen (4): leds: pca9532: check i2c_smbus_read_byte_data() return value leds: pca9532: check return value in pca9532_setled() leds: pca9532: check return value in pca9532_gpio_get_value() leds: pca9532: fix use-after-free on unbind with N2100 beeper drivers/leds/leds-pca9532.c | 47 ++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) --- base-commit: c5e32e86ca02b003f86e095d379b38148999293d change-id: 20260727-led-fix-28f085e12feb Best regards, -- Haibo Chen <[email protected]>