From: sashiko-bot@kernel.org
To: "Jie Gu" <jie.gu@leica-geosystems.com>
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH v2 2/2] leds: tps6131x: Clear torch brightness cache on flash takeover
Date: Fri, 20 Nov 2026 08:09:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-224684@kernel.org> (raw)
In-Reply-To: <20261120075859.731257-3-jie.gu@leica-geosystems.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] leds: tps6131x: race between torch brightness work and flash
takeover
- [Low] leds: tps6131x: stale torch brightness on error in
tps6131x_strobe_set()
--
commit 97db4f98d0889a2079f12eddeb42ef27c0ba097d
Author: Jie Gu <jie.gu@leica-geosystems.com.cn>
leds: tps6131x: Clear torch brightness cache on flash takeover
This commit resets fled_cdev->led_cdev.brightness to LED_OFF when
switching to flash or shutdown mode in tps6131x_strobe_set() and
tps6131x_flash_external_strobe_set().
> diff --git a/drivers/leds/flash/leds-tps6131x.c b/drivers/leds/flash/leds-tps6131x.c
> index 704c3e7dfcda0..76f452842f1bd 100644
> --- a/drivers/leds/flash/leds-tps6131x.c
> +++ b/drivers/leds/flash/leds-tps6131x.c
> @@ -398,6 +398,8 @@ static int tps6131x_strobe_set(struct led_classdev_flash *fled_cdev, bool state)
> if (ret)
> return ret;
>
> + fled_cdev->led_cdev.brightness = LED_OFF;
> +
> return 0;
> }
>
[Severity: Low]
Can fled_cdev->led_cdev.brightness remain stale if one of the subsequent
TPS6131X_REG_3 writes in tps6131x_strobe_set() fails?
tps6131x_set_mode() has already switched the hardware out of
TPS6131X_MODE_TORCH before the TPS6131X_REG_3_SFT updates run, so an early
return on those writes leaves the torch off while brightness still reports
the old non-zero value. In addition, both tps6131x_strobe_set() and
tps6131x_flash_external_strobe_set() cancel torch_refresh_work before
calling tps6131x_set_mode(), so if tps6131x_set_mode() itself fails, the
13-second hardware watchdog will shut the torch down without brightness
being cleared.
> @@ -697,12 +699,19 @@ static int tps6131x_flash_external_strobe_set(struct v4l2_flash *v4l2_flash, boo
> {
> struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;
> struct tps6131x *tps6131x = fled_cdev_to_tps6131x(fled_cdev);
> + int ret;
>
> cancel_delayed_work_sync(&tps6131x->torch_refresh_work);
> guard(mutex)(&tps6131x->lock);
>
> - return tps6131x_set_mode(tps6131x, enable ? TPS6131X_MODE_FLASH : TPS6131X_MODE_SHUTDOWN,
> - false);
> + ret = tps6131x_set_mode(tps6131x, enable ? TPS6131X_MODE_FLASH : TPS6131X_MODE_SHUTDOWN,
> + false);
> + if (ret)
> + return ret;
> +
> + fled_cdev->led_cdev.brightness = LED_OFF;
> +
> + return 0;
> }
>
> static const struct v4l2_flash_ops tps6131x_v4l2_flash_ops = {
[Severity: Medium]
Can a concurrent torch brightness update re-enable TPS6131X_MODE_TORCH
after tps6131x_strobe_set() or tps6131x_flash_external_strobe_set() sets
fled_cdev->led_cdev.brightness to LED_OFF?
Because tps6131x uses brightness_set_blocking, led_set_brightness_nosleep()
updates led_cdev->brightness and queues set_brightness_work asynchronously.
In addition, cancel_delayed_work_sync(&tps6131x->torch_refresh_work) runs
before acquiring tps6131x->lock, while tps6131x_brightness_set() schedules
torch_refresh_work under tps6131x->lock:
CPU0 (leds_wq) CPU1 (strobe / v4l2_flash)
tps6131x_brightness_set()
guard(mutex)(&tps6131x->lock)
tps6131x_set_mode(...,
TPS6131X_MODE_TORCH, true)
tps6131x_strobe_set()
cancel_delayed_work_sync(
&tps6131x->torch_refresh_work)
schedule_delayed_work(
&tps6131x->torch_refresh_work,
...)
guard(mutex)(&tps6131x->lock)
tps6131x_set_mode(...,
TPS6131X_MODE_FLASH, true)
fled_cdev->led_cdev.brightness = LED_OFF
tps6131x_torch_refresh_handler()
tps6131x_set_mode(...,
TPS6131X_MODE_TORCH, true) <-- forces torch back on while brightness is 0
Similarly, if set_brightness_work was already queued with a non-zero
delayed_set_value before the strobe callback ran, set_brightness_delayed()
can execute tps6131x_brightness_set() right after the strobe callback
clears fled_cdev->led_cdev.brightness, turning the hardware torch on while
sysfs brightness stays at LED_OFF.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120075859.731257-1-jie.gu@leica-geosystems.com?part=2
prev parent reply other threads:[~2026-11-20 8:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 7:58 [PATCH v2 0/2] leds: tps6131x: Fix torch-to-flash transitions Jie Gu
2026-11-20 7:58 ` [PATCH v2 1/2] leds: tps6131x: Cancel torch refresh on flash mode switch Jie Gu
2026-11-20 8:09 ` sashiko-bot
2026-11-20 7:58 ` [PATCH v2 2/2] leds: tps6131x: Clear torch brightness cache on flash takeover Jie Gu
2026-11-20 8:09 ` 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-224684@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jie.gu@leica-geosystems.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