From: sashiko-bot@kernel.org
To: "Daniil Demakov" <t3127430@gmail.com>
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH v4] leds: pca9532: Propagate I2C errors
Date: Sun, 29 Nov 2026 00:11:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-239176@kernel.org> (raw)
In-Reply-To: <20261128235735.246391-1-t3127430@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] leds: pca9532: unrestored led->state on error in
pca9532_set_brightness()
- [Medium] leds: pca9532: unlocked led->state update and rollback in
pca9532_set_blink()
--
commit de45e00e83780f08043196b7fb8ea56f8bb90c4f
Author: Daniil Demakov <t3127430@gmail.com>
leds: pca9532: Propagate I2C errors
This commit checks SMBus read and write return values in pca9532_setled(),
propagates errors to callers, configures LEDs before registering their
class devices, and restores led->state if hardware blinking setup fails.
> diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
> index c8085427696ff..1c85e97e964b5 100644
> --- a/drivers/leds/leds-pca9532.c
> +++ b/drivers/leds/leds-pca9532.c
[ ... ]
> @@ -196,7 +216,7 @@ static int pca9532_set_brightness(struct led_classdev *led_cdev,
> }
> if (led->state == PCA9532_PWM0)
> pca9532_setpwm(led->client, PCA9532_PWM_ID_0);
> - pca9532_setled(led);
> + err = pca9532_setled(led);
> return err;
> }
[Severity: Medium]
Should pca9532_set_brightness() restore led->state when pca9532_calcpwm()
or pca9532_setled() fails, the same way pca9532_set_blink() does?
led->state is updated to PCA9532_OFF, PCA9532_ON, or PCA9532_PWM0 before
programming the hardware. If the SMBus transfer in pca9532_setled() fails,
led->state remains out of sync with the hardware register, which skews PWM0
duty-cycle averaging in pca9532_calcpwm() and hardware blink checks in
pca9532_set_brightness() and pca9532_update_hw_blink().
pca9532_gpio_set_value() similarly leaves led->state modified when
pca9532_setled() fails.
> @@ -242,6 +262,7 @@ static int pca9532_set_blink(struct led_classdev *led_cdev,
> struct pca9532_led *led = ldev_to_led(led_cdev);
> struct i2c_client *client = led->client;
> struct pca9532_data *data = i2c_get_clientdata(client);
> + int old_state = led->state;
> int err;
>
> if (!data->hw_blink)
> @@ -255,11 +276,18 @@ static int pca9532_set_blink(struct led_classdev *led_cdev,
>
> err = pca9532_update_hw_blink(led, *delay_on, *delay_off);
> if (err)
> - return err;
> + goto restore_state;
>
> - pca9532_setled(led);
> + err = pca9532_setled(led);
> + if (err)
> + goto restore_state;
>
> return 0;
> +
> +restore_state:
> + led->state = old_state;
> +
> + return err;
> }
[Severity: Medium]
Can saving and restoring led->state without holding data->update_lock race
with pca9532_set_brightness()?
data->update_lock only protects the SMBus calls inside pca9532_setpwm() and
pca9532_setled(). pca9532_set_blink() runs in sysfs or trigger context
while pca9532_set_brightness() runs on set_brightness_work:
CPU0 CPU1 (kworker)
pca9532_set_blink()
old_state = led->state;
pca9532_update_hw_blink()
led->state = PCA9532_PWM1;
pca9532_setpwm()
pca9532_set_brightness(..., LED_OFF)
led->state = PCA9532_OFF;
pca9532_setled()
pca9532_setled() -> fails
led->state = old_state; <-- overwrites PCA9532_OFF with stale state
If pca9532_setled() in pca9532_set_blink() instead succeeds in that window,
it writes PCA9532_OFF to hardware while returning 0 as if hardware blinking
were active. Also, while led->state is transiently PCA9532_PWM1 before a
failing pca9532_setled() rolls it back, a concurrent non-zero
pca9532_set_brightness() hits the led->state == PCA9532_PWM1 early return
and drops the brightness update.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128235735.246391-1-t3127430@gmail.com?part=1
next prev parent reply other threads:[~2026-11-29 0:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 23:57 [PATCH v4] leds: pca9532: Propagate I2C errors Daniil Demakov
2026-11-29 0:11 ` sashiko-bot [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-11-17 6:00 Daniil Demakov
2026-11-17 6:24 ` sashiko-bot
2026-11-26 14:09 ` Lee Jones
2026-11-14 14:19 [PATCH] " Daniil Demakov
2026-11-14 18:52 ` [PATCH v4] " Daniil Demakov
2026-11-14 19:06 ` sashiko-bot
2026-11-16 12:43 ` Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-239176@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=t3127430@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.