From: sashiko-bot@kernel.org
To: "Manuel Fombuena" <fombuena@outlook.com>
Cc: lee@kernel.org, linux-leds@vger.kernel.org
Subject: Re: [PATCH v6 2/9] leds: st1202: validate pattern input before stopping the sequence
Date: Thu, 02 Jul 2026 17:58:45 +0000 [thread overview]
Message-ID: <20260702175845.A1A311F000E9@smtp.kernel.org> (raw)
In-Reply-To: <GV1PR08MB84971EE254E4D7A3B0178039C5F52@GV1PR08MB8497.eurprd08.prod.outlook.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver improperly writes 8-bit brightness values directly into a 12-bit PWM register without scaling, resulting in extremely dim pattern output.
- [High] The driver implements the `.brightness_set` callback with a function that sleeps, violating LED subsystem requirements and causing a panic in atomic context.
- [High] Clearing one LED's pattern destructively resets the globally shared pattern sequencer and duration registers for all other LEDs.
--
commit 9797d63cea6ed2c2a29dd33d73d899810acde5ba
Author: Manuel Fombuena <fombuena@outlook.com>
leds: st1202: validate pattern input before stopping the sequence
Input validation for pattern duration is performed inside the write
loop, after the pattern sequence has already been stopped. This patch
moves all input validation before the mutex and before any hardware
interaction, so an invalid input leaves the chip state unchanged.
> diff --git a/drivers/leds/leds-st1202.c b/drivers/leds/leds-st1202.c
> index 316ed8eb054f9..a750c95ef3f89 100644
> --- a/drivers/leds/leds-st1202.c
> +++ b/drivers/leds/leds-st1202.c
> @@ -228,6 +228,12 @@ static int st1202_led_pattern_set(struct led_classdev *ldev,
> if (len > ST1202_MAX_PATTERNS)
> return -EINVAL;
>
> + for (int patt = 0; patt < len; patt++) {
> + if (pattern[patt].delta_t < ST1202_MILLIS_PATTERN_DUR_MIN ||
> + pattern[patt].delta_t > ST1202_MILLIS_PATTERN_DUR_MAX)
> + return -EINVAL;
> + }
> +
> guard(mutex)(&chip->lock);
>
> ret = st1202_write_reg(chip, ST1202_CONFIG_REG, ST1202_CONFIG_REG_SHFT);
> @@ -235,10 +241,6 @@ static int st1202_led_pattern_set(struct led_classdev *ldev,
> return ret;
>
> for (int patt = 0; patt < len; patt++) {
> - if (pattern[patt].delta_t < ST1202_MILLIS_PATTERN_DUR_MIN ||
> - pattern[patt].delta_t > ST1202_MILLIS_PATTERN_DUR_MAX)
> - return -EINVAL;
> -
> ret = st1202_pwm_pattern_write(chip, led->led_num, patt, pattern[patt].brightness);
[Severity: High]
This isn't a bug introduced by this patch, but does this function improperly
write 8-bit brightness values directly into a 12-bit PWM register without
scaling?
Because the input brightness value is bounded to max_brightness (255) by
the subsystem, the upper 8 bits in st1202_pwm_pattern_write() appear to
always be 0:
drivers/leds/leds-st1202.c:st1202_pwm_pattern_write() {
...
value_h = (u8)(value >> 8);
...
}
Will this result in extremely dim pattern output (maximum of 6.2% brightness)
and render the pattern feature functionally broken?
> if (ret != 0)
> return ret;
[ ... ]
Additionally, there are a few other pre-existing issues in this driver
that I noticed:
[Severity: High]
This is a pre-existing issue, but does the driver inappropriately register a
sleeping function as the non-blocking .brightness_set callback?
drivers/leds/leds-st1202.c:st1202_dt_init() {
...
led->led_cdev.brightness_set = st1202_brightness_set;
...
}
When a trigger (like the timer trigger) calls this from atomic context,
st1202_brightness_set() takes a mutex and performs I2C operations which can
sleep:
drivers/leds/leds-st1202.c:st1202_brightness_set() {
...
guard(mutex)(&chip->lock);
...
}
Will this cause a panic in atomic context? Should the driver only implement
.brightness_set_blocking to ensure the LED core defers the work to a
workqueue?
[Severity: High]
This is a pre-existing issue, but does clearing one LED's pattern
destructively reset the globally shared pattern sequencer for all other LEDs?
In st1202_led_pattern_clear(), it writes directly to the global configuration
register, disabling the pattern sequencer for all LEDs on the chip:
drivers/leds/leds-st1202.c:st1202_led_pattern_clear() {
...
ret = st1202_write_reg(chip, ST1202_CONFIG_REG, ST1202_CONFIG_REG_SHFT);
...
}
It also appears to blindly zero out the globally shared duration registers:
drivers/leds/leds-st1202.c:st1202_led_pattern_clear() {
...
ret = st1202_write_reg(chip, ST1202_PATTERN_DUR + patt, 0);
...
}
Will this corrupt any sequences currently running on other channels on the
same chip?
--
Sashiko AI review · https://sashiko.dev/#/patchset/GV1PR08MB84972A16ED557BFB96D63F57C5F52@GV1PR08MB8497.eurprd08.prod.outlook.com?part=2
next prev parent reply other threads:[~2026-07-02 17:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 17:33 [PATCH v6 0/9] leds: st1202: fix multiple bugs in pattern engine and brightness handling Manuel Fombuena
2026-07-02 17:36 ` [PATCH v6 1/9] leds: st1202: stop pattern sequence before reprogramming Manuel Fombuena
2026-07-02 17:55 ` sashiko-bot
2026-07-02 17:37 ` [PATCH v6 2/9] leds: st1202: validate pattern input before stopping the sequence Manuel Fombuena
2026-07-02 17:58 ` sashiko-bot [this message]
2026-07-02 17:37 ` [PATCH v6 3/9] leds: st1202: fix pattern duration prescaler and pattern_clear skip marker Manuel Fombuena
2026-07-02 17:55 ` sashiko-bot
2026-07-02 17:38 ` [PATCH v6 4/9] leds: st1202: set all pattern PWM slots to full after clearing pattern Manuel Fombuena
2026-07-02 17:55 ` sashiko-bot
2026-07-02 22:09 ` Manuel Fombuena
2026-07-02 17:39 ` [PATCH v6 5/9] leds: st1202: fix spurious pattern sequence start in setup Manuel Fombuena
2026-07-02 17:53 ` sashiko-bot
2026-07-02 17:41 ` [PATCH v6 6/9] leds: st1202: fix brightness having no effect while pattern mode is active Manuel Fombuena
2026-07-02 17:56 ` sashiko-bot
2026-07-02 21:58 ` Manuel Fombuena
2026-07-02 17:42 ` [PATCH v6 7/9] leds: st1202: disable channel when brightness is set to zero Manuel Fombuena
2026-07-02 17:58 ` sashiko-bot
2026-07-02 17:43 ` [PATCH v6 8/9] leds: st1202: validate LED reg property against channel count Manuel Fombuena
2026-07-02 18:02 ` sashiko-bot
2026-07-02 17:44 ` [PATCH v6 9/9] leds: st1202: correct and extend hw_pattern documentation Manuel Fombuena
2026-07-02 18:06 ` 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=20260702175845.A1A311F000E9@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