From: Greg KH <gregkh@linuxfoundation.org>
To: plaztininikolai@gmail.com
Cc: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>,
Hans de Goede <hansg@kernel.org>,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/2] leds: triggers: Add led_trigger_for_each_led()
Date: Sat, 31 Oct 2026 11:23:13 +0100 [thread overview]
Message-ID: <2026103131-unharmed-dizzy-ade8@gregkh> (raw)
In-Reply-To: <20261030-leds-input-events-brightness-v4-1-5ea0ead7480c@gmail.com>
On Fri, Oct 30, 2026 at 09:51:31PM +0800, Nikolay Plastinin via B4 Relay wrote:
> From: Nikolay Plastinin <plaztininikolai@gmail.com>
>
> led_trigger_event() sets one brightness for all LEDs using a trigger.
> A trigger which restores a different brightness per LED needs to iterate
> over the attached LEDs instead.
>
> Add led_trigger_for_each_led(), a wrapper around list_for_each_entry_rcu(),
> so triggers can perform this iteration without spelling out the list
> members. Document that callers must hold the RCU read lock throughout
> the iteration and must not sleep while accessing the LEDs.
>
> Assisted-by: LLM
> Signed-off-by: Nikolay Plastinin <plaztininikolai@gmail.com>
> ---
> include/linux/leds.h | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/include/linux/leds.h b/include/linux/leds.h
> index a515f075c..675c58661 100644
> --- a/include/linux/leds.h
> +++ b/include/linux/leds.h
> @@ -11,6 +11,7 @@
> #include <dt-bindings/leds/common.h>
> #include <linux/device.h>
> #include <linux/mutex.h>
> +#include <linux/rculist.h>
> #include <linux/rwsem.h>
> #include <linux/spinlock.h>
> #include <linux/timer.h>
> @@ -502,6 +503,17 @@ struct led_trigger {
> const struct attribute_group **groups;
> };
>
> +/**
> + * led_trigger_for_each_led - iterate over the LEDs attached to a trigger
> + * @pos: struct led_classdev pointer used as the loop cursor
> + * @trig: trigger whose LEDs are iterated
> + *
> + * The caller must hold the RCU read lock throughout the iteration and must
> + * not sleep while accessing the LEDs.
> + */
> +#define led_trigger_for_each_led(pos, trig) \
> + list_for_each_entry_rcu(pos, &(trig)->led_cdevs, trig_list)
> +
No need for this when you are only using it in one place, AND you are
always going to forget to grab the rcu lock. Just "open code" it
please, that way driver authors don't get confused and use this
accidentally in the future.
thanks,
greg k-h
next prev parent reply other threads:[~2026-10-31 10:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 13:51 [PATCH v4 0/2] leds: trigger: input-events: Restore previous brightness on input Nikolay Plastinin via B4 Relay
2026-10-30 13:51 ` [PATCH v4 1/2] leds: triggers: Add led_trigger_for_each_led() Nikolay Plastinin via B4 Relay
2026-10-30 13:54 ` sashiko-bot
2026-10-31 10:23 ` Greg KH [this message]
2026-10-30 13:51 ` [PATCH v4 2/2] leds: trigger: input-events: Restore previous brightness on input Nikolay Plastinin via B4 Relay
2026-10-30 14:00 ` 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=2026103131-unharmed-dizzy-ade8@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=plaztininikolai@gmail.com \
/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