From: sashiko-bot@kernel.org
To: "Rong Zhang" <i@rong.moe>
Cc: lee@kernel.org, linux-leds@vger.kernel.org
Subject: Re: [PATCH] leds: core: Disable hardware control when writing brightness
Date: Sat, 11 Jul 2026 18:52:18 +0000 [thread overview]
Message-ID: <20260711185219.2BF991F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260712-leds-hw-control-brightness-set-v1-1-1de593b09d26@rong.moe>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] TOCTOU race in brightness_store() can cause unintended removal of a newly registered trigger.
--
--- Patch [1]: [PATCH] leds: core: Disable hardware control when writing brightness ---
commit 86a852e7c49262f7479b1653712185d4edd86c24
Author: Rong Zhang <i@rong.moe>
leds: core: Disable hardware control when writing brightness
This commit modifies the brightness sysfs attribute to disable hardware control
when written. It addresses an issue where the brightness attribute becomes
confusingly write-only while hardware control remains active.
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index a51b0ed538864..3e25e5fb63dc8 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -72,7 +72,7 @@ static ssize_t brightness_store(struct device *dev,
> if (ret)
> goto unlock;
>
> - if (state == LED_OFF)
> + if (state == LED_OFF || led_trigger_is_hw_controlled(led_cdev))
> led_trigger_remove(led_cdev);
[Severity: Medium]
Could this introduce a race condition that removes an unrelated trigger?
led_trigger_is_hw_controlled() takes and drops the read-side of trigger_lock:
drivers/leds/led-class.c:led_trigger_is_hw_controlled() {
...
guard(rwsem_read)(&led_cdev->trigger_lock);
return led_cdev->trigger && led_cdev->trigger->trigger_type;
}
Since the lock is dropped before led_trigger_remove() acquires the write-side
lock, is it possible for a concurrent thread to unregister the hardware
trigger and attach a new default trigger in the window between the check and
the removal?
If that sequence occurs, led_trigger_remove() might inadvertently remove the
newly attached trigger instead of the intended hardware trigger.
> led_set_brightness(led_cdev, state);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260712-leds-hw-control-brightness-set-v1-1-1de593b09d26@rong.moe?part=1
next prev parent reply other threads:[~2026-07-11 18:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-11 18:40 [PATCH] leds: core: Disable hardware control when writing brightness Rong Zhang
2026-07-11 18:52 ` sashiko-bot [this message]
2026-07-14 17:37 ` Rong Zhang
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=20260711185219.2BF991F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=i@rong.moe \
--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