Linux LED subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniil Demakov" <t3127430@gmail.com>
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH v3] leds: pca9532: Propagate I2C errors
Date: Sat, 28 Nov 2026 23:50:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-239153@kernel.org> (raw)
In-Reply-To: <20261128234104.242580-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_blink()
- [Low] leds: pca9532: redundant I2C write on rollback in
  pca9532_configure()
--

commit 15d258237fb566c3dd867ed6f88e5dd7743fd211
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, and unregisters the LED class device if
configuring it fails.

> diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
> index c8085427696ff..e2772c7b23d92 100644
> --- a/drivers/leds/leds-pca9532.c
> +++ b/drivers/leds/leds-pca9532.c
[ ... ]
> @@ -257,9 +277,9 @@ static int pca9532_set_blink(struct led_classdev *led_cdev,
>  	if (err)
>  		return err;
>  
> -	pca9532_setled(led);
> +	err = pca9532_setled(led);
>  
> -	return 0;
> +	return err;
>  }

[Severity: Medium]
Does returning an error here leave led->state stuck at PCA9532_PWM1?

pca9532_update_hw_blink() sets led->state = PCA9532_PWM1 before
pca9532_setled() writes the hardware selector register.  When
pca9532_set_blink() returns a non-zero error, led_blink_setup() falls back
to software blinking, but non-zero brightness updates are then ignored
because pca9532_set_brightness() sees PCA9532_PWM1:

drivers/leds/leds-pca9532.c:pca9532_set_brightness() {
    ...
	if (value == LED_OFF) {
		led->state = PCA9532_OFF;
	} else if (led->state == PCA9532_PWM1) {
		return 0; /* Non-zero brightness shall not stop HW blinking */
    ...
}

As a result, the ON phase of software blinking and later non-zero
brightness writes silently do nothing, and pca9532_update_hw_blink() on
sibling LEDs rejects different blink timings with -EINVAL even though
hardware blinking was not enabled on this LED.  pca9532_set_brightness()
similarly updates led->state before pca9532_calcpwm() and pca9532_setled()
succeed.

[ ... ]

> @@ -442,14 +460,20 @@ static int pca9532_configure(struct i2c_client *client,
>  					led->name);
>  				goto exit;
>  			}
> -			pca9532_setled(led);
> +			err = pca9532_setled(led);
> +			if (err) {
> +				led_classdev_unregister(&led->ldev);
> +			    goto exit;
> +			}
>  			break;
>  		case PCA9532_TYPE_N2100_BEEP:
>  			/* PWM1 is reserved for beeper so blink will not use hardware */
>  			data->hw_blink = false;
>  			BUG_ON(data->idev);
>  			led->state = PCA9532_PWM1;
> -			pca9532_setled(led);
> +			err = pca9532_setled(led);
> +			if (err)
> +			    goto exit;
>  			data->idev = devm_input_allocate_device(&client->dev);
>  			if (data->idev == NULL) {
>  				err = -ENOMEM;

[Severity: Low]
Could pca9532_setled() be called before led_classdev_register() in the
PCA9532_TYPE_LED case, matching PCA9532_TYPE_N2100_BEEP below?

When pca9532_setled() fails after registration, led_classdev_unregister()
calls led_set_brightness(led_cdev, LED_OFF) and flushes
set_brightness_work, which invokes pca9532_set_brightness() ->
pca9532_setled() a second time against the failing I2C device.

Also, both new "goto exit;" lines are indented with spaces instead of a
tab.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128234104.242580-1-t3127430@gmail.com?part=1

  reply	other threads:[~2026-11-28 23:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 23:41 [PATCH v3] leds: pca9532: Propagate I2C errors Daniil Demakov
2026-11-28 23:50 ` sashiko-bot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-11-14 17:24 [PATCH v2] " Daniil Demakov
2026-11-14 18:14 ` [PATCH v3] " Daniil Demakov
2026-11-14 18:31   ` sashiko-bot

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-239153@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox