From: sashiko-bot@kernel.org
To: "Daniil Demakov" <t3127430@gmail.com>, linux-leds@vger.kernel.org
Cc: linux-gpio@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH v4] leds: pca9532: Propagate I2C errors
Date: Tue, 17 Nov 2026 06:24:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-218250@kernel.org> (raw)
In-Reply-To: <20261117060002.3752-1-t3127430@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] leds: pca9532: software blink fallback broken in
pca9532_set_blink()
--
commit 68a4ebaa5c8871e0f2cc482a8a248aba7009e6bc
Author: Daniil Demakov <t3127430@gmail.com>
leds: pca9532: Propagate I2C errors
This commit checks SMBus read and write return values across LED, PWM,
blink, GPIO, and probe paths in leds-pca9532, restoring previous state on
failure and serializing shared state updates under update_lock.
> diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
> index c8085427696ff..19b993d9ac9f5 100644
> --- a/drivers/leds/leds-pca9532.c
> +++ b/drivers/leds/leds-pca9532.c
[ ... ]
> @@ -144,68 +148,147 @@ static int pca9532_calcpwm(struct i2c_client *client, int pwm, int blink,
[ ... ]
> static int pca9532_set_brightness(struct led_classdev *led_cdev,
> - enum led_brightness value)
> + enum led_brightness value)
> {
> - int err = 0;
> struct pca9532_led *led = ldev_to_led(led_cdev);
> + struct pca9532_data *data = i2c_get_clientdata(led->client);
> + int old_state;
> + u8 old_pwm;
> + u8 old_psc;
> + bool pwm_updated = false;
> + int restore_err;
> + int err = 0;
> +
> + mutex_lock(&data->update_lock);
> + old_state = led->state;
> + old_pwm = data->pwm[PCA9532_PWM_ID_0];
> + old_psc = data->psc[PCA9532_PWM_ID_0];
>
> if (value == LED_OFF) {
> led->state = PCA9532_OFF;
> } else if (led->state == PCA9532_PWM1) {
> - return 0; /* Non-zero brightness shall not stop HW blinking */
> + goto out;
> } else if (value == LED_FULL) {
[ ... ]
> @@ -223,29 +306,64 @@ static int pca9532_update_hw_blink(struct pca9532_led *led,
> }
> }
>
> - psc = ((delay_on + delay_off) * PCA9532_PWM_PERIOD_DIV - 1) / 1000;
> - if (psc > U8_MAX) {
> - /* Blink period too long to be handled by hardware */
> + if (delay_on > ULONG_MAX - delay_off)
> return -EINVAL;
> +
> + period = delay_on + delay_off;
> +
> + if (!delay_on || !delay_off)
> + return -EINVAL;
> +
> + if (period > ((U8_MAX + 1) * 1000) /
> + PCA9532_PWM_PERIOD_DIV)
> + return -EINVAL;
[ ... ]
> @@ -255,26 +373,47 @@ 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;
> +
> + err = __pca9532_setled(led);
> + if (err < 0) {
> + led->state = old_state;
> + data->pwm[PCA9532_PWM_ID_1] = old_pwm;
> + data->psc[PCA9532_PWM_ID_1] = old_psc;
> +
> + restore_err = __pca9532_setpwm(client, PCA9532_PWM_ID_1);
> + if (restore_err < 0)
> + dev_warn(&client->dev,
> + "Failed to restore PWM settings: %d\n",
> + restore_err);
> + }
>
> - pca9532_setled(led);
> + goto out;
>
> - return 0;
> +restore_state:
> + led->state = old_state;
> +out:
> + mutex_unlock(&data->update_lock);
> + return err;
> }
[Severity: Medium]
Does returning -EINVAL from pca9532_set_blink() while leaving led->state set
to PCA9532_PWM1 break the fallback to software blinking?
When an LED is already hardware blinking (led->state == PCA9532_PWM1) and
is reconfigured with delays rejected by pca9532_update_hw_blink() (such as
setting delay_off to 0 under the timer trigger, which this patch now rejects
with -EINVAL, or a period longer than the hardware limit), led_blink_setup()
falls back to led_set_software_blink(). For delay_off == 0,
led_set_software_blink() calls led_set_brightness_nosleep(led_cdev,
led_cdev->blink_brightness) to turn the LED steady on, and for software
timer blinking, led_timer_function() alternates brightness between 0 and
blink_brightness. However, pca9532_set_brightness() ignores all non-zero
brightness values while led->state is PCA9532_PWM1, so the LED stays
hardware-blinking at the old PWM1 rate or fails to turn on during software
blink on-phases.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117060002.3752-1-t3127430@gmail.com?part=1
next prev parent reply other threads:[~2026-11-17 6:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 6:00 [PATCH v4] leds: pca9532: Propagate I2C errors Daniil Demakov
2026-11-17 6:24 ` sashiko-bot [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-11-14 14:19 [PATCH] " Daniil Demakov
2026-11-14 18:52 ` [PATCH v4] " Daniil Demakov
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-218250@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=lee@kernel.org \
--cc=linux-gpio@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox