[PATCH v2 6/7] leds: aw2013: Prevent writes to unpowered chip

From: Paul Sajna

Date: Mon Oct 05 2026 - 23:49:43 EST


Replace chip_in_use check with chip->enabled boolean in
aw20xx_brightness_set

During teardown, probe, or unregistration, the LED core initializes
cdev->brightness to 0 and queues a work to set the brightness to 0.
This canalso be triggered by unprivileged user space via sysfs by
writing 0 to the brightness file when already 0.

When this occurs, aw2013_chip_in_use() evaluates to false and skips
enabling the regulators:

Because aw2013_chip_enable() is skipped, the driver then unconditionally
calls regmap_write() and regmap_update_bits(), which perform I2C
transactions to the unpowered chip.

Signed-off-by: Paul Sajna <sajattack@xxxxxxxxxxxxxxxx>
---
drivers/leds/leds-aw2013.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/leds/leds-aw2013.c b/drivers/leds/leds-aw2013.c
index 5d242e2bab60..2a133657d9b6 100644
--- a/drivers/leds/leds-aw2013.c
+++ b/drivers/leds/leds-aw2013.c
@@ -257,7 +257,7 @@ static int aw20xx_brightness_set(struct led_classdev *cdev,

mutex_lock(&led->chip->mutex);

- if (aw20xx_chip_in_use(led->chip)) {
+ if (!led->chip->enabled) {
ret = aw20xx_chip_enable(led->chip);
if (ret)
goto error;

--
2.55.0