From: Nikolay Plastinin via B4 Relay <devnull+plaztininikolai.gmail.com@kernel.org>
To: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>
Cc: Hans de Goede <hansg@kernel.org>,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
Nikolay Plastinin <plaztininikolai@gmail.com>
Subject: [PATCH v3 1/2] leds: triggers: Add led_trigger_for_each_led()
Date: Fri, 16 Oct 2026 02:56:49 +0800 [thread overview]
Message-ID: <20261016-leds-input-events-brightness-v3-1-2c462cafe020@gmail.com> (raw)
In-Reply-To: <20261016-leds-input-events-brightness-v3-0-2c462cafe020@gmail.com>
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)
+
/*
* Currently the attributes in struct led_trigger::groups are added directly to
* the LED device. As this might change in the future, the following
--
2.56.0
next prev parent reply other threads:[~2026-10-15 18:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 18:56 [PATCH v3 0/2] leds: trigger: input-events: Restore previous brightness on input Nikolay Plastinin via B4 Relay
2026-10-15 18:56 ` Nikolay Plastinin via B4 Relay [this message]
2026-10-15 18:56 ` [PATCH v3 2/2] " Nikolay Plastinin via B4 Relay
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=20261016-leds-input-events-brightness-v3-1-2c462cafe020@gmail.com \
--to=devnull+plaztininikolai.gmail.com@kernel.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
all inboxes | Powered by JetHome®