From: sashiko-bot@kernel.org
To: jiegu <jie.gu@leica-geosystems.com>
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH 2/2] leds: tps6131x: clear torch brightness cache on flash takeover
Date: Tue, 17 Nov 2026 07:03:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-218289@kernel.org> (raw)
In-Reply-To: <20261117064328.4096518-3-jie.gu@leica-geosystems.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] leds: tps6131x: Signed-off-by trailer uses handle instead of
real name
- [Medium] leds: tps6131x: race between torch brightness work and flash
takeover
- [Low] leds: tps6131x: missing Fixes trailer for commit b338a2ae9b31
- [Low] leds: tps6131x: lowercase commit subject description after
prefix
- [Low] leds: tps6131x: stale torch brightness on error in
tps6131x_strobe_set()
--
commit f89ca151830eb0b217f7a4d48fff59fc543e3ca3
Author: gujie <jie.gu@leica-geosystems.com.cn>
> leds: tps6131x: clear torch brightness cache on flash takeover
[Severity: Low]
Per LED subsystem conventions, the description after the "leds: tps6131x: "
prefix should be capitalized ("leds: tps6131x: Clear torch brightness cache
on flash takeover").
>
> When the device switches from torch mode to flash or external strobe
> mode, the hardware torch output is disabled, but the LED class
> brightness cache may still keep the previous non-zero torch value.
>
> This leaves sysfs brightness reporting an enabled torch state even
> though the light is already off.
>
> Update the cached LED brightness to LED_OFF when flash control takes
> over so userspace state matches the actual hardware state.
>
> Signed-off-by: gujie <jie.gu@leica-geosystems.com.cn>
[Severity: High]
The Signed-off-by trailer and Author header use a single-word handle
("gujie") instead of a full real human name, which does not meet the
Developer's Certificate of Origin requirements in
Documentation/process/submitting-patches.rst.
[Severity: Low]
Since this fixes a bug introduced with the driver, should it include a
Fixes tag?
Fixes: b338a2ae9b31 ("leds: tps6131x: Add support for Texas Instruments TPS6131X flash LED driver")
> diff --git a/drivers/leds/flash/leds-tps6131x.c b/drivers/leds/flash/leds-tps6131x.c
> index 704c3e7dfcda0..4b36fd2e3778b 100644
> --- a/drivers/leds/flash/leds-tps6131x.c
> +++ b/drivers/leds/flash/leds-tps6131x.c
> @@ -294,6 +294,11 @@ static int tps6131x_set_mode(struct tps6131x *tps6131x, enum tps6131x_mode mode,
> NULL, false, force);
> }
>
> +static void tps6131x_sync_torch_brightness_off(struct tps6131x *tps6131x)
> +{
> + tps6131x->fled_cdev.led_cdev.brightness = LED_OFF;
> +}
> +
> static void tps6131x_torch_refresh_handler(struct work_struct *work)
> {
> struct tps6131x *tps6131x = container_of(work, struct tps6131x, torch_refresh_work.work);
> @@ -398,6 +403,8 @@ static int tps6131x_strobe_set(struct led_classdev_flash *fled_cdev, bool state)
> if (ret)
> return ret;
>
> + tps6131x_sync_torch_brightness_off(tps6131x);
> +
> return 0;
> }
[Severity: Low]
Can fled_cdev.led_cdev.brightness still remain stale if a TPS6131X_REG_3
update fails in tps6131x_strobe_set()?
drivers/leds/flash/leds-tps6131x.c:tps6131x_strobe_set() {
...
ret = tps6131x_set_mode(tps6131x, state ? TPS6131X_MODE_FLASH : TPS6131X_MODE_SHUTDOWN,
true);
if (ret < 0)
return ret;
if (state) {
ret = regmap_update_bits_base(tps6131x->regmap, TPS6131X_REG_3, TPS6131X_REG_3_SFT,
TPS6131X_REG_3_SFT, NULL, false, true);
if (ret)
return ret;
}
...
}
Once tps6131x_set_mode() succeeds, the hardware torch output is already
disabled. If either subsequent regmap_update_bits_base() call on
TPS6131X_REG_3 fails, returning before tps6131x_sync_torch_brightness_off()
leaves fled_cdev.led_cdev.brightness reporting a non-zero torch value while
the torch is off. Similarly, because cancel_delayed_work_sync() runs
before tps6131x_set_mode() here and in tps6131x_flash_external_strobe_set(),
a failure in tps6131x_set_mode() leaves torch_refresh_work canceled so the
hardware watchdog shuts the torch down after 13 seconds without updating
fled_cdev.led_cdev.brightness.
> @@ -697,12 +704,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;
> +
> + tps6131x_sync_torch_brightness_off(tps6131x);
> +
> + return 0;
> }
[Severity: Medium]
Can a concurrent torch brightness update race with flash takeover and
re-enable hardware torch mode after fled_cdev.led_cdev.brightness has been
reset to LED_OFF?
Because tps6131x_led_class_setup() registers brightness_set_blocking,
writing a non-zero value to sysfs brightness updates led_cdev.brightness
immediately and queues set_brightness_work to run tps6131x_brightness_set()
asynchronously. In addition, tps6131x_strobe_set() and
tps6131x_flash_external_strobe_set() call cancel_delayed_work_sync() on
torch_refresh_work before acquiring tps6131x->lock, whereas
tps6131x_brightness_set() schedules torch_refresh_work under tps6131x->lock:
CPU0 (kworker) CPU1 (strobe / v4l2)
tps6131x_brightness_set()
guard(mutex)(&tps6131x->lock)
tps6131x_set_mode(..., TORCH)
tps6131x_strobe_set()
cancel_delayed_work_sync(...)
guard(mutex)(&tps6131x->lock)
schedule_delayed_work(...)
tps6131x_set_mode(..., FLASH)
tps6131x_sync_torch_brightness_off()
led_cdev.brightness = LED_OFF
tps6131x_torch_refresh_handler()
tps6131x_set_mode(..., TORCH) <-- torch re-enabled while brightness == 0
The same mismatch happens if set_brightness_work runs
tps6131x_brightness_set() with a queued non-zero delayed_set_value right
after tps6131x_strobe_set() or tps6131x_flash_external_strobe_set() clears
led_cdev.brightness: the hardware switches back to TPS6131X_MODE_TORCH
while sysfs brightness still reports LED_OFF.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117064328.4096518-1-jie.gu@leica-geosystems.com?part=2
prev parent reply other threads:[~2026-11-17 7:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 6:43 [PATCH 0/2] leds: tps6131x: Fix torch-to-flash transitions jiegu
2026-11-17 6:43 ` [PATCH 1/2] leds: tps6131x: cancel torch refresh on flash mode switch jiegu
2026-11-17 7:04 ` sashiko-bot
2026-11-17 6:43 ` [PATCH 2/2] leds: tps6131x: clear torch brightness cache on flash takeover jiegu
2026-11-17 7:03 ` 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-218289@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