HID: generic: add LampArray support via hid-lamparray helper
v6 cover HID: generic: add LampArray support via hid-lamparray helper
Add a new hid-lamparray helper module and integrate it with the hid-generic driver.
While more complex lamparray handling should be done in userspace via hidraw, providing a small module to add basic lamparray support makes it possible for userspace software to interact with lamparrays by simply using well-known APIs of the LED subsystem. One use-case would be to enable desktop environments to support keyboard backlight control out of the box for HID lamparray devices without having to implement the whole HID protocol themselves.
This patch is based on previous discussions:
https://lore.kernel.org/all/[email protected]/
The helper provides basic support for devices exposing a Lighting/LampArray application collection (usage page 0x59) and registers a single-zone RGB LED representation via the LED subsystem.
hid-generic now checks for LampArray support after hid_parse() and optionally registers a lamparray instance. Failures in the helper do not abort device probe to keep the driver logic otherwise unchanged.
LampArray resources are released on driver remove.
This commit was successfully tested on the Microsoft MacroPad reference implementation (https://github.com/microsoft/RP2040MacropadHidSample 1d6c3ad) and in combination with the tuxedo_nb04_wmi driver, albeit only fully functional with a recent fix posted to the LKML
(https://lore.kernel.org/all/[email protected]).
Others reported the driver to work on the Acer Predator PT14-52T and the ASUS Prime B650-Plus, with the former requiring some patches on top of v5, which should now be included in v6.
v6:
- Read attribute reports synchronously (by Cristian Mazotta)
- Raise log level of fatal probe errors (by Cristian Mazotta)
- Transfer control when use_leds_uapi changes (by Cristian Mazotta)
- Blank lamps across suspend and restore on resume (by Cristian Mazotta)
- Add quirk for devices that ignore intensities (reported by Armin Wolf)
- Better locking, fixing rare races in uapi registration
- Use scope guards for locking and allocations where possible
- Remove obsolete calls to led_mc_calc_color_components and hid_device_io_start/stop
- Updated and slightly improved documentation
v5:
- Proper hardware detection (no quirks necessary anymore)
- Add documentation for new sysfs knob
- Pass limits of the device to sysfs (intensities & brightness)
- More flexible Kconfig (use tristate)
- Improved locking
- Several memory leak and (de-)initialization fixes
- Don't read current color values from hardware (the HID spec does not offer this option)
- Remove redundant report dump functionality
v4:
- Restrict CONFIG_HID_LAMPARRAY to built-in configurations only to fix additional randconfig build errors
v3:
- Squash V1 and V2 into one patch
v2:
- Fix Kconfig to avoid build errors when LEDS_CLASS_MULTICOLOR is disabled
Aaron Erhardt (2):
HID: lamparray: add new LampArray helper module
HID: generic: add LampArray support via hid-lamparray helper
Cristian Mazzotta (1):
HID: lamparray: blank lamps across suspend and restore on resume
.../ABI/testing/sysfs-driver-hid-lamparray | 15 + drivers/hid/Kconfig | 18 + drivers/hid/Makefile | 2 + drivers/hid/hid-generic.c | 70 +- drivers/hid/hid-lamparray.c | 907 ++++++++++++++++++ include/linux/hid-lamparray.h | 117 +++ 6 files changed, 1128 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lamparray create mode 100644 drivers/hid/hid-lamparray.c create mode 100644 include/linux/hid-lamparray.h
Signature · 1 line
2.43.0
PATCH v6 1/3 HID: lamparray: add new LampArray helper module
Add a new hid-lamparray helper module that provides basic support for devices exposing a Lighting/LampArray application collection (usage page 0x59) and registers a single-zone RGB LED representation via the LED subsystem.
The module can be used as a library in HID drivers to add support for the HID LampArray protocol. While the API is quite basic as of now it could be extended in the future.
--- .../ABI/testing/sysfs-driver-hid-lamparray | 15 + drivers/hid/Kconfig | 17 + drivers/hid/Makefile | 2 + drivers/hid/hid-lamparray.c | 853 ++++++++++++++++++ include/linux/hid-lamparray.h | 88 ++ 5 files changed, 975 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lamparray create mode 100644 drivers/hid/hid-lamparray.c create mode 100644 include/linux/hid-lamparray.h
Documentation/ABI/testing/sysfs-driver-hid-lamparray new file +15 -0
@@ -0,0 +1,15 @@ +What: /sys/bus/hid/devices/<bus>:<vid>:<pid>.<n>/use_leds_uapi +Date: December 2026 +KernelVersion: 7.4 +Contact: [email protected] +Description: + If a driver uses the hid-lamparray module and a device supporting + LampArray is found, one multicolor LED class device is registered under + /sys/class/leds/rgb:<function> to expose the single-zone RGB control. + + Additionally, the use_leds_uapi sysfs attribute to control the LED class + device is attached directly to the HID device at + /sys/bus/hid/devices/<bus>:<vid>:<pid>.<n>/use_leds_uapi. Writing 0 to + use_leds_uapi unregisters the LED class device. The last state is kept + cached. Writing 1 registers it again and restores the cached state to + hardware.
drivers/hid/Kconfig +17 -0
@@ -92,6 +92,23 @@ config HID_GENERIC If unsure, say Y. +config HID_LAMPARRAY + tristate "HID LampArray helper" + depends on HID + depends on LEDS_CLASS_MULTICOLOR + default n + help + Helper for HID devices exposing a Lighting/LampArray collection. + Treats LampArray devices as a single-zone device and exposes a sysfs + interface for changing color and intensity values. Also exposes a + sysfs flag to be disabled e.g. by a userspace driver. + + This can be used as library in existing drivers. The generic HID + driver is extended by default to handle lamp array devices if this + option is enabled. + + If unsure, say N. + config HID_HAPTIC bool "Haptic touchpad support" default n
drivers/hid/Makefile +2 -0
@@ -13,6 +13,8 @@ obj-$(CONFIG_UHID) += uhid.o obj-$(CONFIG_HID_GENERIC) += hid-generic.o +obj-$(CONFIG_HID_LAMPARRAY) += hid-lamparray.o + hid-$(CONFIG_HIDRAW) += hidraw.o hid-logitech-y := hid-lg.o
drivers/hid/hid-lamparray.c new file +853 -0
853 lines not on this page · raw message
include/linux/hid-lamparray.h new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v6 1/3] HID: lamparray: add new LampArray helper module
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [High] hid: lamparray: out-of-bounds access on field->value array - [Medium] hid: lamparray: mixing goto…
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] hid: lamparray: out-of-bounds access on field->value array
- [Medium] hid: lamparray: mixing goto and scope-based cleanup
- [Medium] hid: lamparray: silent state update failures due to unverified shared reports
- [Medium] hid: lamparray: TOCTOU race in unregister leaves hardware in wrong state
- [Medium] hid: lamparray: error path fails to revert autonomous mode
- [Medium] hid: lamparray: data race on LED class device state
- [Medium] hid: lamparray: initialization race due to early sysfs exposure
- [Low] leds: lamparray: prints success log messages
--
commit dcca692c120b5bda2e0a125483a058dc7b60dad2
Author: Aaron Erhardt <[email protected]>
HID: lamparray: add new LampArray helper module
Add a new hid-lamparray helper module that provides basic support for devices exposing a Lighting/LampArray application collection. It registers a single-zone RGB LED representation via the LED subsystem.
Quoted 3 lines
drivers/hid/hid-lamparray.c new file +0
-0
[ ... ]
Quoted 10 lines
drivers/hid/hid-lamparray.c new file +10
-0+static int lamparray_read_attributes_report (struct lamparray_device *ldev) +{ +struct hid_device *hdev = ldev->hdev; +struct hid_report *report; +int ret; +size_t len; + +if (!ldev->lamp_count.field) { +hid_warn (hdev,"No LampCount field found\n" ); +return -ENODEV ;
drivers/hid/hid-lamparray.c line 183
Quoted 10 lines
drivers/hid/hid-lamparray.c new file +10
-0+ } + +if (!ldev->lamparray_kind.field) { +hid_warn (hdev,"No LampArrayKind field found\n" ); +return -ENODEV ; + } + + report = ldev->lamp_count.field->report; + +if (!report) {
[Severity: Medium]
Can lamparray_kind read stale or zeroed memory here? By only fetching the report associated with lamp_count, the lamparray_kind field may not be updated if it resides in a different HID report than lamp_count.
Quoted 3 lines
drivers/hid/hid-lamparray.c new file +3
-0+hid_warn (hdev,"LampCount field has no report\n" ); +return -ENODEV ; + }
[ ... ]
Quoted 12 lines
drivers/hid/hid-lamparray.c new file +12
-0+static int lamparray_parse_update_report (struct lamparray_device *ldev) +{ +struct hid_device *hdev = ldev->hdev; +struct hid_report_enum *re; +struct hid_report *report; +struct hid_field *field; +int i, j; +int ret =0 ; + + re = &hdev->report_enum[HID_FEATURE_REPORT ]; + +list_for_each_entry (report, &re->report_list, list) {
drivers/hid/hid-lamparray.c line 240
Quoted 10 lines
drivers/hid/hid-lamparray.c new file +10
-0+for (i =0 ; i < report->maxfield; i++) { + field = report->field[i]; +if (!field) +continue ; + +if (!field->usage || !field->maxusage) +continue ; + +for (j =0 ; j < field->maxusage; j++) { +u32 usage = field->usage[j].hid;
[Severity: High]
Could this loop overflow the field->value array? The loop iterates up to field->maxusage, storing the loop index in the field_value structs. However, the field->value array is allocated by the HID core based on field->report_count. If a crafted HID descriptor specifies a maxusage larger than report_count, the subsequent reads and writes in get_field_value() and set_field_value() can overflow the array.
Quoted 2 lines
drivers/hid/hid-lamparray.c new file +2
-0+u32 collection_idx = field->usage[j].collection_index; +u32 collection_usage = hdev->collection[collection_idx].usage;
[ ... ]
Quoted 13 lines
drivers/hid/hid-lamparray.c new file +13
-0+static int lamparray_hw_set_state (struct lamparray_device *ldev,u8 r,u8 g, +u8 b,u8 intensity) +{ +struct hid_device *hdev = ldev->hdev; +struct hid_report *report; + +if (!lamparray_color_fields_is_complete (&ldev->color_update)) +return -ENODEV ; + +if (ldev->range_start.field && ldev->range_end.field) { +set_field_value (&ldev->range_start,0 ); +set_field_value (&ldev->range_end, ldev->lamp_count_value -1 ); + }
drivers/hid/hid-lamparray.c line 366
Quoted 10 lines
drivers/hid/hid-lamparray.c new file +10
-0+ +set_field_value (&ldev->color_update.red, r); +set_field_value (&ldev->color_update.green, g); +set_field_value (&ldev->color_update.blue, b); +set_field_value (&ldev->color_update.intensity, intensity); + + report = ldev->color_update.red.field->report; +hid_hw_request (hdev, report,HID_REQ_SET_REPORT ); + +return 0 ;
[Severity: Medium]
Does this drop updates for the other color channels and range fields? If green, blue, intensity, or the range fields reside in a different report than the red field, sending only color_update.red.field->report will skip their updates.
Quoted 1 line
+}
[ ... ]
Quoted 10 lines
drivers/hid/hid-lamparray.c new file +10
-0+static int lamparray_restore_state (struct lamparray_device *ldev) +{ +u8 r, g, b; +int ret; +enum led_brightness brightness; + +if (!ldev->use_leds_uapi) +return 0 ; + +guard (mutex)(&ldev->dev_lock);
drivers/hid/hid-lamparray.c line 450
Quoted 10 lines
drivers/hid/hid-lamparray.c new file +10
-0+ + r = ldev->last_r; + g = ldev->last_g; + b = ldev->last_b; + brightness = ldev->last_brightness; + + ldev->mc_cdev.subled_info[0 ].intensity = r; + ldev->mc_cdev.subled_info[1 ].intensity = g; + ldev->mc_cdev.subled_info[2 ].intensity = b; + ldev->mc_cdev.led_cdev.brightness = brightness;
[Severity: Medium]
Can these updates race with concurrent sysfs writes? Modifying these LED class device fields without holding the led_cdev->led_access mutex while the sysfs interface is active can cause inconsistent brightness or color states if userspace writes to them simultaneously.
Quoted 5 lines
drivers/hid/hid-lamparray.c new file +5
-0+ +/* +* Quirk for devices ignoring intensity values, see +* lamparray_led_brightness_set for more information. +*/
[ ... ]
Quoted 23 lines
drivers/hid/hid-lamparray.c new file +23
-0+static ssize_t use_leds_uapi_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct lamparray_device *ldev =lamparray_ldev_from_sysfs_dev (dev); +bool val, old_val; +int ret; + +if (!ldev) +return -ENODEV ; + + ret =kstrtobool (buf, &val); +if (ret) +return ret; + +/* Make sure only one concurrent write is possible */ +guard (mutex)(&ldev->sysfs_lock); + old_val = ldev->use_leds_uapi; + +if (val == old_val) +return count; + + ldev->use_leds_uapi = val;
drivers/hid/hid-lamparray.c line 651
Quoted 10 lines
drivers/hid/hid-lamparray.c new file +10
-0+ +/* +* Take the device out of autonomous mode before exposing the LED +* class device, and hand it back afterwards, so that control is +* transferred in both directions rather than only at probe. +*/ +if (val ==1 ) { + ret =lamparray_hw_set_autonomous (ldev, false); +if (ret) + goto err_revert;
[Severity: Medium]
Does this function mix goto-based error handling with scope-based cleanup? The cleanup subsystem guidelines request converting all resources to scope-based cleanup if using __free() or guard(). Mixing the paradigms in functions like lamparray_register() and use_leds_uapi_store() can create ownership semantics confusion.
Quoted 4 lines
drivers/hid/hid-lamparray.c new file +4
-0+ ret =lamparray_register_led (ldev); +if (ret) { +lamparray_hw_set_autonomous (ldev, true); + goto err_revert;
[ ... ]
Quoted 15 lines
drivers/hid/hid-lamparray.c new file +15
-0+struct lamparray * +lamparray_register (struct hid_device *hdev, +const struct lamparray_init_state *led_init_state) +{ +int ret; +struct lamparray_device *ldev; + +if (!hdev) +return ERR_PTR (-ENODEV ); + + struct lamparray *la __free(kfree) = kzalloc_obj(*la, GFP_KERNEL); +if (!la) +return ERR_PTR (-ENOMEM ); + + ldev = &la->ldev;
[ ... ]
drivers/hid/hid-lamparray.c line 795
Quoted 10 lines
drivers/hid/hid-lamparray.c new file +10
-0+ ret =xa_err (xa_store (&lamparray_by_hdev, (unsigned long )hdev, ldev, +GFP_KERNEL )); +if (ret) + goto err_unregister_led; + + ret =lamparray_register_sysfs (ldev); +if (ret) + goto err_xa_erase; + + ret =lamparray_hw_set_autonomous (ldev, false);
[Severity: Medium]
Could exposing the sysfs file before hardware initialization completes create a race condition? If userspace writes 0 to use_leds_uapi right after this call, the store handler will unregister the LED and set autonomous to true. This probe thread then resumes, unconditionally setting autonomous to false and skipping lamparray_restore_state(), leaving the device in a broken state.
drivers/hid/hid-lamparray.c line 801
Quoted 6 lines
drivers/hid/hid-lamparray.c new file +6
-0+if (ret) { +hid_err (hdev,"Could not disable autonomous mode: %d" , ret); + goto err_remove_sysfs; + } + +hid_info (hdev,"LampArray device registered\n" );
[Severity: Low]
Should this log message be removed? The LED subsystem guidelines specify that drivers should only log errors or warnings, avoiding success messages on probe.
drivers/hid/hid-lamparray.c line 807
Quoted 6 lines
drivers/hid/hid-lamparray.c new file +6
-0+ + ret =lamparray_restore_state (ldev); +if (ret) { +hid_err (hdev,"Failed to set default state: %d" , ret); + goto err_remove_sysfs; + }
[Severity: Medium]
Does this error path leave the hardware in a non-autonomous state? If lamparray_restore_state() fails, the code jumps to err_remove_sysfs and cleans up software state, but does not revert the device back to autonomous mode.
Quoted 7 lines
drivers/hid/hid-lamparray.c new file +7
-0+ +return_ptr (la); + +err_remove_sysfs: +lamparray_remove_sysfs (ldev); +err_xa_erase: +xa_erase (&lamparray_by_hdev, (unsigned long )hdev);
[ ... ]
drivers/hid/hid-lamparray.c line 837
Quoted 12 lines
drivers/hid/hid-lamparray.c new file +12
-0+void lamparray_unregister (struct lamparray *la) +{ +struct lamparray_device *ldev; + +if (!la) +return ; + + ldev = &la->ldev; + +lamparray_hw_set_autonomous (ldev, true); + +lamparray_remove_sysfs (ldev);
[Severity: Medium]
Can this sequence permanently leave the hardware in a non-autonomous state? Calling lamparray_hw_set_autonomous(..., true) before removing the sysfs interface creates a window where a concurrent sysfs write to use_leds_uapi can switch the device back to non-autonomous mode right before the device is completely unregistered.
Quoted 4 lines
drivers/hid/hid-lamparray.c new file +4
-0+xa_erase (&lamparray_by_hdev, (unsigned long )ldev->hdev); + +mutex_lock (&ldev->sysfs_lock); +lamparray_unregister_led (ldev);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v6 2/3 HID: generic: add LampArray support via hid-lamparray helper
In reply to Aaron ErhardtThe hid-generic driver now checks for LampArray support after hid_parse() and optionally registers a lamparray instance. Failures in the helper do not abort device probe to keep the device unchanged.
LampArray resources are released on driver remove.
This patch was successfully tested on the Microsoft MacroPad reference implementation (https://github.com/microsoft/RP2040MacropadHidSample
1d6c3ad) and in combination with the tuxedo_nb04_wmi driver, albeit only functional with a recent fix posted to the LKML.
Link:
https://lore.kernel.org/all/[email protected]
--- drivers/hid/Kconfig | 1 + drivers/hid/hid-generic.c | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
drivers/hid/Kconfig +1 -0
@@ -82,6 +82,7 @@ config UHID config HID_GENERIC tristate "Generic HID driver" + depends on HID_LAMPARRAY if HID_LAMPARRAY default HID help Support for generic devices on the HID bus. This includes most
drivers/hid/hid-generic.c +41 -0
71 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v6 3/3 HID: lamparray: blank lamps across suspend and restore on resume
In reply to Aaron ErhardtFrom: Cristian Mazzotta <[email protected]>
The helper installs no PM callbacks, so lamps keep their last state across suspend. Firmware is not required to turn them off in low power states, and on devices where it does not, they stay lit for the whole suspend.
On an Acer Predator PT14-52T, system power draw during s2idle is 12.35W with the lamps lit and 2.84W with them blanked, measured at the charger.
Add lamparray_suspend(), which writes zeroes to the color channels while leaving the cached RGB and brightness untouched, and lamparray_resume(), which restores that cache. Both return early when use_leds_uapi is 0 so a userspace driver keeps full control. hid-generic gains suspend and resume callbacks to drive them, and calls lamparray_resume() from reset_resume as well.
Some devices return to firmware control across a hibernate transition while still reporting AutonomousMode = 0, and ignore host lamp updates until the value genuinely transitions. Force a 1 -> 0 on resume before restoring state.
--- drivers/hid/hid-generic.c | 29 ++++++++++++++++++- drivers/hid/hid-lamparray.c | 54 +++++++++++++++++++++++++++++++++++ include/linux/hid-lamparray.h | 29 +++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-)
drivers/hid/hid-generic.c +28 -1
@@ -102,9 +102,34 @@ static int hid_generic_probe(struct hid_device *hdev,static int hid_generic_reset_resume (struct hid_device *hdev) { +struct lamparray *la =hid_get_drvdata (hdev); +if (hdev->claimed &HID_CLAIMED_INPUT )hidinput_reset_resume (hdev); +if (IS_ENABLED (CONFIG_HID_LAMPARRAY ) && la) +lamparray_resume (la); + +return 0 ; +} + +static int hid_generic_suspend (struct hid_device *hdev,pm_message_t message) +{ +struct lamparray *la =hid_get_drvdata (hdev); + +if (IS_ENABLED (CONFIG_HID_LAMPARRAY ) && la) +lamparray_suspend (la); + +return 0 ; +} + +static int hid_generic_resume (struct hid_device *hdev) +{ +struct lamparray *la =hid_get_drvdata (hdev); + +if (IS_ENABLED (CONFIG_HID_LAMPARRAY ) && la) +lamparray_resume (la); +return 0 ; }
@@ -129,8 +154,10 @@ static struct hid_driver hid_generic = { .id_table = hid_table, .match = hid_generic_match, .probe = hid_generic_probe, - .reset_resume = hid_generic_reset_resume, .remove = hid_generic_remove, + .reset_resume = pm_ptr(hid_generic_reset_resume), + .suspend = pm_ptr(hid_generic_suspend), + .resume = pm_ptr(hid_generic_resume), };module_hid_driver (hid_generic);
drivers/hid/hid-lamparray.c +54 -0
60 lines not on this page · raw message
include/linux/hid-lamparray.h +29 -0
@@ -65,6 +65,27 @@ struct lamparray *lamparray_register(struct hid_device *hdev,*/ void lamparray_unregister (struct lamparray *la); +/** +* lamparray_suspend() - blank all lamps ahead of sleep transition +* @la: LampArray handle returned by lamparray_register() +* +* Writes zeroes to the rgb values only, keeping the brightness, unless the +* use_leds_uapi sysfs attribute is 0, in which case, it will return early +* before writing anything. The cached state is left untouched so +* lamparray_resume() can restore it. +*/ +void lamparray_suspend (struct lamparray *la); + +/** +* lamparray_resume() - restore host control and LampArray state +* @la: LampArray handle returned by lamparray_register() +* +* Disables autonomous mode (in case device returns to firmware control after suspend) +* and restores the cached state of the device. If the use_leds_uapi attribute is 0, +* it will return early and prevent any unwanted writing. +*/ +void lamparray_resume (struct lamparray *la); +#else /* !CONFIG_HID_LAMPARRAY */ static inline bool lamparray_is_supported_device (struct hid_device *hdev)
@@ -83,6 +104,14 @@ static inline void lamparray_unregister(struct lamparray *la) { } +static inline void lamparray_suspend (struct lamparray *la) +{ +} + +static inline void lamparray_resume (struct lamparray *la) +{ +} +#endif /* CONFIG_HID_LAMPARRAY */ #endif /* _HID_LAMPARRAY_H */
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v6 3/3] HID: lamparray: blank lamps across suspend and restore on resume
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] hid: lamparray: blink timer overwrites blanked state during suspend --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] hid: lamparray: blink timer overwrites blanked state during suspend --
commit 0480546fa780aefd04da86e31cbb23c2cb7e6a3d
Author: Cristian Mazzotta <[email protected]>
HID: lamparray: blank lamps across suspend and restore on resume
This commit adds power management callbacks to blank lamparray devices during system suspend by writing zeroes to the color channels. It also introduces a resume function to explicitly transition the device out of autonomous mode and restore its cached color state.
Quoted 4 lines
drivers/hid/hid-lamparray.c +0
-0
[ ... ]
Quoted 5 lines
drivers/hid/hid-lamparray.c +5
-0+void lamparray_suspend (struct lamparray *la) +{ +struct lamparray_device *ldev; + +if (!la)
drivers/hid/hid-lamparray.c void lamparray_unregister(struct lamparray *la) · line 872
Quoted 10 lines
drivers/hid/hid-lamparray.c +10
-0+return ; + + ldev = &la->ldev; + +if (!ldev->use_leds_uapi) +return ; + +mutex_lock (&ldev->dev_lock); +lamparray_hw_set_state (ldev,0 ,0 ,0 ,0 ); +mutex_unlock (&ldev->dev_lock);
[Severity: Medium]
Will active LED software blink timers continue to fire during system suspend and overwrite this blanked state?
If a userspace application or trigger enables software blinking on the lamparray LED classdev before system suspend (e.g. s2idle), the timer can continue to queue work to leds_wq. This will call lamparray_hw_set_state() and overwrite the blanked (0,0,0,0) state set here, causing high power draw and undermining the intent of this function.
Does the lamparray LED classdev initialization need to set the LED_CORE_SUSPENDRESUME flag so the LED subsystem correctly applies LED_SUSPENDED and prevents timers from queuing new brightness updates during suspend?
Quoted 4 lines
drivers/hid/hid-lamparray.c +4
-0+ +hid_hw_wait (ldev->hdev); +} +EXPORT_SYMBOL_GPL (lamparray_suspend);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Quoted 2 lines · Aaron Erhardt
Add a new hid-lamparray helper module and integrate it with the hid-generic driver.
Thanks for picking these up!
I do have two corrections on patch 3 however, and both were mine originally, so my bad:
- The measurement in the commit message and in the comment above lamparray_suspend() is wrong. It should be 12.35 W with lamps lit and 3.14 W blanked, which is 9.21 W or about 75% of s2idle draw, not 2.84 W / 77%. The 2.84 W was an earlier test on a local branch that includes full multi-zone support. It's worth noting in the comment that the 3.14 W still includes the lid zone, which single-zone control cannot reach on this device.
- The kerneldoc for lamparray_suspend() still says it "writes zeroes to the rgb values only, keeping the brightness", but the call is now lamparray_hw_set_state(ldev, 0, 0, 0, 0). The code is fine, but the doc should follow it.
On your question about the default state: I think the lights "look like they don't work" can be a real conclusion, but the cause is the intensity default rather than the brightness default.
With led_init_state NULL, last_r/g/b stay zero, register_led copies them into subleds[].intensity, and brightness_set reads r/g/b back out of subled_info[].intensity. So every brightness write sends (0, 0, 0, brightness), which is black at any brightness. The zero-brightness quirk does not change this since it only forces RGB to zero when brightness is already zero.
The LED class device is therefore inert rather than just dark; systemd-backlight restoring a saved brightness, or a DE slider, or UPower, all write brightness and see nothing happen. This is because nothing in that stack writes multi_intensity first.
Defaulting to autonomous mode would not fix that. It would replace an inert knob with an ignored one: the cached RGB and brightness would describe nothing the hardware is doing, and a DE would have to discover and write use_leds_uapi to make the node real. That is driver-specific knowledge that desktop environments are unlikely to carry.
On a second look, I would suggest keeping brightness at LED_OFF, but defaulting the intensities to max_r/max_g/max_b. The device is still dark at probe, autonomous mode is still disabled so the cached state matches the hardware, and the first brightness write from existing userspace lights it up. Combined with the quirk you added for Armin's device, it stays dark even on firmware that ignores the intensity channel.
One hardware data point, since discoverability came up: on the Acer Predator PT14-52T the keyboard brightness keys are handled entirely in the EC and never reach the LED class device, so they cannot be relied on to show the user that anything is controllable.
On multi-collection, I don't see myself getting to it soon. I might work on it during fall or winter break of my university, however I cannot guarantee it, so please do not consider it blocked on me. The ENE controller exposes two LampArrayAttributesReport collections and lamparray_parse_update_report() only keeps the last.
I have a local branch which includes working multi-collection support. It's based off of Tim's v4, and it's what I referred to in the original v4 thread; I'd be happy to send over my branch as a reference, though porting it to v6 is not trivial.
Am 16.09.26 um 18:15 schrieb Cristian Mazzotta:
Quoted 17 lines · Aaron Erhardt
Quoted 2 lines
Add a new hid-lamparray helper module and integrate it with the hid-generic driver.
Thanks for picking these up!
I do have two corrections on patch 3 however, and both were mine originally, so my bad:
- The measurement in the commit message and in the comment above
lamparray_suspend()is wrong. It should be 12.35 W with lamps lit and 3.14 W blanked, which is 9.21 W or about 75% of s2idle draw, not 2.84 W / 77%. The 2.84 W was an earlier test on a local branch that includes full multi-zone support. It's worth noting in the comment that the 3.14 W still includes the lid zone, which single-zone control cannot reach on this device.
Quoted 4 lines
- The kerneldoc for
lamparray_suspend()still says it "writes zeroes to the rgb values only, keeping the brightness", but the call is nowlamparray_hw_set_state(ldev, 0, 0, 0, 0). The code is fine, but the doc should follow it.
Ack. Will be fixed in v7.
Quoted 24 lines
On your question about the default state: I think the lights "look like they don't work" can be a real conclusion, but the cause is the intensity default rather than the brightness default.
With
led_init_stateNULL, last_r/g/b stay zero,register_ledcopies them into subleds[].intensity, andbrightness_setreads r/g/b back out of subled_info[].intensity. So every brightness write sends (0, 0, 0, brightness), which is black at any brightness. The zero-brightness quirk does not change this since it only forces RGB to zero when brightness is already zero.The LED class device is therefore inert rather than just dark; systemd-backlight restoring a saved brightness, or a DE slider, or UPower, all write brightness and see nothing happen. This is because nothing in that stack writes
multi_intensityfirst.Defaulting to autonomous mode would not fix that. It would replace an inert knob with an ignored one: the cached RGB and brightness would describe nothing the hardware is doing, and a DE would have to discover and write
use_leds_uapito make the node real. That is driver-specific knowledge that desktop environments are unlikely to carry.
Quoted 6 lines
On a second look, I would suggest keeping brightness at
LED_OFF, but defaulting the intensities to max_r/max_g/max_b. The device is still dark at probe, autonomous mode is still disabled so the cached state matches the hardware, and the first brightness write from existing userspace lights it up. Combined with the quirk you added for Armin's device, it stays dark even on firmware that ignores the intensity channel.
I think this is a good idea. In general, the default should probably either set intensities to max_(r|g|b) or brightness to max_brightness. This would reduce the amount of writes necessary to see a result and I agree that probably the brightness knob is most likely to be used by userspace. Still, I'd like to have some more feedback, especially from the maintainers before integrating this behavior in v7.
Quoted 12 lines
One hardware data point, since discoverability came up: on the Acer Predator PT14-52T the keyboard brightness keys are handled entirely in the EC and never reach the LED class device, so they cannot be relied on to show the user that anything is controllable.
On multi-collection, I don't see myself getting to it soon. I might work on it during fall or winter break of my university, however I cannot guarantee it, so please do not consider it blocked on me. The ENE controller exposes two LampArrayAttributesReport collections and
lamparray_parse_update_report()only keeps the last.
Quoted 4 lines
I have a local branch which includes working multi-collection support. It's based off of Tim's v4, and it's what I referred to in the original v4 thread; I'd be happy to send over my branch as a reference, though porting it to v6 is not trivial.
I could have a look at your branch, but I think it's better to wait for this series to be merged before exploring more advanced features. I can't guarantee that I will work on that actively, especially since I don't have access to such hardware, but I'm curious to see what changes you have applied to make it work with v4.