Linux LED subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Manuel Fombuena" <fombuena@outlook.com>
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH v5 1/1] leds: st1202: Add hardware-accelerated blink support
Date: Tue, 04 Aug 2026 10:52:53 +0000	[thread overview]
Message-ID: <20260804105253.C68661F000E9@smtp.kernel.org> (raw)
In-Reply-To: <GV1PR08MB849709A3BE3D1CBB9E28ABD2C5D42@GV1PR08MB8497.eurprd08.prod.outlook.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [High] Hardware-accelerated blink destructively alters the physical state of all other active LEDs by zeroing their PWM slots.
- [Medium] Hardware blink overrides user-configured brightness by hardcoding maximum intensity.
- [Medium] Updating LED brightness indiscriminately breaks an active hardware blink configuration.

Pre-existing issues:
- [High] The driver incorrectly assigns a sleeping function to the non-blocking `brightness_set` callback, causing 'scheduling while atomic' panics.
- [High] Dangling `fwnode` pointers due to un-incremented scoped device node reference.
--

--- Patch [1]: [PATCH v5 1/1] leds: st1202: Add hardware-accelerated blink support ---
commit c3a88eb697aa140ded0dcf2250d8f8ad71aa79ac
Author: Manuel Fombuena <fombuena@outlook.com>

leds: st1202: Add hardware-accelerated blink support

Implement blink_set() to enable hardware-accelerated blinking via the timer
trigger. Requested delays are clamped to the hardware range and the LED1202
pattern sequencer is configured globally.

> diff --git a/drivers/leds/leds-st1202.c b/drivers/leds/leds-st1202.c
> --- a/drivers/leds/leds-st1202.c
> +++ b/drivers/leds/leds-st1202.c
[ ... ]
> +static int st1202_blink_set(struct led_classdev *led_cdev,
> +			unsigned long *delay_on, unsigned long *delay_off)
> +{
[ ... ]
> +	/* Zero out PWM for all other active channels to prevent them from blinking */
> +	for (int i = 0; i < ST1202_MAX_LEDS; i++) {
> +		if (!chip->leds[i].is_active || i == led->led_num)
> +			continue;
> +		ret = st1202_pwm_pattern_write(chip, i, 0, LED_OFF);
> +		if (ret)
> +			return ret;
> +		ret = st1202_pwm_pattern_write(chip, i, 1, LED_OFF);
> +		if (ret)
> +			return ret;
> +	}

[Severity: High]
Does this loop destructively alter the physical state of all other active
LEDs?

Because the LED1202 hardware sequencer is a global resource, starting it
forces all channels to execute the sequence. Any LED that was previously set
to steady ON will output zero during these steps, causing it to go dark
while the kernel subsystem still believes it to be on.

> +
> +	ret = st1202_pwm_pattern_write(chip, led->led_num, 0, ST1202_PATTERN_PWM_FULL);

[Severity: Medium]
Can this override the user-configured brightness by hardcoding maximum
intensity?

The PWM slot is being forced to ST1202_PATTERN_PWM_FULL, and later the ILED
register is forced to U8_MAX, completely disregarding the
led_cdev->brightness value.

[ ... ]
> @@ -301,6 +380,7 @@ static int st1202_dt_init(struct st1202_chip *chip)
[ ... ]
>  		led = &chip->leds[reg];
>  		led->is_active = true;
>  		led->fwnode = of_fwnode_handle(child);

[Severity: High]
This is a pre-existing issue, but could this leave led->fwnode with a
dangling pointer?

The driver stores a pointer to this node from the scoped
for_each_available_child_of_node_scoped() loop, but fails to increment
its reference count via fwnode_handle_get(). When the scoped loop
drops the reference, the node may be freed, causing a use-after-free
when accessing the fwnode during class device registration or subsystem
operations.

>  
>  		led->led_cdev.max_brightness = U8_MAX;
>  		led->led_cdev.brightness_set_blocking = st1202_led_set;
>  		led->led_cdev.pattern_set = st1202_led_pattern_set;
>  		led->led_cdev.pattern_clear = st1202_led_pattern_clear;
>  		led->led_cdev.default_trigger = "pattern";
> +		led->led_cdev.blink_set = st1202_blink_set;

[Severity: Medium]
Would updating the LED brightness indiscriminately break an active hardware
blink configuration?

If a user changes the brightness while the LED is hardware-blinking,
st1202_brightness_set() unconditionally forces all 8 PWM pattern slots to
ST1202_PATTERN_PWM_FULL:

st1202_brightness_set() {
        ...
        for (int patt = 0; patt < ST1202_MAX_PATTERNS; patt++)
                st1202_pwm_pattern_write(chip, led->led_num, patt, 
                                         ST1202_PATTERN_PWM_FULL);
        ...
}

This overwrites the OFF step established by st1202_blink_set(), turning the
LED steadily ON while the subsystem still considers it to be blinking.

>  		led->led_cdev.brightness_set = st1202_brightness_set;

[Severity: High]
This is a pre-existing issue, but is it safe to assign a sleeping function
to the non-blocking brightness_set callback? 

st1202_brightness_set() acquires a mutex and performs sleepable I2C
operations:

st1202_brightness_set() {
        ...
        guard(mutex)(&chip->lock);
        ...
        st1202_write_reg(...)
}

The LED core assumes led_cdev.brightness_set does not sleep, calling it
directly from atomic contexts. This can cause scheduling while atomic
panics.

>  		led->led_cdev.brightness_get = st1202_brightness_get;
>  	}
>  
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/GV1PR08MB849709A3BE3D1CBB9E28ABD2C5D42@GV1PR08MB8497.eurprd08.prod.outlook.com?part=1

  reply	other threads:[~2026-08-04 10:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 10:39 [PATCH v5 0/1] leds: st1202: Add hardware-accelerated blink support Manuel Fombuena
2026-08-04 10:40 ` [PATCH v5 1/1] " Manuel Fombuena
2026-08-04 10:52   ` sashiko-bot [this message]
2026-08-04 15:41     ` Manuel Fombuena
2026-08-06 14:17   ` 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=20260804105253.C68661F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fombuena@outlook.com \
    --cc=lee@kernel.org \
    --cc=linux-leds@vger.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