mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/2] leds: trigger: input-events: Restore previous brightness on input
@ 2026-10-30 13:51 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:51 ` [PATCH v4 2/2] leds: trigger: input-events: Restore previous brightness on input Nikolay Plastinin via B4 Relay
  0 siblings, 2 replies; 3+ messages in thread
From: Nikolay Plastinin via B4 Relay @ 2026-10-30 13:51 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek
  Cc: Hans de Goede, linux-leds, linux-kernel, Nikolay Plastinin

The input-events trigger turns LEDs back on with LED_FULL, so a keyboard
backlight with several levels always comes back at maximum after being
idle. This series restores the level the user picked instead.

Patch 1 adds led_trigger_for_each_led(), an RCU list iterator in leds.h.
Patch 2 uses it to save and restore each LED's brightness in one loop,
with per-LED state allocated in activate() and freed in deactivate().
There is no new exported function or callback API.

This came up while looking at a keyboard backlight idle timeout for ASUS
laptops in asusctl:
https://github.com/OpenGamingCollective/asusctl/issues/98

Validation for v4: the module builds out of tree with W=1 against Fedora
7.2.12-200.fc44.x86_64 using the patched leds.h. A user-space harness using
the driver functions reproduces a heap-use-after-free with v3 when the
LED remains in the iteration after deactivate(), modelling the
attribute-creation error path. With v4, the same test, brightness restore,
and 10,000 concurrent deactivate/reinitialise cycles pass ASan/UBSan.
The harness substitutes mutexes and a one-element list for kernel
primitives; it is not kernel fault injection or an RCU implementation test.

V4 was tested on an ASUS ROG Flow X13 GV302XV with kernel
7.2.12-200.fc44.x86_64 and no external monitor: brightness levels 1 and 2
were restored after idle timeout and keyboard input, and 20 trigger
activate/deactivate cycles passed. No kernel messages appeared during
the test. The original brightness and trigger were restored afterwards.
No full kernel build has been performed.

LLM assistance was used for the implementation, tests and message drafts.

---
Changes in v4:
- Clear trigger_data under input_events_data.lock before freeing per-LED
  state in deactivate(), as suggested by Lee Jones. This also covers the
  device_add_groups() error path, which deactivates before list removal.
- Update the NULL-state comment to cover activation error unwind.
- Patch 1 is unchanged.
- Link to v3: https://lore.kernel.org/r/20261016-leds-input-events-brightness-v3-0-2c462cafe020@gmail.com

Changes in v3:
- Replace led_trigger_walk_leds() with led_trigger_for_each_led(), an
  RCU list iterator in include/linux/leds.h, as suggested by Lee Jones.
- Remove the exported helper, callback typedef, and void-pointer argument.
- Keep saving and restoring brightness in input_events_set_leds(), using
  guard(rcu)() and a single loop for both the on and off paths.
- Link to v2: https://lore.kernel.org/r/20260930-leds-input-events-brightness-v2-0-3948d3cddd83@gmail.com

Changes in v2:
- Keep the saved brightness in a per-LED struct allocated in activate()
  and freed in deactivate(), stored in led_cdev->trigger_data, instead of
  overloading blink_brightness (Lee Jones).
- Add led_trigger_walk_leds() to led-triggers.c and use it instead of
  walking led_cdevs/trig_list from the trigger (Lee Jones).
- Use the Assisted-by tag format from coding-assistants.rst.
- Link to v1: https://lore.kernel.org/r/20260924-leds-input-events-brightness-v1-1-b0ceff3a2343@gmail.com

---
Nikolay Plastinin (2):
      leds: triggers: Add led_trigger_for_each_led()
      leds: trigger: input-events: Restore previous brightness on input

 drivers/leds/trigger/ledtrig-input-events.c | 76 ++++++++++++++++++++++++++---
 include/linux/leds.h                        | 12 +++++
 2 files changed, 82 insertions(+), 6 deletions(-)
---
base-commit: f475845eaf3d749114a63270bf2efea459e14dd2
change-id: 20260924-leds-input-events-brightness-a76ae9a77b85

Best regards,
-- 
Nikolay Plastinin <plaztininikolai@gmail.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-30 13:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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:51 ` [PATCH v4 2/2] leds: trigger: input-events: Restore previous brightness on input Nikolay Plastinin via B4 Relay

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®