From: sashiko-bot@kernel.org
To: "Joseph Telaak" <joseph@telaak.dev>
Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org, lee@kernel.org
Subject: Re: [PATCH v3 11/11] leds: rgb: ktd202x: Don't let a blinking LED retime another one
Date: Fri, 20 Nov 2026 00:25:42 +0000 [thread overview]
Message-ID: <sashiko-outbox-224266@kernel.org> (raw)
In-Reply-To: <20261119-ktd202x-et6326-v3-11-98b836b1cddc@telaak.dev>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] leds: rgb: ktd202x: race on cdev.brightness in
ktd202x_chip_in_use()
--
commit 53a1322c29ce0429d0f7e6ad7328dce239f5bd4f
Author: Joseph Telaak <joseph@telaak.dev>
leds: rgb: ktd202x: Don't let a blinking LED retime another one
This commit tracks which LEDs on a ktd202x chip are using the shared PWM1
flash timer, rejects incompatible concurrent timer requests with -EBUSY,
and holds the chip mutex across setting brightness and programming the
timer.
> diff --git a/drivers/leds/rgb/leds-ktd202x.c b/drivers/leds/rgb/leds-ktd202x.c
> index c9f1a5234d6e2..2e84fed016f9f 100644
> --- a/drivers/leds/rgb/leds-ktd202x.c
> +++ b/drivers/leds/rgb/leds-ktd202x.c
[ ... ]
> @@ -266,26 +264,46 @@ static int ktd202x_brightness_set(struct ktd202x_led *led,
> return 0;
> }
>
> -static int ktd202x_brightness_single_set(struct led_classdev *cdev,
> - enum led_brightness value)
> +/* Called with the chip mutex held */
> +static int __ktd202x_brightness_single_set(struct ktd202x_led *led,
> + enum led_brightness value)
> {
> - struct ktd202x_led *led = container_of(cdev, struct ktd202x_led, cdev);
> struct mc_subled info;
> - int ret;
> -
> - cdev->brightness = value;
>
> - mutex_lock(&led->chip->mutex);
> + led->cdev.brightness = value;
>
> info.brightness = value;
> info.channel = led->index;
> - ret = ktd202x_brightness_set(led, &info, 1);
>
> + return ktd202x_brightness_set(led, value, &info, 1);
> +}
[ ... ]
> @@ -427,7 +519,21 @@ static int ktd202x_blink_single_set(struct led_classdev *cdev,
> if (!*delay_on)
> return ktd202x_brightness_single_set(cdev, LED_OFF);
>
> - info.brightness = cdev->brightness;
> + guard(mutex)(&led->chip->mutex);
> +
> + /*
> + * The LED core may have changed the brightness without the chip mutex
> + * and not applied it yet, so read it once and apply it here. An unlit
> + * LED blinks at the brightness of a software blink, which may be in its
> + * off phase, or else at full brightness.
> + */
> + brightness = READ_ONCE(cdev->brightness) ?: cdev->blink_brightness ?: cdev->max_brightness;
> +
> + ret = __ktd202x_brightness_single_set(led, brightness);
> + if (ret)
> + return ret;
> +
> + info.brightness = brightness;
> info.channel = led->index;
>
> return ktd202x_blink_set(led, delay_on, delay_off, &info, 1);
[Severity: Medium]
Can a concurrent unlocked write to cdev->brightness in the LED core cause
ktd202x_brightness_set() to disable the chip right before
ktd202x_blink_set() or ktd202x_timer_set() programs the timer?
ktd202x_chip_in_use() still determines whether the chip is active by
reading chip->leds[i].cdev.brightness:
drivers/leds/rgb/leds-ktd202x.c:ktd202x_chip_in_use() {
for (i = 0; i < chip->num_leds; i++) {
if (chip->leds[i].cdev.brightness)
return true;
}
return false;
}
Because led_set_brightness_nosleep() updates led_cdev->brightness without
holding chip->mutex before queuing set_brightness_work, a concurrent
LED_OFF update can zero cdev.brightness after
__ktd202x_brightness_single_set() sets it:
CPU0 CPU1
ktd202x_blink_single_set()
guard(mutex)(&led->chip->mutex)
__ktd202x_brightness_single_set()
led->cdev.brightness = brightness
ktd202x_brightness_set()
ktd202x_chip_enable()
regmap_write(..., IOUT, ...)
led_set_brightness(cdev, LED_OFF)
led_set_brightness_nosleep()
cdev->brightness = 0
queue_work(set_brightness_work)
if (!ktd202x_chip_in_use(chip))
ktd202x_chip_disable()
ktd202x_blink_set()
ktd202x_timer_set()
regmap_write(...) <-- writes to sleeping/unpowered chip
If no other LED on the chip is lit, ktd202x_brightness_set() puts the chip
to sleep and disables its regulators, and ktd202x_timer_set() (in the
single/mc blink and pattern callbacks) then writes the timer and channel
registers over I2C to the unpowered chip.
The same race occurs when two lit LEDs on the chip are turned off together
(for instance via led_trigger_event(trig, LED_OFF)): both cdev.brightness
fields are zeroed before the first LED's set_brightness_work finishes, so
the first LED disables the chip and regulators before the second LED's
ktd202x_brightness_set() writes KTD202X_REG_CHANNEL_CTRL. Tracking each
LED's applied hardware brightness under chip->mutex and checking that in
ktd202x_chip_in_use() would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-ktd202x-et6326-v3-0-98b836b1cddc@telaak.dev?part=11
prev parent reply other threads:[~2026-11-20 0:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 0:07 [PATCH v3 00/11] leds: ktd202x: Add Etek ET6326, hardware breathing and fixes Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 01/11] leds: rgb: ktd202x: Fix the flash period of short blinks on 32 bit Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 02/11] leds: rgb: ktd202x: Fix an out-of-bounds read with unused channels Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 03/11] leds: rgb: ktd202x: Never program an on time of zero Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 04/11] leds: rgb: ktd202x: Fix a division by zero with long blinks Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 05/11] leds: rgb: ktd202x: Keep the unlit colors of a blinking LED off Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 06/11] dt-bindings: leds: kinetic,ktd202x: Add Etek ET6326 Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 07/11] leds: rgb: ktd202x: Add Etek ET6326 support Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 08/11] leds: rgb: ktd202x: Add hardware pattern support Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 09/11] leds: rgb: ktd202x: Limit the LED current to led-max-microamp Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 10/11] leds: rgb: ktd202x: Fail the probe when the chip does not answer Joseph Telaak via B4 Relay
2026-11-20 0:07 ` [PATCH v3 11/11] leds: rgb: ktd202x: Don't let a blinking LED retime another one Joseph Telaak via B4 Relay
2026-11-20 0:25 ` sashiko-bot [this message]
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-224266@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=joseph@telaak.dev \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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