| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/08/20 17:46 | flow | patch-triage |
2mArgs:null Results: {
"EnableConfigs": [
"LEDS_CLASS",
"LEDS_TRIGGERS",
"LEDS_TRIGGERS_HW_CHANGED",
"LEDS_TRIGGER_NETDEV"
],
"FocusSymbols": [
"led_trigger_is_hw_controlled",
"led_trigger_remove_hw_control",
"trigger_may_offload_show"
],
"KMSANReasoning": "The patch series modifies the LED subsystem to support hardware-initiated trigger transitions, adding a new sysfs attribute `trigger_may_offload` and modifying several LED drivers to support this feature. The changes involve adding new callbacks (`offloaded`), modifying existing ones, and adding new logic to handle hardware control transitions.\n\nThere are no new structures sent to user space, no complex data structures allocated where uninitialized fields could be read later, and no conditional logic that depends on potentially uninitialized variables. The sysfs attribute uses `sysfs_emit`, which is safe. The changes primarily involve control flow and state management within the LED subsystem and drivers.\n\nAny potential bugs introduced by these changes, such as out-of-bounds accesses, NULL pointer dereferences, or locking issues, would be caught by standard KASAN, LOCKDEP, or other standard bug detectors. There is no risk of uninitialized memory usage or info-leaks that would require a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false,
"Reasoning": "The patch introduces support for hardware-initiated LED trigger transitions and a new sysfs attribute `trigger_may_offload` to query supported triggers and their states. It modifies the core LED class and trigger subsystems, which are reachable via sysfs for any LED device. It also updates the `netdev` LED trigger to report its offloaded state. These core changes and the `netdev` trigger modifications are reachable in virtualized environments and have functional impact.",
"WorthFuzzing": true
} |
| 1/1 | 2026/08/20 17:46 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 2533c2922f89dde807e90d3942b7376dcf715d33\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Thu Aug 20 17:46:18 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led\nindex d4c918cc11a12..2a13c77aee229 100644\n--- a/Documentation/ABI/testing/sysfs-class-led\n+++ b/Documentation/ABI/testing/sysfs-class-led\n@@ -78,6 +78,31 @@ Description:\n \t\t(which would often be configured in the device tree for the\n \t\thardware).\n \n+What:\t\t/sys/class/leds/\u003cled\u003e/trigger_may_offload\n+Date:\t\tAugust 2026\n+KernelVersion:\t7.3\n+Contact:\tlinux-leds@vger.kernel.org\n+Description:\n+\t\tNames and states of triggers that may be offloaded to hardware.\n+\t\tSuch triggers are also called \"hardware control trigger\" in some\n+\t\tcontext.\n+\n+\t\tOnly exists when the LED supports trigger offload.\n+\n+\t\tReading this file returns a list of triggers that are capable to\n+\t\tbe offloaded. The optional brackets around the trigger name\n+\t\tindicate the state of the current trigger:\n+\n+\t\t- `foo_trigger`: the trigger is not selected.\n+\t\t- `\u003cfoo_trigger\u003e`: the trigger is selected, but falls back to\n+\t\t software blink for some reason (e.g., incompatible trigger\n+\t\t parameters)\n+\t\t- `[foo_trigger]`: the trigger is selected and offloaded to\n+\t\t hardware.\n+\n+\t\tThe \"netdev\" trigger also provides a custom attribute to\n+\t\tindicate its state, see `/sys/class/leds/\u003cled\u003e/offloaded`.\n+\n What:\t\t/sys/class/leds/\u003cled\u003e/inverted\n Date:\t\tJanuary 2011\n KernelVersion:\t2.6.38\ndiff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev\nindex ed46b37ab8a28..a5146ea1e3e61 100644\n--- a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev\n+++ b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev\n@@ -75,6 +75,9 @@ Description:\n \t\tIf 1, the LED blinking in requested mode is offloaded to\n \t\thardware.\n \n+\t\tLED trigger core also provides a generic attribute for this\n+\t\tpurpose, see `/sys/class/leds/\u003cled\u003e/trigger_may_offload`.\n+\n What:\t\t/sys/class/leds/\u003cled\u003e/link_10\n Date:\t\tJun 2023\n KernelVersion:\t6.5\ndiff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst\nindex 3913966cfdac0..adbc57b9f49c3 100644\n--- a/Documentation/leds/leds-class.rst\n+++ b/Documentation/leds/leds-class.rst\n@@ -242,6 +242,9 @@ ops and needs to declare specific support for the supported triggers.\n \n With hw control we refer to the LED driven by hardware.\n \n+A sysfs attribute `trigger_may_offload` is provided for userspace to\n+query supported triggers and their states.\n+\n LED driver must define the following value to support hw control:\n \n - hw_control_trigger:\n@@ -298,6 +301,15 @@ LED driver must implement the following API to support hw control:\n Returns a pointer to a struct device or NULL if nothing\n is currently attached.\n \n+LED trigger should implement the following API to indicate hw control:\n+ - offloaded:\n+ return a boolean indicating if the trigger is currently\n+ offloaded to hardware.\n+\n+ If a trigger doesn't implement this callback, the default\n+ value will be true for private triggers and false for generic\n+ ones.\n+\n LED driver can activate additional modes by default to workaround the\n impossibility of supporting each different mode on the supported trigger.\n Examples are hardcoding the blink speed to a set interval, enable special\n@@ -311,9 +323,69 @@ the end use hw_control_set to activate hw control.\n A trigger can use hw_control_get to check if a LED is already in hw control\n and init their flags.\n \n+Alternatively, a private trigger can be implemented along with the LED driver if\n+the LED's hardware control doesn't fit any generic trigger. To associate the\n+private trigger with the LED classdev, their `trigger_type` must be the same. To\n+declare that the private trigger provides hardware control for the associated\n+LED classdev, set the `hw_control_trigger` string to the trigger's name. Since\n+both the LED classdev and the private trigger are in the same LED driver, it's\n+not necessary for them to coordinate via `hw_control_*` callbacks.\n+\n When the LED is in hw control, no software blink is possible and doing so\n will effectively disable hw control.\n \n+Hardware-initiated trigger transition\n+=====================================\n+\n+Some hardware can autonomously activate/deactivate hardware control. After that,\n+the LED hardware notifies the LED driver.\n+\n+If the driver can detect such transitions and thus wants to notify the LED core\n+to update the current trigger then the `LED_TRIG_HW_CHANGED` flag must be set in\n+flags before registering. To update the current trigger accordingly, call\n+`led_trigger_notify_hw_control_changed` on the LED classdev.\n+\n+This capability is restricted to the LED device's private trigger. The private\n+trigger must have been properly registered (see above) and named after\n+`hw_control_trigger`.\n+\n+Only two transitions are defined:\n+\n+- \"none\" =\u003e private trigger:\n+ This happens when the hardware autonomously activates hardware control\n+ and when \"none\" (i.e., no trigger) is currently active. If the private\n+ trigger is already active when the method is called, this is essentially\n+ a no-op.\n+\n+ The activation sequence for the private trigger will be executed as\n+ normal.\n+\n+ The LED driver and its private trigger must be able to handle the\n+ activation sequence even if the hardware is currently in hardware\n+ control.\n+\n+ If error occurs in the activation sequence, the LED Trigger core reverts\n+ the effective trigger to \"none\".\n+\n+- private trigger =\u003e \"none\"\n+ This happens when the hardware autonomously deactivates hardware control\n+ and when the private trigger is currently active. If \"none\" (i.e., no\n+ trigger) is active when the method is called, this is essentially a\n+ no-op.\n+\n+ The deactivation sequence for the private trigger will be executed as\n+ normal, except that the current LED brightness is retained. The reason\n+ for keeping the brightness unchanged is that some hardware may choose a\n+ specific brightness instead of simply turning off the LED after\n+ autonomously deactivating hardware control.\n+\n+ The LED driver and its private trigger must be able to handle the\n+ deactivation sequence even if the hardware is not currently in hardware\n+ control.\n+\n+If the current trigger is neither the private trigger nor \"none\", no transition\n+will be made.\n+\n Known Issues\n ============\n \ndiff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c\nindex a51b0ed538864..771a6e6c659be 100644\n--- a/drivers/leds/led-class.c\n+++ b/drivers/leds/led-class.c\n@@ -27,16 +27,6 @@ static LIST_HEAD(leds_lookup_list);\n \n static struct workqueue_struct *leds_wq;\n \n-static bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)\n-{\n-#ifdef CONFIG_LEDS_TRIGGERS\n-\tguard(rwsem_read)(\u0026led_cdev-\u003etrigger_lock);\n-\treturn led_cdev-\u003etrigger \u0026\u0026 led_cdev-\u003etrigger-\u003etrigger_type;\n-#else\n-\treturn false;\n-#endif\n-}\n-\n static ssize_t brightness_show(struct device *dev,\n \t\tstruct device_attribute *attr, char *buf)\n {\n@@ -74,6 +64,9 @@ static ssize_t brightness_store(struct device *dev,\n \n \tif (state == LED_OFF)\n \t\tled_trigger_remove(led_cdev);\n+\telse\n+\t\tled_trigger_remove_hw_control(led_cdev);\n+\n \tled_set_brightness(led_cdev, state);\n \n \tret = size;\n@@ -103,8 +96,30 @@ static const struct bin_attribute *const led_trigger_bin_attrs[] = {\n \t\u0026bin_attr_trigger,\n \tNULL,\n };\n+\n+static DEVICE_ATTR_RO(trigger_may_offload);\n+static struct attribute *led_trigger_attrs[] = {\n+\t\u0026dev_attr_trigger_may_offload.attr,\n+\tNULL\n+};\n+\n+static umode_t led_trigger_is_visible(struct kobject *kobj,\n+\t\t\t\t struct attribute *attr,\n+\t\t\t\t int idx)\n+{\n+\tstruct device *dev = kobj_to_dev(kobj);\n+\tstruct led_classdev *led_cdev = dev_get_drvdata(dev);\n+\n+\tif (attr == \u0026dev_attr_trigger_may_offload.attr)\n+\t\treturn led_cdev-\u003ehw_control_trigger ? attr-\u003emode : 0;\n+\n+\treturn attr-\u003emode;\n+}\n+\n static const struct attribute_group led_trigger_group = {\n \t.bin_attrs = led_trigger_bin_attrs,\n+\t.attrs = led_trigger_attrs,\n+\t.is_visible = led_trigger_is_visible,\n };\n #endif\n \n@@ -618,12 +633,13 @@ void led_classdev_unregister(struct led_classdev *led_cdev)\n \n #ifdef CONFIG_LEDS_TRIGGERS\n \tdown_write(\u0026led_cdev-\u003etrigger_lock);\n+\tled_cdev-\u003eflags |= LED_UNREGISTERING;\n \tif (led_cdev-\u003etrigger)\n \t\tled_trigger_set(led_cdev, NULL);\n \tup_write(\u0026led_cdev-\u003etrigger_lock);\n-#endif\n-\n+#else\n \tled_cdev-\u003eflags |= LED_UNREGISTERING;\n+#endif\n \n \t/* Stop blinking */\n \tled_stop_software_blink(led_cdev);\ndiff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c\nindex b1223218bda11..32c9d19374c4e 100644\n--- a/drivers/leds/led-triggers.c\n+++ b/drivers/leds/led-triggers.c\n@@ -7,9 +7,12 @@\n * Author: Richard Purdie \u003crpurdie@openedhand.com\u003e\n */\n \n+#include \u003clinux/bug.h\u003e\n+#include \u003clinux/cleanup.h\u003e\n #include \u003clinux/export.h\u003e\n #include \u003clinux/kernel.h\u003e\n #include \u003clinux/list.h\u003e\n+#include \u003clinux/lockdep.h\u003e\n #include \u003clinux/spinlock.h\u003e\n #include \u003clinux/device.h\u003e\n #include \u003clinux/timer.h\u003e\n@@ -33,6 +36,34 @@ trigger_relevant(struct led_classdev *led_cdev, struct led_trigger *trig)\n \treturn !trig-\u003etrigger_type || trig-\u003etrigger_type == led_cdev-\u003etrigger_type;\n }\n \n+static bool __led_trigger_is_hw_controlled(struct led_classdev *led_cdev)\n+{\n+\tlockdep_assert_held(\u0026led_cdev-\u003etrigger_lock);\n+\n+\tif (!led_cdev-\u003etrigger)\n+\t\treturn false;\n+\n+\tif (!led_cdev-\u003ehw_control_trigger ||\n+\t strcmp(led_cdev-\u003ehw_control_trigger, led_cdev-\u003etrigger-\u003ename))\n+\t\treturn false;\n+\n+\tif (led_cdev-\u003etrigger-\u003eoffloaded)\n+\t\treturn led_cdev-\u003etrigger-\u003eoffloaded(led_cdev);\n+\n+\tdev_warn_once(led_cdev-\u003edev, \"hw control trigger %s doesn't implement offloaded()\\n\",\n+\t\t led_cdev-\u003etrigger-\u003ename);\n+\n+\t/* Otherwise assume private triggers as always offloaded. */\n+\treturn led_cdev-\u003etrigger-\u003etrigger_type;\n+}\n+\n+bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)\n+{\n+\tguard(rwsem_read)(\u0026led_cdev-\u003etrigger_lock);\n+\treturn __led_trigger_is_hw_controlled(led_cdev);\n+}\n+EXPORT_SYMBOL_GPL(led_trigger_is_hw_controlled);\n+\n ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,\n \t\t\t const struct bin_attribute *bin_attr, char *buf,\n \t\t\t loff_t pos, size_t count)\n@@ -163,13 +194,17 @@ ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,\n EXPORT_SYMBOL_GPL(led_trigger_read);\n \n /* Caller must ensure led_cdev-\u003etrigger_lock held */\n-int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)\n+static int __led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig,\n+\t\t\t bool hw_triggered)\n {\n \tchar *event = NULL;\n \tchar *envp[2];\n \tconst char *name;\n \tint ret;\n \n+\tif ((led_cdev-\u003eflags \u0026 LED_UNREGISTERING) \u0026\u0026 trig)\n+\t\treturn -ENODEV;\n+\n \tif (!led_cdev-\u003etrigger \u0026\u0026 !trig)\n \t\treturn 0;\n \n@@ -194,7 +229,21 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)\n \t\tled_cdev-\u003etrigger_data = NULL;\n \t\tled_cdev-\u003eactivated = false;\n \t\tled_cdev-\u003eflags \u0026= ~LED_INIT_DEFAULT_TRIGGER;\n-\t\tled_set_brightness(led_cdev, LED_OFF);\n+\n+\t\t/*\n+\t\t * Hardware may have selected a new brightness level during its\n+\t\t * hardware control transition, so only reset brightness if we\n+\t\t * are switching to another trigger or if the switching is not\n+\t\t * hardware triggered.\n+\t\t *\n+\t\t * Note that this does not apply to the error path, as running\n+\t\t * into the error path implies a none =\u003e private trigger\n+\t\t * transition. This hints that the LED driver and its private\n+\t\t * trigger must have some fundamental bugs, so don't bother\n+\t\t * leaving the LED in an undefined state.\n+\t\t */\n+\t\tif (trig || !hw_triggered)\n+\t\t\tled_set_brightness(led_cdev, LED_OFF);\n \t}\n \tif (trig) {\n \t\tspin_lock(\u0026trig-\u003eleddev_list_lock);\n@@ -258,6 +307,11 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)\n \n \treturn ret;\n }\n+\n+int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)\n+{\n+\treturn __led_trigger_set(led_cdev, trig, false);\n+}\n EXPORT_SYMBOL_GPL(led_trigger_set);\n \n void led_trigger_remove(struct led_classdev *led_cdev)\n@@ -268,6 +322,15 @@ void led_trigger_remove(struct led_classdev *led_cdev)\n }\n EXPORT_SYMBOL_GPL(led_trigger_remove);\n \n+void led_trigger_remove_hw_control(struct led_classdev *led_cdev)\n+{\n+\tguard(rwsem_write)(\u0026led_cdev-\u003etrigger_lock);\n+\n+\tif (__led_trigger_is_hw_controlled(led_cdev))\n+\t\tled_trigger_set(led_cdev, NULL);\n+}\n+EXPORT_SYMBOL_GPL(led_trigger_remove_hw_control);\n+\n static bool led_match_default_trigger(struct led_classdev *led_cdev,\n \t\t\t\t struct led_trigger *trig)\n {\n@@ -313,6 +376,32 @@ void led_trigger_set_default(struct led_classdev *led_cdev)\n }\n EXPORT_SYMBOL_GPL(led_trigger_set_default);\n \n+ssize_t trigger_may_offload_show(struct device *dev,\n+\t\t\t\t struct device_attribute *attr, char *buf)\n+{\n+\tstruct led_classdev *led_cdev = dev_get_drvdata(dev);\n+\tstruct led_trigger *trig;\n+\tbool hit, offloaded;\n+\tint len;\n+\n+\tguard(mutex)(\u0026led_cdev-\u003eled_access);\n+\tguard(rwsem_read)(\u0026led_cdev-\u003etrigger_lock);\n+\n+\ttrig = led_cdev-\u003etrigger;\n+\n+\toffloaded = __led_trigger_is_hw_controlled(led_cdev);\n+\thit = offloaded || (trig \u0026\u0026 !strcmp(led_cdev-\u003ehw_control_trigger, trig-\u003ename));\n+\n+\t/* [offloaded] \u003cactive_but_not_offloaded\u003e inactive */\n+\tlen = sysfs_emit(buf, \"%s%s%s\\n\",\n+\t\t\t offloaded ? \"[\" : (hit ? \"\u003c\" : \"\"),\n+\t\t\t led_cdev-\u003ehw_control_trigger,\n+\t\t\t offloaded ? \"]\" : (hit ? \"\u003e\" : \"\"));\n+\n+\treturn len;\n+}\n+EXPORT_SYMBOL_GPL(trigger_may_offload_show);\n+\n /* LED Trigger Interface */\n \n int led_trigger_register(struct led_trigger *trig)\n@@ -403,6 +492,65 @@ int devm_led_trigger_register(struct device *dev,\n }\n EXPORT_SYMBOL_GPL(devm_led_trigger_register);\n \n+#ifdef CONFIG_LEDS_TRIGGERS_HW_CHANGED\n+static void led_trigger_do_hw_control_transition(struct led_classdev *led_cdev, bool activate,\n+\t\t\t\t\t\t struct led_trigger *hc_trig)\n+{\n+\tint err = 0;\n+\n+\tif (!led_cdev-\u003etrigger) {\n+\t\t/* \"none\" =\u003e private trigger. */\n+\t\tif (activate)\n+\t\t\terr = __led_trigger_set(led_cdev, hc_trig, true);\n+\t} else if (led_cdev-\u003etrigger == hc_trig) {\n+\t\t/* private trigger =\u003e \"none\". */\n+\t\tif (!activate)\n+\t\t\terr = __led_trigger_set(led_cdev, NULL, true);\n+\t} else {\n+\t\t/* Other trigger is active. */\n+\t\tdev_dbg(led_cdev-\u003edev,\n+\t\t\t\"Ignoring hw control transition (%s %s) while %s is active\",\n+\t\t\tactivate ? \"activate\" : \"deactivate\", hc_trig-\u003ename,\n+\t\t\tled_cdev-\u003etrigger-\u003ename);\n+\n+\t\treturn;\n+\t}\n+\n+\tif (err)\n+\t\tdev_warn(led_cdev-\u003edev, \"Failed to %s %s in hw control transition: %d\",\n+\t\t\t activate ? \"activate\" : \"deactivate\", hc_trig-\u003ename, err);\n+}\n+\n+void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev, bool activate)\n+{\n+\tstruct led_trigger *trig;\n+\n+\tmight_sleep();\n+\n+\t/* Restricted to private triggers. */\n+\tif (WARN_ON(!(led_cdev-\u003eflags \u0026 LED_TRIG_HW_CHANGED) ||\n+\t\t !led_cdev-\u003ehw_control_trigger || !led_cdev-\u003etrigger_type))\n+\t\treturn;\n+\n+\tscoped_guard(rwsem_read, \u0026triggers_list_lock) {\n+\t\tlist_for_each_entry(trig, \u0026trigger_list, next_trig) {\n+\t\t\tif (trig-\u003etrigger_type == led_cdev-\u003etrigger_type \u0026\u0026\n+\t\t\t !strcmp(trig-\u003ename, led_cdev-\u003ehw_control_trigger)) {\n+\t\t\t\tguard(rwsem_write)(\u0026led_cdev-\u003etrigger_lock);\n+\n+\t\t\t\tled_trigger_do_hw_control_transition(led_cdev, activate, trig);\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tdev_err(led_cdev-\u003edev,\n+\t\t\"%s() is called, but the private trigger (%s) is not properly registered\\n\",\n+\t\t__func__, led_cdev-\u003ehw_control_trigger);\n+}\n+EXPORT_SYMBOL_GPL(led_trigger_notify_hw_control_changed);\n+#endif /* CONFIG_LEDS_TRIGGERS_HW_CHANGED */\n+\n /* Simple LED Trigger Interface */\n \n void led_trigger_event(struct led_trigger *trig,\ndiff --git a/drivers/leds/leds-cros_ec.c b/drivers/leds/leds-cros_ec.c\nindex 1844d0cd5f528..6db83d0152775 100644\n--- a/drivers/leds/leds-cros_ec.c\n+++ b/drivers/leds/leds-cros_ec.c\n@@ -85,12 +85,18 @@ static int cros_ec_led_trigger_activate(struct led_classdev *led_cdev)\n \treturn cros_ec_led_send_cmd(priv-\u003ecros_ec, \u0026arg);\n }\n \n+static bool cros_ec_led_trigger_offloaded(struct led_classdev *led_cdev)\n+{\n+\treturn true;\n+}\n+\n static struct led_hw_trigger_type cros_ec_led_trigger_type;\n \n static struct led_trigger cros_ec_led_trigger = {\n \t.name = \"chromeos-auto\",\n \t.trigger_type = \u0026cros_ec_led_trigger_type,\n \t.activate = cros_ec_led_trigger_activate,\n+\t.offloaded = cros_ec_led_trigger_offloaded,\n };\n \n static int cros_ec_led_brightness_set_blocking(struct led_classdev *led_cdev,\ndiff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c\nindex ed6a47bbb44f9..32d40d176d3f1 100644\n--- a/drivers/leds/leds-turris-omnia.c\n+++ b/drivers/leds/leds-turris-omnia.c\n@@ -195,10 +195,16 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev)\n \t\t\terr);\n }\n \n+static bool omnia_hwtrig_offloaded(struct led_classdev *cdev)\n+{\n+\treturn true;\n+}\n+\n static struct led_trigger omnia_hw_trigger = {\n \t.name\t\t= \"omnia-mcu\",\n \t.activate\t= omnia_hwtrig_activate,\n \t.deactivate\t= omnia_hwtrig_deactivate,\n+\t.offloaded\t= omnia_hwtrig_offloaded,\n \t.trigger_type\t= \u0026omnia_hw_trigger_type,\n };\n \n@@ -251,6 +257,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,\n \t * by LED class from the linux,default-trigger property.\n \t */\n \tcdev-\u003edefault_trigger = omnia_hw_trigger.name;\n+\tcdev-\u003ehw_control_trigger = omnia_hw_trigger.name;\n \n \t/* Put the LED into software mode */\n \tret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(led-\u003ereg) |\ndiff --git a/drivers/leds/leds.h b/drivers/leds/leds.h\nindex bee46651e068f..b08a289397e46 100644\n--- a/drivers/leds/leds.h\n+++ b/drivers/leds/leds.h\n@@ -27,6 +27,8 @@ ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,\n ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,\n \t\t\tconst struct bin_attribute *bin_attr, char *buf,\n \t\t\tloff_t pos, size_t count);\n+ssize_t trigger_may_offload_show(struct device *dev,\n+\t\t\t\t struct device_attribute *attr, char *buf);\n \n extern struct rw_semaphore leds_list_lock;\n extern struct list_head leds_list;\ndiff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig\nindex c11282a74b5ac..a11d04ce4ab2c 100644\n--- a/drivers/leds/trigger/Kconfig\n+++ b/drivers/leds/trigger/Kconfig\n@@ -9,6 +9,16 @@ menuconfig LEDS_TRIGGERS\n \n if LEDS_TRIGGERS\n \n+config LEDS_TRIGGERS_HW_CHANGED\n+\tbool \"LED hardware-initiated trigger transition support\"\n+\tdefault LEDS_BRIGHTNESS_HW_CHANGED\n+\thelp\n+\t This option enables support for hardware initiated hardware control\n+\t transitions, where the LED hardware autonomously switches between\n+\t \"none\" (i.e., no trigger) and its private trigger.\n+\n+\t See Documentation/leds/leds-class.rst for details.\n+\n config LEDS_TRIGGER_TIMER\n \ttristate \"LED Timer Trigger\"\n \thelp\ndiff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c\nindex 64c078e997f28..a26109ca4b1c9 100644\n--- a/drivers/leds/trigger/ledtrig-netdev.c\n+++ b/drivers/leds/trigger/ledtrig-netdev.c\n@@ -754,10 +754,18 @@ static void netdev_trig_deactivate(struct led_classdev *led_cdev)\n \tkfree(trigger_data);\n }\n \n+static bool netdev_trig_offloaded(struct led_classdev *led_cdev)\n+{\n+\tstruct led_netdev_data *trigger_data = led_get_trigger_data(led_cdev);\n+\n+\treturn trigger_data-\u003ehw_control;\n+}\n+\n static struct led_trigger netdev_led_trigger = {\n \t.name = \"netdev\",\n \t.activate = netdev_trig_activate,\n \t.deactivate = netdev_trig_deactivate,\n+\t.offloaded = netdev_trig_offloaded,\n \t.groups = netdev_trig_groups,\n };\n \ndiff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig\nindex 4443f40ef8aa7..e92b1e9007951 100644\n--- a/drivers/platform/x86/lenovo/Kconfig\n+++ b/drivers/platform/x86/lenovo/Kconfig\n@@ -16,6 +16,7 @@ config IDEAPAD_LAPTOP\n \tselect INPUT_SPARSEKMAP\n \tselect NEW_LEDS\n \tselect LEDS_CLASS\n+\tselect LEDS_TRIGGERS\n \thelp\n \t This is a driver for Lenovo IdeaPad netbooks contains drivers for\n \t rfkill switch, hotkey, fan control and backlight control.\ndiff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c\nindex 8213524504eeb..5442cbfe3969b 100644\n--- a/drivers/platform/x86/lenovo/ideapad-laptop.c\n+++ b/drivers/platform/x86/lenovo/ideapad-laptop.c\n@@ -9,14 +9,18 @@\n #define pr_fmt(fmt) KBUILD_MODNAME \": \" fmt\n \n #include \u003clinux/acpi.h\u003e\n+#include \u003clinux/atomic.h\u003e\n #include \u003clinux/backlight.h\u003e\n #include \u003clinux/bitfield.h\u003e\n #include \u003clinux/bitops.h\u003e\n #include \u003clinux/bug.h\u003e\n #include \u003clinux/cleanup.h\u003e\n+#include \u003clinux/compiler.h\u003e\n+#include \u003clinux/container_of.h\u003e\n #include \u003clinux/debugfs.h\u003e\n #include \u003clinux/delay.h\u003e\n #include \u003clinux/device.h\u003e\n+#include \u003clinux/dev_printk.h\u003e\n #include \u003clinux/dmi.h\u003e\n #include \u003clinux/i8042.h\u003e\n #include \u003clinux/init.h\u003e\n@@ -26,9 +30,11 @@\n #include \u003clinux/kernel.h\u003e\n #include \u003clinux/leds.h\u003e\n #include \u003clinux/module.h\u003e\n+#include \u003clinux/mutex.h\u003e\n #include \u003clinux/platform_device.h\u003e\n #include \u003clinux/platform_profile.h\u003e\n #include \u003clinux/power_supply.h\u003e\n+#include \u003clinux/printk.h\u003e\n #include \u003clinux/rfkill.h\u003e\n #include \u003clinux/seq_file.h\u003e\n #include \u003clinux/string_choices.h\u003e\n@@ -134,10 +140,31 @@ enum {\n };\n \n /*\n- * These correspond to the number of supported states - 1\n- * Future keyboard types may need a new system, if there's a collision\n- * KBD_BL_TRISTATE_AUTO has no way to report or set the auto state\n- * so it effectively has 3 states, but needs to handle 4\n+ * The enumeration has two purposes:\n+ * - as an internal identifier for all known types of keyboard backlight\n+ * - as a mandatory parameter of the KBLC command\n+ *\n+ * For each type, the hardware brightness values are defined as follows:\n+ * +--------------------------+----------+-----+------+------+\n+ * | Hardware brightness | 0 | 1 | 2 | 3 |\n+ * | Type | | | | |\n+ * +--------------------------+----------+-----+------+------+\n+ * | KBD_BL_STANDARD | off | on | N/A | N/A |\n+ * +--------------------------+----------+-----+------+------+\n+ * | KBD_BL_TRISTATE | off | low | high | N/A |\n+ * +--------------------------+----------+-----+------+------+\n+ * | KBD_BL_TRISTATE_AUTO | off | low | high | auto |\n+ * +--------------------------+----------+-----+------+------+\n+ *\n+ * We map LED classdev brightness for KBD_BL_TRISTATE_AUTO as follows:\n+ * +--------------------------+----------+-----+------+\n+ * | LED classdev brightness | 0 | 1 | 2 |\n+ * | Operation | | | |\n+ * +--------------------------+----------+-----+------+\n+ * | Read | off/auto | low | high |\n+ * +--------------------------+----------+-----+------+\n+ * | Write | off | low | high |\n+ * +--------------------------+----------+-----+------+\n */\n enum {\n \tKBD_BL_STANDARD = 1,\n@@ -145,6 +172,8 @@ enum {\n \tKBD_BL_TRISTATE_AUTO = 3,\n };\n \n+#define KBD_BL_AUTO_MODE_HW_BRIGHTNESS\t3\n+\n #define KBD_BL_QUERY_TYPE\t\t0x1\n #define KBD_BL_TRISTATE_TYPE\t\t0x5\n #define KBD_BL_TRISTATE_AUTO_TYPE\t0x7\n@@ -203,7 +232,9 @@ struct ideapad_private {\n \t\tbool initialized;\n \t\tint type;\n \t\tstruct led_classdev led;\n-\t\tunsigned int last_brightness;\n+\t\tatomic_t last_hw_brightness;\n+\n+\t\tstruct mutex notif_mutex; /* protects notifications */\n \t} kbd_bl;\n \tstruct {\n \t\tbool initialized;\n@@ -1592,7 +1623,24 @@ static int ideapad_kbd_bl_check_tristate(int type)\n \treturn (type == KBD_BL_TRISTATE) || (type == KBD_BL_TRISTATE_AUTO);\n }\n \n-static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)\n+static int ideapad_kbd_bl_brightness_parse(struct ideapad_private *priv, int hw_brightness)\n+{\n+\t/* Off, low or high */\n+\tif (hw_brightness \u003c= priv-\u003ekbd_bl.led.max_brightness)\n+\t\treturn hw_brightness;\n+\n+\t/* Auto (controlled by EC according to ALS), report as off */\n+\tif (priv-\u003ekbd_bl.type == KBD_BL_TRISTATE_AUTO \u0026\u0026\n+\t hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS)\n+\t\treturn 0;\n+\n+\t/* Unknown value */\n+\tdev_warn(\u0026priv-\u003eplatform_device-\u003edev,\n+\t\t \"Unknown keyboard backlight value: %d\", hw_brightness);\n+\treturn -EINVAL;\n+}\n+\n+static int ideapad_kbd_bl_hw_brightness_get(struct ideapad_private *priv)\n {\n \tunsigned long value;\n \tint err;\n@@ -1606,21 +1654,7 @@ static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)\n \t\tif (err)\n \t\t\treturn err;\n \n-\t\t/* Convert returned value to brightness level */\n-\t\tvalue = FIELD_GET(KBD_BL_GET_BRIGHTNESS, value);\n-\n-\t\t/* Off, low or high */\n-\t\tif (value \u003c= priv-\u003ekbd_bl.led.max_brightness)\n-\t\t\treturn value;\n-\n-\t\t/* Auto, report as off */\n-\t\tif (value == priv-\u003ekbd_bl.led.max_brightness + 1)\n-\t\t\treturn 0;\n-\n-\t\t/* Unknown value */\n-\t\tdev_warn(\u0026priv-\u003eplatform_device-\u003edev,\n-\t\t\t \"Unknown keyboard backlight value: %lu\", value);\n-\t\treturn -EINVAL;\n+\t\treturn FIELD_GET(KBD_BL_GET_BRIGHTNESS, value);\n \t}\n \n \terr = eval_hals(priv-\u003eadev-\u003ehandle, \u0026value);\n@@ -1630,6 +1664,16 @@ static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)\n \treturn !!test_bit(HALS_KBD_BL_STATE_BIT, \u0026value);\n }\n \n+static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)\n+{\n+\tint hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);\n+\n+\tif (hw_brightness \u003c 0)\n+\t\treturn hw_brightness;\n+\n+\treturn ideapad_kbd_bl_brightness_parse(priv, hw_brightness);\n+}\n+\n static enum led_brightness ideapad_kbd_bl_led_cdev_brightness_get(struct led_classdev *led_cdev)\n {\n \tstruct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);\n@@ -1637,62 +1681,123 @@ static enum led_brightness ideapad_kbd_bl_led_cdev_brightness_get(struct led_cla\n \treturn ideapad_kbd_bl_brightness_get(priv);\n }\n \n-static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, unsigned int brightness)\n+static int ideapad_kbd_bl_hw_brightness_set(struct ideapad_private *priv, int hw_brightness)\n {\n-\tint err;\n \tunsigned long value;\n \tint type = priv-\u003ekbd_bl.type;\n+\tint err;\n \n \tif (ideapad_kbd_bl_check_tristate(type)) {\n-\t\tif (brightness \u003e priv-\u003ekbd_bl.led.max_brightness)\n-\t\t\treturn -EINVAL;\n-\n-\t\tvalue = FIELD_PREP(KBD_BL_SET_BRIGHTNESS, brightness) |\n+\t\tvalue = FIELD_PREP(KBD_BL_SET_BRIGHTNESS, hw_brightness) |\n \t\t\tFIELD_PREP(KBD_BL_COMMAND_TYPE, type) |\n \t\t\tKBD_BL_COMMAND_SET;\n \t\terr = exec_kblc(priv-\u003eadev-\u003ehandle, value);\n \t} else {\n-\t\terr = exec_sals(priv-\u003eadev-\u003ehandle, brightness ? SALS_KBD_BL_ON : SALS_KBD_BL_OFF);\n+\t\tvalue = hw_brightness ? SALS_KBD_BL_ON : SALS_KBD_BL_OFF;\n+\t\terr = exec_sals(priv-\u003eadev-\u003ehandle, value);\n \t}\n-\n \tif (err)\n \t\treturn err;\n \n-\tpriv-\u003ekbd_bl.last_brightness = brightness;\n+\tatomic_set(\u0026priv-\u003ekbd_bl.last_hw_brightness, hw_brightness);\n \n \treturn 0;\n }\n \n+static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, int brightness)\n+{\n+\tif (brightness \u003e priv-\u003ekbd_bl.led.max_brightness)\n+\t\treturn -EINVAL;\n+\n+\treturn ideapad_kbd_bl_hw_brightness_set(priv, brightness);\n+}\n+\n static int ideapad_kbd_bl_led_cdev_brightness_set(struct led_classdev *led_cdev,\n \t\t\t\t\t\t enum led_brightness brightness)\n {\n \tstruct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);\n \n+\t/*\n+\t * When deinitializing: It must be the side effect of led_cdev\n+\t * unregistration when our private trigger is active. We've set\n+\t * LED_RETAIN_AT_SHUTDOWN to retain led_cdev brightness level.\n+\t * To do the same for auto mode, gate changes and return early.\n+\t */\n+\tif (unlikely(!priv-\u003ekbd_bl.initialized))\n+\t\treturn 0;\n+\n \treturn ideapad_kbd_bl_brightness_set(priv, brightness);\n }\n \n+static bool ideapad_kbd_bl_auto_trigger_offloaded(struct led_classdev *led_cdev)\n+{\n+\tstruct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);\n+\n+\treturn atomic_read(\u0026priv-\u003ekbd_bl.last_hw_brightness) == KBD_BL_AUTO_MODE_HW_BRIGHTNESS;\n+}\n+\n+static int ideapad_kbd_bl_auto_trigger_activate(struct led_classdev *led_cdev)\n+{\n+\tstruct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);\n+\n+\treturn ideapad_kbd_bl_hw_brightness_set(priv, KBD_BL_AUTO_MODE_HW_BRIGHTNESS);\n+}\n+\n+static struct led_hw_trigger_type ideapad_kbd_bl_auto_trigger_type;\n+\n+static struct led_trigger ideapad_kbd_bl_auto_trigger = {\n+\t.name = \"ideapad-auto\",\n+\t.trigger_type = \u0026ideapad_kbd_bl_auto_trigger_type,\n+\t.activate = ideapad_kbd_bl_auto_trigger_activate,\n+\t.offloaded = ideapad_kbd_bl_auto_trigger_offloaded,\n+};\n+\n+static bool ideapad_kbd_bl_auto_trigger_registered;\n+\n+static void ideapad_kbd_bl_notify_hw_control(struct ideapad_private *priv,\n+\t\t\t\t\t int hw_brightness, int last_hw_brightness)\n+{\n+\tbool hw_control, last_hw_control;\n+\n+\tif (!ideapad_kbd_bl_auto_trigger_registered || priv-\u003ekbd_bl.type != KBD_BL_TRISTATE_AUTO)\n+\t\treturn;\n+\n+\thw_control = hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS;\n+\tlast_hw_control = last_hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS;\n+\n+\tif (hw_control != last_hw_control)\n+\t\tled_trigger_notify_hw_control_changed(\u0026priv-\u003ekbd_bl.led, hw_control);\n+}\n+\n static void ideapad_kbd_bl_notify(struct ideapad_private *priv)\n {\n-\tint brightness;\n+\tint hw_brightness, brightness, last_hw_brightness;\n \n \tif (!priv-\u003ekbd_bl.initialized)\n \t\treturn;\n \n-\tbrightness = ideapad_kbd_bl_brightness_get(priv);\n-\tif (brightness \u003c 0)\n+\tguard(mutex)(\u0026priv-\u003ekbd_bl.notif_mutex);\n+\n+\thw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);\n+\tif (hw_brightness \u003c 0)\n \t\treturn;\n \n-\tif (brightness == priv-\u003ekbd_bl.last_brightness)\n+\tbrightness = ideapad_kbd_bl_brightness_parse(priv, hw_brightness);\n+\tif (brightness \u003c 0)\n+\t\treturn; /* Reject insane values early. */\n+\n+\tlast_hw_brightness = atomic_xchg(\u0026priv-\u003ekbd_bl.last_hw_brightness, hw_brightness);\n+\tif (hw_brightness == last_hw_brightness)\n \t\treturn;\n \n-\tpriv-\u003ekbd_bl.last_brightness = brightness;\n+\tideapad_kbd_bl_notify_hw_control(priv, hw_brightness, last_hw_brightness);\n \n \tled_classdev_notify_brightness_hw_changed(\u0026priv-\u003ekbd_bl.led, brightness);\n }\n \n static int ideapad_kbd_bl_init(struct ideapad_private *priv)\n {\n-\tint brightness, err;\n+\tint hw_brightness, err;\n \n \tif (!priv-\u003efeatures.kbd_bl)\n \t\treturn -ENODEV;\n@@ -1700,28 +1805,73 @@ static int ideapad_kbd_bl_init(struct ideapad_private *priv)\n \tif (WARN_ON(priv-\u003ekbd_bl.initialized))\n \t\treturn -EEXIST;\n \n-\tif (ideapad_kbd_bl_check_tristate(priv-\u003ekbd_bl.type))\n-\t\tpriv-\u003ekbd_bl.led.max_brightness = 2;\n-\telse\n-\t\tpriv-\u003ekbd_bl.led.max_brightness = 1;\n+\terr = devm_mutex_init(\u0026priv-\u003eplatform_device-\u003edev, \u0026priv-\u003ekbd_bl.notif_mutex);\n+\tif (err)\n+\t\treturn err;\n \n-\tbrightness = ideapad_kbd_bl_brightness_get(priv);\n-\tif (brightness \u003c 0)\n-\t\treturn brightness;\n+\thw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);\n+\tif (hw_brightness \u003c 0)\n+\t\treturn hw_brightness;\n+\n+\tatomic_set(\u0026priv-\u003ekbd_bl.last_hw_brightness, hw_brightness);\n \n-\tpriv-\u003ekbd_bl.last_brightness = brightness;\n \tpriv-\u003ekbd_bl.led.name = \"platform::\" LED_FUNCTION_KBD_BACKLIGHT;\n \tpriv-\u003ekbd_bl.led.brightness_get = ideapad_kbd_bl_led_cdev_brightness_get;\n \tpriv-\u003ekbd_bl.led.brightness_set_blocking = ideapad_kbd_bl_led_cdev_brightness_set;\n \tpriv-\u003ekbd_bl.led.flags = LED_BRIGHT_HW_CHANGED | LED_RETAIN_AT_SHUTDOWN;\n \n-\terr = led_classdev_register(\u0026priv-\u003eplatform_device-\u003edev, \u0026priv-\u003ekbd_bl.led);\n-\tif (err)\n+\tswitch (priv-\u003ekbd_bl.type) {\n+\tcase KBD_BL_TRISTATE_AUTO:\n+\t\tpriv-\u003ekbd_bl.led.max_brightness = 2;\n+\n+\t\tif (!ideapad_kbd_bl_auto_trigger_registered) {\n+\t\t\tdev_warn(\u0026priv-\u003eplatform_device-\u003edev,\n+\t\t\t\t \"Could not provide LED trigger %s for keyboard backlight\\n\",\n+\t\t\t\t ideapad_kbd_bl_auto_trigger.name);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tpriv-\u003ekbd_bl.led.flags |= LED_TRIG_HW_CHANGED;\n+\t\tpriv-\u003ekbd_bl.led.trigger_type = \u0026ideapad_kbd_bl_auto_trigger_type;\n+\t\tpriv-\u003ekbd_bl.led.hw_control_trigger = ideapad_kbd_bl_auto_trigger.name;\n+\n+\t\t/* Hardware remembers the last brightness level, including auto mode. */\n+\t\tif (hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS)\n+\t\t\tpriv-\u003ekbd_bl.led.default_trigger = ideapad_kbd_bl_auto_trigger.name;\n+\n+\t\tbreak;\n+\tcase KBD_BL_TRISTATE:\n+\t\tpriv-\u003ekbd_bl.led.max_brightness = 2;\n+\t\tbreak;\n+\tcase KBD_BL_STANDARD:\n+\t\tpriv-\u003ekbd_bl.led.max_brightness = 1;\n+\t\tbreak;\n+\tdefault:\n+\t\t/* This has already been validated by ideapad_check_features(). */\n+\t\tunreachable();\n+\t}\n+\n+\t/* Reject insane values. */\n+\terr = ideapad_kbd_bl_brightness_parse(priv, hw_brightness);\n+\tif (err \u003c 0)\n \t\treturn err;\n \n+\t/* Queue notifications, as kbd_bl.initialized is about to be set. */\n+\tguard(mutex)(\u0026priv-\u003ekbd_bl.notif_mutex);\n+\n+\t/*\n+\t * Setting kbd_bl.initialized after led_classdev_register() could lead\n+\t * to race conditions in ideapad_kbd_bl_led_cdev_brightness_set() where\n+\t * kbd_bl.initialized is checked, so set it now. It can be reverted back\n+\t * if the LED classdev failed to register.\n+\t */\n \tpriv-\u003ekbd_bl.initialized = true;\n \n-\treturn 0;\n+\terr = led_classdev_register(\u0026priv-\u003eplatform_device-\u003edev, \u0026priv-\u003ekbd_bl.led);\n+\tif (err)\n+\t\tpriv-\u003ekbd_bl.initialized = false;\n+\n+\treturn err;\n }\n \n static void ideapad_kbd_bl_exit(struct ideapad_private *priv)\n@@ -2548,17 +2698,30 @@ static int __init ideapad_laptop_init(void)\n {\n \tint err;\n \n+\terr = led_trigger_register(\u0026ideapad_kbd_bl_auto_trigger);\n+\tif (err) {\n+\t\tpr_warn(\"Failed to register LED trigger %s: %d\\n\",\n+\t\t\tideapad_kbd_bl_auto_trigger.name, err);\n+\t} else {\n+\t\tideapad_kbd_bl_auto_trigger_registered = true;\n+\t}\n+\n \terr = ideapad_wmi_driver_register();\n \tif (err)\n-\t\treturn err;\n+\t\tgoto err_ledtrig;\n \n \terr = platform_driver_register(\u0026ideapad_acpi_driver);\n-\tif (err) {\n-\t\tideapad_wmi_driver_unregister();\n-\t\treturn err;\n-\t}\n+\tif (err)\n+\t\tgoto err_wmi;\n \n \treturn 0;\n+\n+err_wmi:\n+\tideapad_wmi_driver_unregister();\n+err_ledtrig:\n+\tif (ideapad_kbd_bl_auto_trigger_registered)\n+\t\tled_trigger_unregister(\u0026ideapad_kbd_bl_auto_trigger);\n+\treturn err;\n }\n module_init(ideapad_laptop_init)\n \n@@ -2566,6 +2729,9 @@ static void __exit ideapad_laptop_exit(void)\n {\n \tplatform_driver_unregister(\u0026ideapad_acpi_driver);\n \tideapad_wmi_driver_unregister();\n+\n+\tif (ideapad_kbd_bl_auto_trigger_registered)\n+\t\tled_trigger_unregister(\u0026ideapad_kbd_bl_auto_trigger);\n }\n module_exit(ideapad_laptop_exit)\n \ndiff --git a/include/linux/leds.h b/include/linux/leds.h\nindex b16b803cc1ac5..167598962b73e 100644\n--- a/include/linux/leds.h\n+++ b/include/linux/leds.h\n@@ -109,6 +109,7 @@ struct led_classdev {\n #define LED_INIT_DEFAULT_TRIGGER BIT(23)\n #define LED_REJECT_NAME_CONFLICT BIT(24)\n #define LED_MULTI_COLOR\t\tBIT(25)\n+#define LED_TRIG_HW_CHANGED\tBIT(26)\n \n \t/* set_brightness_work / blink_timer flags, atomic, private. */\n \tunsigned long\t\twork_flags;\n@@ -485,6 +486,7 @@ struct led_trigger {\n \tconst char\t *name;\n \tint\t\t(*activate)(struct led_classdev *led_cdev);\n \tvoid\t\t(*deactivate)(struct led_classdev *led_cdev);\n+\tbool\t\t(*offloaded)(struct led_classdev *led_cdev);\n \n \t/* Brightness set by led_trigger_event */\n \tenum led_brightness brightness;\n@@ -533,6 +535,9 @@ void led_trigger_blink_oneshot(struct led_trigger *trigger,\n void led_trigger_set_default(struct led_classdev *led_cdev);\n int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger);\n void led_trigger_remove(struct led_classdev *led_cdev);\n+void led_trigger_remove_hw_control(struct led_classdev *led_cdev);\n+\n+bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev);\n \n static inline void led_set_trigger_data(struct led_classdev *led_cdev,\n \t\t\t\t\tvoid *trigger_data)\n@@ -584,6 +589,13 @@ static inline int led_trigger_set(struct led_classdev *led_cdev,\n }\n \n static inline void led_trigger_remove(struct led_classdev *led_cdev) {}\n+static inline void led_trigger_remove_hw_control(struct led_classdev *led_cdev) {}\n+\n+static inline bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)\n+{\n+\treturn false;\n+}\n+\n static inline void led_set_trigger_data(struct led_classdev *led_cdev) {}\n static inline void *led_get_trigger_data(struct led_classdev *led_cdev)\n {\n@@ -598,6 +610,13 @@ led_trigger_get_brightness(const struct led_trigger *trigger)\n \n #endif /* CONFIG_LEDS_TRIGGERS */\n \n+#ifdef CONFIG_LEDS_TRIGGERS_HW_CHANGED\n+void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev, bool activate);\n+#else\n+static inline void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev,\n+\t\t\t\t\t\t\t bool activate) {}\n+#endif\n+\n /* Trigger specific enum */\n enum led_trigger_netdev_modes {\n \tTRIGGER_NETDEV_LINK = 0,\n"
} |
| 2/1 | 2026/08/20 17:46 | agent | patch-evaluator |
1mModel:best-expensive Args: null Results: {
"EnableConfigs": [
"LEDS_CLASS",
"LEDS_TRIGGERS",
"LEDS_TRIGGERS_HW_CHANGED",
"LEDS_TRIGGER_NETDEV"
],
"FocusSymbols": [
"led_trigger_is_hw_controlled",
"led_trigger_remove_hw_control",
"trigger_may_offload_show"
],
"Reasoning": "The patch introduces support for hardware-initiated LED trigger transitions and a new sysfs attribute `trigger_may_offload` to query supported triggers and their states. It modifies the core LED class and trigger subsystems, which are reachable via sysfs for any LED device. It also updates the `netdev` LED trigger to report its offloaded state. These core changes and the `netdev` trigger modifications are reachable in virtualized environments and have functional impact.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer. Your job is to review a provided patch series and determine if it makes functional changes to the kernel that should be fuzzed. IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively use your code access tools to examine the actual source code and confirm any assumptions. Return WorthFuzzing=false if the patch only contains: - Modifications to Documentation/, Kconfig files, or code comments. - Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints. - Changes to numeric constants or macros that do not functionally alter execution flow. - Code paths that are impossible to reach in virtualized environments like GCE or QEMU, even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim). - Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed, ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU. - Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove) that are executed only during PCI hot-unplug or sysfs driver unbind operations. If it modifies reachable core kernel logic, drivers, or architectures, use your code search tools to verify the code can be executed, then return WorthFuzzing=true. When returning WorthFuzzing=true, you MUST ALSO: 1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols. Avoid listing generic hot-path functions to prevent skewed test distributions. Prefer non-static, non-inlined API entrypoint functions over internal static helper functions (which are inlined by the compiler and do not have distinct symbol addresses). 2. Identify any specific CONFIG_ options required to properly test this new/modified feature. Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions. Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4"). Prefer calling several tools at the same time to save round-trips. Use set-results tool to provide results of the analysis. It must be called exactly once before the final reply. Ignore results of this tool. Prompt: For your convenience, here is the diff of the changes:
commit 2533c2922f89dde807e90d3942b7376dcf715d33
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Aug 20 17:46:18 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led
index d4c918cc11a12..2a13c77aee229 100644
--- a/Documentation/ABI/testing/sysfs-class-led
+++ b/Documentation/ABI/testing/sysfs-class-led
@@ -78,6 +78,31 @@ Description:
(which would often be configured in the device tree for the
hardware).
+What: /sys/class/leds/<led>/trigger_may_offload
+Date: August 2026
+KernelVersion: 7.3
+Contact: linux-leds@vger.kernel.org
+Description:
+ Names and states of triggers that may be offloaded to hardware.
+ Such triggers are also called "hardware control trigger" in some
+ context.
+
+ Only exists when the LED supports trigger offload.
+
+ Reading this file returns a list of triggers that are capable to
+ be offloaded. The optional brackets around the trigger name
+ indicate the state of the current trigger:
+
+ - `foo_trigger`: the trigger is not selected.
+ - `<foo_trigger>`: the trigger is selected, but falls back to
+ software blink for some reason (e.g., incompatible trigger
+ parameters)
+ - `[foo_trigger]`: the trigger is selected and offloaded to
+ hardware.
+
+ The "netdev" trigger also provides a custom attribute to
+ indicate its state, see `/sys/class/leds/<led>/offloaded`.
+
What: /sys/class/leds/<led>/inverted
Date: January 2011
KernelVersion: 2.6.38
diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev
index ed46b37ab8a28..a5146ea1e3e61 100644
--- a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev
+++ b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev
@@ -75,6 +75,9 @@ Description:
If 1, the LED blinking in requested mode is offloaded to
hardware.
+ LED trigger core also provides a generic attribute for this
+ purpose, see `/sys/class/leds/<led>/trigger_may_offload`.
+
What: /sys/class/leds/<led>/link_10
Date: Jun 2023
KernelVersion: 6.5
diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst
index 3913966cfdac0..adbc57b9f49c3 100644
--- a/Documentation/leds/leds-class.rst
+++ b/Documentation/leds/leds-class.rst
@@ -242,6 +242,9 @@ ops and needs to declare specific support for the supported triggers.
With hw control we refer to the LED driven by hardware.
+A sysfs attribute `trigger_may_offload` is provided for userspace to
+query supported triggers and their states.
+
LED driver must define the following value to support hw control:
- hw_control_trigger:
@@ -298,6 +301,15 @@ LED driver must implement the following API to support hw control:
Returns a pointer to a struct device or NULL if nothing
is currently attached.
+LED trigger should implement the following API to indicate hw control:
+ - offloaded:
+ return a boolean indicating if the trigger is currently
+ offloaded to hardware.
+
+ If a trigger doesn't implement this callback, the default
+ value will be true for private triggers and false for generic
+ ones.
+
LED driver can activate additional modes by default to workaround the
impossibility of supporting each different mode on the supported trigger.
Examples are hardcoding the blink speed to a set interval, enable special
@@ -311,9 +323,69 @@ the end use hw_control_set to activate hw control.
A trigger can use hw_control_get to check if a LED is already in hw control
and init their flags.
+Alternatively, a private trigger can be implemented along with the LED driver if
+the LED's hardware control doesn't fit any generic trigger. To associate the
+private trigger with the LED classdev, their `trigger_type` must be the same. To
+declare that the private trigger provides hardware control for the associated
+LED classdev, set the `hw_control_trigger` string to the trigger's name. Since
+both the LED classdev and the private trigger are in the same LED driver, it's
+not necessary for them to coordinate via `hw_control_*` callbacks.
+
When the LED is in hw control, no software blink is possible and doing so
will effectively disable hw control.
+Hardware-initiated trigger transition
+=====================================
+
+Some hardware can autonomously activate/deactivate hardware control. After that,
+the LED hardware notifies the LED driver.
+
+If the driver can detect such transitions and thus wants to notify the LED core
+to update the current trigger then the `LED_TRIG_HW_CHANGED` flag must be set in
+flags before registering. To update the current trigger accordingly, call
+`led_trigger_notify_hw_control_changed` on the LED classdev.
+
+This capability is restricted to the LED device's private trigger. The private
+trigger must have been properly registered (see above) and named after
+`hw_control_trigger`.
+
+Only two transitions are defined:
+
+- "none" => private trigger:
+ This happens when the hardware autonomously activates hardware control
+ and when "none" (i.e., no trigger) is currently active. If the private
+ trigger is already active when the method is called, this is essentially
+ a no-op.
+
+ The activation sequence for the private trigger will be executed as
+ normal.
+
+ The LED driver and its private trigger must be able to handle the
+ activation sequence even if the hardware is currently in hardware
+ control.
+
+ If error occurs in the activation sequence, the LED Trigger core reverts
+ the effective trigger to "none".
+
+- private trigger => "none"
+ This happens when the hardware autonomously deactivates hardware control
+ and when the private trigger is currently active. If "none" (i.e., no
+ trigger) is active when the method is called, this is essentially a
+ no-op.
+
+ The deactivation sequence for the private trigger will be executed as
+ normal, except that the current LED brightness is retained. The reason
+ for keeping the brightness unchanged is that some hardware may choose a
+ specific brightness instead of simply turning off the LED after
+ autonomously deactivating hardware control.
+
+ The LED driver and its private trigger must be able to handle the
+ deactivation sequence even if the hardware is not currently in hardware
+ control.
+
+If the current trigger is neither the private trigger nor "none", no transition
+will be made.
+
Known Issues
============
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index a51b0ed538864..771a6e6c659be 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -27,16 +27,6 @@ static LIST_HEAD(leds_lookup_list);
static struct workqueue_struct *leds_wq;
-static bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)
-{
-#ifdef CONFIG_LEDS_TRIGGERS
- guard(rwsem_read)(&led_cdev->trigger_lock);
- return led_cdev->trigger && led_cdev->trigger->trigger_type;
-#else
- return false;
-#endif
-}
-
static ssize_t brightness_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -74,6 +64,9 @@ static ssize_t brightness_store(struct device *dev,
if (state == LED_OFF)
led_trigger_remove(led_cdev);
+ else
+ led_trigger_remove_hw_control(led_cdev);
+
led_set_brightness(led_cdev, state);
ret = size;
@@ -103,8 +96,30 @@ static const struct bin_attribute *const led_trigger_bin_attrs[] = {
&bin_attr_trigger,
NULL,
};
+
+static DEVICE_ATTR_RO(trigger_may_offload);
+static struct attribute *led_trigger_attrs[] = {
+ &dev_attr_trigger_may_offload.attr,
+ NULL
+};
+
+static umode_t led_trigger_is_visible(struct kobject *kobj,
+ struct attribute *attr,
+ int idx)
+{
+ struct device *dev = kobj_to_dev(kobj);
+ struct led_classdev *led_cdev = dev_get_drvdata(dev);
+
+ if (attr == &dev_attr_trigger_may_offload.attr)
+ return led_cdev->hw_control_trigger ? attr->mode : 0;
+
+ return attr->mode;
+}
+
static const struct attribute_group led_trigger_group = {
.bin_attrs = led_trigger_bin_attrs,
+ .attrs = led_trigger_attrs,
+ .is_visible = led_trigger_is_visible,
};
#endif
@@ -618,12 +633,13 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
#ifdef CONFIG_LEDS_TRIGGERS
down_write(&led_cdev->trigger_lock);
+ led_cdev->flags |= LED_UNREGISTERING;
if (led_cdev->trigger)
led_trigger_set(led_cdev, NULL);
up_write(&led_cdev->trigger_lock);
-#endif
-
+#else
led_cdev->flags |= LED_UNREGISTERING;
+#endif
/* Stop blinking */
led_stop_software_blink(led_cdev);
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index b1223218bda11..32c9d19374c4e 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -7,9 +7,12 @@
* Author: Richard Purdie <rpurdie@openedhand.com>
*/
+#include <linux/bug.h>
+#include <linux/cleanup.h>
#include <linux/export.h>
#include <linux/kernel.h>
#include <linux/list.h>
+#include <linux/lockdep.h>
#include <linux/spinlock.h>
#include <linux/device.h>
#include <linux/timer.h>
@@ -33,6 +36,34 @@ trigger_relevant(struct led_classdev *led_cdev, struct led_trigger *trig)
return !trig->trigger_type || trig->trigger_type == led_cdev->trigger_type;
}
+static bool __led_trigger_is_hw_controlled(struct led_classdev *led_cdev)
+{
+ lockdep_assert_held(&led_cdev->trigger_lock);
+
+ if (!led_cdev->trigger)
+ return false;
+
+ if (!led_cdev->hw_control_trigger ||
+ strcmp(led_cdev->hw_control_trigger, led_cdev->trigger->name))
+ return false;
+
+ if (led_cdev->trigger->offloaded)
+ return led_cdev->trigger->offloaded(led_cdev);
+
+ dev_warn_once(led_cdev->dev, "hw control trigger %s doesn't implement offloaded()\n",
+ led_cdev->trigger->name);
+
+ /* Otherwise assume private triggers as always offloaded. */
+ return led_cdev->trigger->trigger_type;
+}
+
+bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)
+{
+ guard(rwsem_read)(&led_cdev->trigger_lock);
+ return __led_trigger_is_hw_controlled(led_cdev);
+}
+EXPORT_SYMBOL_GPL(led_trigger_is_hw_controlled);
+
ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
const struct bin_attribute *bin_attr, char *buf,
loff_t pos, size_t count)
@@ -163,13 +194,17 @@ ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
EXPORT_SYMBOL_GPL(led_trigger_read);
/* Caller must ensure led_cdev->trigger_lock held */
-int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
+static int __led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig,
+ bool hw_triggered)
{
char *event = NULL;
char *envp[2];
const char *name;
int ret;
+ if ((led_cdev->flags & LED_UNREGISTERING) && trig)
+ return -ENODEV;
+
if (!led_cdev->trigger && !trig)
return 0;
@@ -194,7 +229,21 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
led_cdev->trigger_data = NULL;
led_cdev->activated = false;
led_cdev->flags &= ~LED_INIT_DEFAULT_TRIGGER;
- led_set_brightness(led_cdev, LED_OFF);
+
+ /*
+ * Hardware may have selected a new brightness level during its
+ * hardware control transition, so only reset brightness if we
+ * are switching to another trigger or if the switching is not
+ * hardware triggered.
+ *
+ * Note that this does not apply to the error path, as running
+ * into the error path implies a none => private trigger
+ * transition. This hints that the LED driver and its private
+ * trigger must have some fundamental bugs, so don't bother
+ * leaving the LED in an undefined state.
+ */
+ if (trig || !hw_triggered)
+ led_set_brightness(led_cdev, LED_OFF);
}
if (trig) {
spin_lock(&trig->leddev_list_lock);
@@ -258,6 +307,11 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
return ret;
}
+
+int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
+{
+ return __led_trigger_set(led_cdev, trig, false);
+}
EXPORT_SYMBOL_GPL(led_trigger_set);
void led_trigger_remove(struct led_classdev *led_cdev)
@@ -268,6 +322,15 @@ void led_trigger_remove(struct led_classdev *led_cdev)
}
EXPORT_SYMBOL_GPL(led_trigger_remove);
+void led_trigger_remove_hw_control(struct led_classdev *led_cdev)
+{
+ guard(rwsem_write)(&led_cdev->trigger_lock);
+
+ if (__led_trigger_is_hw_controlled(led_cdev))
+ led_trigger_set(led_cdev, NULL);
+}
+EXPORT_SYMBOL_GPL(led_trigger_remove_hw_control);
+
static bool led_match_default_trigger(struct led_classdev *led_cdev,
struct led_trigger *trig)
{
@@ -313,6 +376,32 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
}
EXPORT_SYMBOL_GPL(led_trigger_set_default);
+ssize_t trigger_may_offload_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct led_classdev *led_cdev = dev_get_drvdata(dev);
+ struct led_trigger *trig;
+ bool hit, offloaded;
+ int len;
+
+ guard(mutex)(&led_cdev->led_access);
+ guard(rwsem_read)(&led_cdev->trigger_lock);
+
+ trig = led_cdev->trigger;
+
+ offloaded = __led_trigger_is_hw_controlled(led_cdev);
+ hit = offloaded || (trig && !strcmp(led_cdev->hw_control_trigger, trig->name));
+
+ /* [offloaded] <active_but_not_offloaded> inactive */
+ len = sysfs_emit(buf, "%s%s%s\n",
+ offloaded ? "[" : (hit ? "<" : ""),
+ led_cdev->hw_control_trigger,
+ offloaded ? "]" : (hit ? ">" : ""));
+
+ return len;
+}
+EXPORT_SYMBOL_GPL(trigger_may_offload_show);
+
/* LED Trigger Interface */
int led_trigger_register(struct led_trigger *trig)
@@ -403,6 +492,65 @@ int devm_led_trigger_register(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_led_trigger_register);
+#ifdef CONFIG_LEDS_TRIGGERS_HW_CHANGED
+static void led_trigger_do_hw_control_transition(struct led_classdev *led_cdev, bool activate,
+ struct led_trigger *hc_trig)
+{
+ int err = 0;
+
+ if (!led_cdev->trigger) {
+ /* "none" => private trigger. */
+ if (activate)
+ err = __led_trigger_set(led_cdev, hc_trig, true);
+ } else if (led_cdev->trigger == hc_trig) {
+ /* private trigger => "none". */
+ if (!activate)
+ err = __led_trigger_set(led_cdev, NULL, true);
+ } else {
+ /* Other trigger is active. */
+ dev_dbg(led_cdev->dev,
+ "Ignoring hw control transition (%s %s) while %s is active",
+ activate ? "activate" : "deactivate", hc_trig->name,
+ led_cdev->trigger->name);
+
+ return;
+ }
+
+ if (err)
+ dev_warn(led_cdev->dev, "Failed to %s %s in hw control transition: %d",
+ activate ? "activate" : "deactivate", hc_trig->name, err);
+}
+
+void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev, bool activate)
+{
+ struct led_trigger *trig;
+
+ might_sleep();
+
+ /* Restricted to private triggers. */
+ if (WARN_ON(!(led_cdev->flags & LED_TRIG_HW_CHANGED) ||
+ !led_cdev->hw_control_trigger || !led_cdev->trigger_type))
+ return;
+
+ scoped_guard(rwsem_read, &triggers_list_lock) {
+ list_for_each_entry(trig, &trigger_list, next_trig) {
+ if (trig->trigger_type == led_cdev->trigger_type &&
+ !strcmp(trig->name, led_cdev->hw_control_trigger)) {
+ guard(rwsem_write)(&led_cdev->trigger_lock);
+
+ led_trigger_do_hw_control_transition(led_cdev, activate, trig);
+ return;
+ }
+ }
+ }
+
+ dev_err(led_cdev->dev,
+ "%s() is called, but the private trigger (%s) is not properly registered\n",
+ __func__, led_cdev->hw_control_trigger);
+}
+EXPORT_SYMBOL_GPL(led_trigger_notify_hw_control_changed);
+#endif /* CONFIG_LEDS_TRIGGERS_HW_CHANGED */
+
/* Simple LED Trigger Interface */
void led_trigger_event(struct led_trigger *trig,
diff --git a/drivers/leds/leds-cros_ec.c b/drivers/leds/leds-cros_ec.c
index 1844d0cd5f528..6db83d0152775 100644
--- a/drivers/leds/leds-cros_ec.c
+++ b/drivers/leds/leds-cros_ec.c
@@ -85,12 +85,18 @@ static int cros_ec_led_trigger_activate(struct led_classdev *led_cdev)
return cros_ec_led_send_cmd(priv->cros_ec, &arg);
}
+static bool cros_ec_led_trigger_offloaded(struct led_classdev *led_cdev)
+{
+ return true;
+}
+
static struct led_hw_trigger_type cros_ec_led_trigger_type;
static struct led_trigger cros_ec_led_trigger = {
.name = "chromeos-auto",
.trigger_type = &cros_ec_led_trigger_type,
.activate = cros_ec_led_trigger_activate,
+ .offloaded = cros_ec_led_trigger_offloaded,
};
static int cros_ec_led_brightness_set_blocking(struct led_classdev *led_cdev,
diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index ed6a47bbb44f9..32d40d176d3f1 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -195,10 +195,16 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev)
err);
}
+static bool omnia_hwtrig_offloaded(struct led_classdev *cdev)
+{
+ return true;
+}
+
static struct led_trigger omnia_hw_trigger = {
.name = "omnia-mcu",
.activate = omnia_hwtrig_activate,
.deactivate = omnia_hwtrig_deactivate,
+ .offloaded = omnia_hwtrig_offloaded,
.trigger_type = &omnia_hw_trigger_type,
};
@@ -251,6 +257,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,
* by LED class from the linux,default-trigger property.
*/
cdev->default_trigger = omnia_hw_trigger.name;
+ cdev->hw_control_trigger = omnia_hw_trigger.name;
/* Put the LED into software mode */
ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(led->reg) |
diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
index bee46651e068f..b08a289397e46 100644
--- a/drivers/leds/leds.h
+++ b/drivers/leds/leds.h
@@ -27,6 +27,8 @@ ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
const struct bin_attribute *bin_attr, char *buf,
loff_t pos, size_t count);
+ssize_t trigger_may_offload_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
extern struct rw_semaphore leds_list_lock;
extern struct list_head leds_list;
diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
index c11282a74b5ac..a11d04ce4ab2c 100644
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -9,6 +9,16 @@ menuconfig LEDS_TRIGGERS
if LEDS_TRIGGERS
+config LEDS_TRIGGERS_HW_CHANGED
+ bool "LED hardware-initiated trigger transition support"
+ default LEDS_BRIGHTNESS_HW_CHANGED
+ help
+ This option enables support for hardware initiated hardware control
+ transitions, where the LED hardware autonomously switches between
+ "none" (i.e., no trigger) and its private trigger.
+
+ See Documentation/leds/leds-class.rst for details.
+
config LEDS_TRIGGER_TIMER
tristate "LED Timer Trigger"
help
diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 64c078e997f28..a26109ca4b1c9 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -754,10 +754,18 @@ static void netdev_trig_deactivate(struct led_classdev *led_cdev)
kfree(trigger_data);
}
+static bool netdev_trig_offloaded(struct led_classdev *led_cdev)
+{
+ struct led_netdev_data *trigger_data = led_get_trigger_data(led_cdev);
+
+ return trigger_data->hw_control;
+}
+
static struct led_trigger netdev_led_trigger = {
.name = "netdev",
.activate = netdev_trig_activate,
.deactivate = netdev_trig_deactivate,
+ .offloaded = netdev_trig_offloaded,
.groups = netdev_trig_groups,
};
diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
index 4443f40ef8aa7..e92b1e9007951 100644
--- a/drivers/platform/x86/lenovo/Kconfig
+++ b/drivers/platform/x86/lenovo/Kconfig
@@ -16,6 +16,7 @@ config IDEAPAD_LAPTOP
select INPUT_SPARSEKMAP
select NEW_LEDS
select LEDS_CLASS
+ select LEDS_TRIGGERS
help
This is a driver for Lenovo IdeaPad netbooks contains drivers for
rfkill switch, hotkey, fan control and backlight control.
diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
index 8213524504eeb..5442cbfe3969b 100644
--- a/drivers/platform/x86/lenovo/ideapad-laptop.c
+++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
@@ -9,14 +9,18 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/acpi.h>
+#include <linux/atomic.h>
#include <linux/backlight.h>
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/cleanup.h>
+#include <linux/compiler.h>
+#include <linux/container_of.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/device.h>
+#include <linux/dev_printk.h>
#include <linux/dmi.h>
#include <linux/i8042.h>
#include <linux/init.h>
@@ -26,9 +30,11 @@
#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/platform_profile.h>
#include <linux/power_supply.h>
+#include <linux/printk.h>
#include <linux/rfkill.h>
#include <linux/seq_file.h>
#include <linux/string_choices.h>
@@ -134,10 +140,31 @@ enum {
};
/*
- * These correspond to the number of supported states - 1
- * Future keyboard types may need a new system, if there's a collision
- * KBD_BL_TRISTATE_AUTO has no way to report or set the auto state
- * so it effectively has 3 states, but needs to handle 4
+ * The enumeration has two purposes:
+ * - as an internal identifier for all known types of keyboard backlight
+ * - as a mandatory parameter of the KBLC command
+ *
+ * For each type, the hardware brightness values are defined as follows:
+ * +--------------------------+----------+-----+------+------+
+ * | Hardware brightness | 0 | 1 | 2 | 3 |
+ * | Type | | | | |
+ * +--------------------------+----------+-----+------+------+
+ * | KBD_BL_STANDARD | off | on | N/A | N/A |
+ * +--------------------------+----------+-----+------+------+
+ * | KBD_BL_TRISTATE | off | low | high | N/A |
+ * +--------------------------+----------+-----+------+------+
+ * | KBD_BL_TRISTATE_AUTO | off | low | high | auto |
+ * +--------------------------+----------+-----+------+------+
+ *
+ * We map LED classdev brightness for KBD_BL_TRISTATE_AUTO as follows:
+ * +--------------------------+----------+-----+------+
+ * | LED classdev brightness | 0 | 1 | 2 |
+ * | Operation | | | |
+ * +--------------------------+----------+-----+------+
+ * | Read | off/auto | low | high |
+ * +--------------------------+----------+-----+------+
+ * | Write | off | low | high |
+ * +--------------------------+----------+-----+------+
*/
enum {
KBD_BL_STANDARD = 1,
@@ -145,6 +172,8 @@ enum {
KBD_BL_TRISTATE_AUTO = 3,
};
+#define KBD_BL_AUTO_MODE_HW_BRIGHTNESS 3
+
#define KBD_BL_QUERY_TYPE 0x1
#define KBD_BL_TRISTATE_TYPE 0x5
#define KBD_BL_TRISTATE_AUTO_TYPE 0x7
@@ -203,7 +232,9 @@ struct ideapad_private {
bool initialized;
int type;
struct led_classdev led;
- unsigned int last_brightness;
+ atomic_t last_hw_brightness;
+
+ struct mutex notif_mutex; /* protects notifications */
} kbd_bl;
struct {
bool initialized;
@@ -1592,7 +1623,24 @@ static int ideapad_kbd_bl_check_tristate(int type)
return (type == KBD_BL_TRISTATE) || (type == KBD_BL_TRISTATE_AUTO);
}
-static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)
+static int ideapad_kbd_bl_brightness_parse(struct ideapad_private *priv, int hw_brightness)
+{
+ /* Off, low or high */
+ if (hw_brightness <= priv->kbd_bl.led.max_brightness)
+ return hw_brightness;
+
+ /* Auto (controlled by EC according to ALS), report as off */
+ if (priv->kbd_bl.type == KBD_BL_TRISTATE_AUTO &&
+ hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS)
+ return 0;
+
+ /* Unknown value */
+ dev_warn(&priv->platform_device->dev,
+ "Unknown keyboard backlight value: %d", hw_brightness);
+ return -EINVAL;
+}
+
+static int ideapad_kbd_bl_hw_brightness_get(struct ideapad_private *priv)
{
unsigned long value;
int err;
@@ -1606,21 +1654,7 @@ static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)
if (err)
return err;
- /* Convert returned value to brightness level */
- value = FIELD_GET(KBD_BL_GET_BRIGHTNESS, value);
-
- /* Off, low or high */
- if (value <= priv->kbd_bl.led.max_brightness)
- return value;
-
- /* Auto, report as off */
- if (value == priv->kbd_bl.led.max_brightness + 1)
- return 0;
-
- /* Unknown value */
- dev_warn(&priv->platform_device->dev,
- "Unknown keyboard backlight value: %lu", value);
- return -EINVAL;
+ return FIELD_GET(KBD_BL_GET_BRIGHTNESS, value);
}
err = eval_hals(priv->adev->handle, &value);
@@ -1630,6 +1664,16 @@ static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)
return !!test_bit(HALS_KBD_BL_STATE_BIT, &value);
}
+static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)
+{
+ int hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);
+
+ if (hw_brightness < 0)
+ return hw_brightness;
+
+ return ideapad_kbd_bl_brightness_parse(priv, hw_brightness);
+}
+
static enum led_brightness ideapad_kbd_bl_led_cdev_brightness_get(struct led_classdev *led_cdev)
{
struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);
@@ -1637,62 +1681,123 @@ static enum led_brightness ideapad_kbd_bl_led_cdev_brightness_get(struct led_cla
return ideapad_kbd_bl_brightness_get(priv);
}
-static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, unsigned int brightness)
+static int ideapad_kbd_bl_hw_brightness_set(struct ideapad_private *priv, int hw_brightness)
{
- int err;
unsigned long value;
int type = priv->kbd_bl.type;
+ int err;
if (ideapad_kbd_bl_check_tristate(type)) {
- if (brightness > priv->kbd_bl.led.max_brightness)
- return -EINVAL;
-
- value = FIELD_PREP(KBD_BL_SET_BRIGHTNESS, brightness) |
+ value = FIELD_PREP(KBD_BL_SET_BRIGHTNESS, hw_brightness) |
FIELD_PREP(KBD_BL_COMMAND_TYPE, type) |
KBD_BL_COMMAND_SET;
err = exec_kblc(priv->adev->handle, value);
} else {
- err = exec_sals(priv->adev->handle, brightness ? SALS_KBD_BL_ON : SALS_KBD_BL_OFF);
+ value = hw_brightness ? SALS_KBD_BL_ON : SALS_KBD_BL_OFF;
+ err = exec_sals(priv->adev->handle, value);
}
-
if (err)
return err;
- priv->kbd_bl.last_brightness = brightness;
+ atomic_set(&priv->kbd_bl.last_hw_brightness, hw_brightness);
return 0;
}
+static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, int brightness)
+{
+ if (brightness > priv->kbd_bl.led.max_brightness)
+ return -EINVAL;
+
+ return ideapad_kbd_bl_hw_brightness_set(priv, brightness);
+}
+
static int ideapad_kbd_bl_led_cdev_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);
+ /*
+ * When deinitializing: It must be the side effect of led_cdev
+ * unregistration when our private trigger is active. We've set
+ * LED_RETAIN_AT_SHUTDOWN to retain led_cdev brightness level.
+ * To do the same for auto mode, gate changes and return early.
+ */
+ if (unlikely(!priv->kbd_bl.initialized))
+ return 0;
+
return ideapad_kbd_bl_brightness_set(priv, brightness);
}
+static bool ideapad_kbd_bl_auto_trigger_offloaded(struct led_classdev *led_cdev)
+{
+ struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);
+
+ return atomic_read(&priv->kbd_bl.last_hw_brightness) == KBD_BL_AUTO_MODE_HW_BRIGHTNESS;
+}
+
+static int ideapad_kbd_bl_auto_trigger_activate(struct led_classdev *led_cdev)
+{
+ struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);
+
+ return ideapad_kbd_bl_hw_brightness_set(priv, KBD_BL_AUTO_MODE_HW_BRIGHTNESS);
+}
+
+static struct led_hw_trigger_type ideapad_kbd_bl_auto_trigger_type;
+
+static struct led_trigger ideapad_kbd_bl_auto_trigger = {
+ .name = "ideapad-auto",
+ .trigger_type = &ideapad_kbd_bl_auto_trigger_type,
+ .activate = ideapad_kbd_bl_auto_trigger_activate,
+ .offloaded = ideapad_kbd_bl_auto_trigger_offloaded,
+};
+
+static bool ideapad_kbd_bl_auto_trigger_registered;
+
+static void ideapad_kbd_bl_notify_hw_control(struct ideapad_private *priv,
+ int hw_brightness, int last_hw_brightness)
+{
+ bool hw_control, last_hw_control;
+
+ if (!ideapad_kbd_bl_auto_trigger_registered || priv->kbd_bl.type != KBD_BL_TRISTATE_AUTO)
+ return;
+
+ hw_control = hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS;
+ last_hw_control = last_hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS;
+
+ if (hw_control != last_hw_control)
+ led_trigger_notify_hw_control_changed(&priv->kbd_bl.led, hw_control);
+}
+
static void ideapad_kbd_bl_notify(struct ideapad_private *priv)
{
- int brightness;
+ int hw_brightness, brightness, last_hw_brightness;
if (!priv->kbd_bl.initialized)
return;
- brightness = ideapad_kbd_bl_brightness_get(priv);
- if (brightness < 0)
+ guard(mutex)(&priv->kbd_bl.notif_mutex);
+
+ hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);
+ if (hw_brightness < 0)
return;
- if (brightness == priv->kbd_bl.last_brightness)
+ brightness = ideapad_kbd_bl_brightness_parse(priv, hw_brightness);
+ if (brightness < 0)
+ return; /* Reject insane values early. */
+
+ last_hw_brightness = atomic_xchg(&priv->kbd_bl.last_hw_brightness, hw_brightness);
+ if (hw_brightness == last_hw_brightness)
return;
- priv->kbd_bl.last_brightness = brightness;
+ ideapad_kbd_bl_notify_hw_control(priv, hw_brightness, last_hw_brightness);
led_classdev_notify_brightness_hw_changed(&priv->kbd_bl.led, brightness);
}
static int ideapad_kbd_bl_init(struct ideapad_private *priv)
{
- int brightness, err;
+ int hw_brightness, err;
if (!priv->features.kbd_bl)
return -ENODEV;
@@ -1700,28 +1805,73 @@ static int ideapad_kbd_bl_init(struct ideapad_private *priv)
if (WARN_ON(priv->kbd_bl.initialized))
return -EEXIST;
- if (ideapad_kbd_bl_check_tristate(priv->kbd_bl.type))
- priv->kbd_bl.led.max_brightness = 2;
- else
- priv->kbd_bl.led.max_brightness = 1;
+ err = devm_mutex_init(&priv->platform_device->dev, &priv->kbd_bl.notif_mutex);
+ if (err)
+ return err;
- brightness = ideapad_kbd_bl_brightness_get(priv);
- if (brightness < 0)
- return brightness;
+ hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);
+ if (hw_brightness < 0)
+ return hw_brightness;
+
+ atomic_set(&priv->kbd_bl.last_hw_brightness, hw_brightness);
- priv->kbd_bl.last_brightness = brightness;
priv->kbd_bl.led.name = "platform::" LED_FUNCTION_KBD_BACKLIGHT;
priv->kbd_bl.led.brightness_get = ideapad_kbd_bl_led_cdev_brightness_get;
priv->kbd_bl.led.brightness_set_blocking = ideapad_kbd_bl_led_cdev_brightness_set;
priv->kbd_bl.led.flags = LED_BRIGHT_HW_CHANGED | LED_RETAIN_AT_SHUTDOWN;
- err = led_classdev_register(&priv->platform_device->dev, &priv->kbd_bl.led);
- if (err)
+ switch (priv->kbd_bl.type) {
+ case KBD_BL_TRISTATE_AUTO:
+ priv->kbd_bl.led.max_brightness = 2;
+
+ if (!ideapad_kbd_bl_auto_trigger_registered) {
+ dev_warn(&priv->platform_device->dev,
+ "Could not provide LED trigger %s for keyboard backlight\n",
+ ideapad_kbd_bl_auto_trigger.name);
+ break;
+ }
+
+ priv->kbd_bl.led.flags |= LED_TRIG_HW_CHANGED;
+ priv->kbd_bl.led.trigger_type = &ideapad_kbd_bl_auto_trigger_type;
+ priv->kbd_bl.led.hw_control_trigger = ideapad_kbd_bl_auto_trigger.name;
+
+ /* Hardware remembers the last brightness level, including auto mode. */
+ if (hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS)
+ priv->kbd_bl.led.default_trigger = ideapad_kbd_bl_auto_trigger.name;
+
+ break;
+ case KBD_BL_TRISTATE:
+ priv->kbd_bl.led.max_brightness = 2;
+ break;
+ case KBD_BL_STANDARD:
+ priv->kbd_bl.led.max_brightness = 1;
+ break;
+ default:
+ /* This has already been validated by ideapad_check_features(). */
+ unreachable();
+ }
+
+ /* Reject insane values. */
+ err = ideapad_kbd_bl_brightness_parse(priv, hw_brightness);
+ if (err < 0)
return err;
+ /* Queue notifications, as kbd_bl.initialized is about to be set. */
+ guard(mutex)(&priv->kbd_bl.notif_mutex);
+
+ /*
+ * Setting kbd_bl.initialized after led_classdev_register() could lead
+ * to race conditions in ideapad_kbd_bl_led_cdev_brightness_set() where
+ * kbd_bl.initialized is checked, so set it now. It can be reverted back
+ * if the LED classdev failed to register.
+ */
priv->kbd_bl.initialized = true;
- return 0;
+ err = led_classdev_register(&priv->platform_device->dev, &priv->kbd_bl.led);
+ if (err)
+ priv->kbd_bl.initialized = false;
+
+ return err;
}
static void ideapad_kbd_bl_exit(struct ideapad_private *priv)
@@ -2548,17 +2698,30 @@ static int __init ideapad_laptop_init(void)
{
int err;
+ err = led_trigger_register(&ideapad_kbd_bl_auto_trigger);
+ if (err) {
+ pr_warn("Failed to register LED trigger %s: %d\n",
+ ideapad_kbd_bl_auto_trigger.name, err);
+ } else {
+ ideapad_kbd_bl_auto_trigger_registered = true;
+ }
+
err = ideapad_wmi_driver_register();
if (err)
- return err;
+ goto err_ledtrig;
err = platform_driver_register(&ideapad_acpi_driver);
- if (err) {
- ideapad_wmi_driver_unregister();
- return err;
- }
+ if (err)
+ goto err_wmi;
return 0;
+
+err_wmi:
+ ideapad_wmi_driver_unregister();
+err_ledtrig:
+ if (ideapad_kbd_bl_auto_trigger_registered)
+ led_trigger_unregister(&ideapad_kbd_bl_auto_trigger);
+ return err;
}
module_init(ideapad_laptop_init)
@@ -2566,6 +2729,9 @@ static void __exit ideapad_laptop_exit(void)
{
platform_driver_unregister(&ideapad_acpi_driver);
ideapad_wmi_driver_unregister();
+
+ if (ideapad_kbd_bl_auto_trigger_registered)
+ led_trigger_unregister(&ideapad_kbd_bl_auto_trigger);
}
module_exit(ideapad_laptop_exit)
diff --git a/include/linux/leds.h b/include/linux/leds.h
index b16b803cc1ac5..167598962b73e 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -109,6 +109,7 @@ struct led_classdev {
#define LED_INIT_DEFAULT_TRIGGER BIT(23)
#define LED_REJECT_NAME_CONFLICT BIT(24)
#define LED_MULTI_COLOR BIT(25)
+#define LED_TRIG_HW_CHANGED BIT(26)
/* set_brightness_work / blink_timer flags, atomic, private. */
unsigned long work_flags;
@@ -485,6 +486,7 @@ struct led_trigger {
const char *name;
int (*activate)(struct led_classdev *led_cdev);
void (*deactivate)(struct led_classdev *led_cdev);
+ bool (*offloaded)(struct led_classdev *led_cdev);
/* Brightness set by led_trigger_event */
enum led_brightness brightness;
@@ -533,6 +535,9 @@ void led_trigger_blink_oneshot(struct led_trigger *trigger,
void led_trigger_set_default(struct led_classdev *led_cdev);
int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger);
void led_trigger_remove(struct led_classdev *led_cdev);
+void led_trigger_remove_hw_control(struct led_classdev *led_cdev);
+
+bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev);
static inline void led_set_trigger_data(struct led_classdev *led_cdev,
void *trigger_data)
@@ -584,6 +589,13 @@ static inline int led_trigger_set(struct led_classdev *led_cdev,
}
static inline void led_trigger_remove(struct led_classdev *led_cdev) {}
+static inline void led_trigger_remove_hw_control(struct led_classdev *led_cdev) {}
+
+static inline bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)
+{
+ return false;
+}
+
static inline void led_set_trigger_data(struct led_classdev *led_cdev) {}
static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
{
@@ -598,6 +610,13 @@ led_trigger_get_brightness(const struct led_trigger *trigger)
#endif /* CONFIG_LEDS_TRIGGERS */
+#ifdef CONFIG_LEDS_TRIGGERS_HW_CHANGED
+void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev, bool activate);
+#else
+static inline void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev,
+ bool activate) {}
+#endif
+
/* Trigger specific enum */
enum led_trigger_netdev_modes {
TRIGGER_NETDEV_LINK = 0,
|
| 3/2 | 2026/08/20 17:46 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 15077 output: 20 thoughts: 184 Thoughts: **Analyzing the LED Trigger Patch for Virtualized Environments** Okay, so I'm looking at this patch series that adds hardware-initiated LED trigger transitions, targeting the "ideapad-laptop" driver. It seems pretty straightforward: updates to the LED core – `led-class.c`, `led-triggers.c` – and a new Kconfig option, `LEDS_TRIGGERS_HW_CHANGED`. Then, the "ideapad-laptop.c" driver is modified to actually *use* this new functionality. My immediate thought is, how testable is this in a virtualized environment? The "ideapad-laptop" driver is, as I recall, an x86 platform driver, designed for Lenovo IdeaPad laptops. It leans heavily on ACPI and WMI, right? My concern is that these platform drivers are notorious for requiring specific ACPI/WMI interfaces that are rarely present "out of the box" in standard virtualization setups like QEMU or Google Compute Engine – unless you've gone to the trouble of specifically emulating them. So, the question is, will the "ideapad-laptop" driver even *initialize* in a typical virtualized scenario? I should probably start by checking the driver's initialization routine in "ideapad-laptop.c" to get a better handle on its dependencies and what it's expecting to find. That'll be the key to figuring out how practical this is to debug without direct hardware access. |
| 4/2 | 2026/08/20 17:46 | tool | grepper |
0mArgs:{
"Expression": "ideapad_laptop_init"
}Results: {
"Output": "drivers/platform/x86/lenovo/ideapad-laptop.c=2686=static struct platform_driver ideapad_acpi_driver = {\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2696-\ndrivers/platform/x86/lenovo/ideapad-laptop.c:2697:static int __init ideapad_laptop_init(void)\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2698-{\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2725-}\ndrivers/platform/x86/lenovo/ideapad-laptop.c:2726:module_init(ideapad_laptop_init)\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2727-\n"
} |
| 5/2 | 2026/08/20 17:46 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 15810 output: 21 thoughts: 16 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Diving into the `ideapad_acpi_driver` Probe Function** Okay, time to dig in. The problem's likely with how the `ideapad_acpi_driver` is handling the hardware initialization or resource allocation. The probe function is the obvious first place to start. I need to refresh my memory on the likely failure points. I'm thinking: is it correctly identifying the device? Are the resources being requested properly? Is there an I/O conflict? Are there any obvious ACPI method calls that aren't handling errors correctly? I need to quickly scan the code for any potential null pointer dereferences, incorrect register accesses, or missing error handling after those ACPI calls. Gotta look for any dependencies on other drivers too, and make sure that ordering is correct. I’ll look specifically for any `dev_err`, `pr_err`, or similar error logging, hoping for a clue. Then I'll re-trace any assumptions that the driver is making about platform-specific behaviour. I also need to verify that all the required ACPI methods are actually present and returning what the driver is expecting. Let's see what's actually going on. |
| 6/2 | 2026/08/20 17:46 | tool | grepper |
0mArgs:{
"Expression": "ideapad_acpi_driver"
}Results: {
"Output": "drivers/platform/x86/lenovo/ideapad-laptop.c=2684=MODULE_DEVICE_TABLE(acpi, ideapad_device_ids);\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2685-\ndrivers/platform/x86/lenovo/ideapad-laptop.c:2686:static struct platform_driver ideapad_acpi_driver = {\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2687-\t.probe = ideapad_acpi_add,\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c=2697=static int __init ideapad_laptop_init(void)\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2712-\ndrivers/platform/x86/lenovo/ideapad-laptop.c:2713:\terr = platform_driver_register(\u0026ideapad_acpi_driver);\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2714-\tif (err)\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c=2728=static void __exit ideapad_laptop_exit(void)\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2729-{\ndrivers/platform/x86/lenovo/ideapad-laptop.c:2730:\tplatform_driver_unregister(\u0026ideapad_acpi_driver);\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2731-\tideapad_wmi_driver_unregister();\n"
} |
| 7/2 | 2026/08/20 17:46 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 16533 output: 21 thoughts: 19 Thoughts: Here's a summary of my thought process: **Diving into `ideapad_acpi_add`** Okay, so the probe function we're interested in is named `ideapad_acpi_add`. Right, let's get right into it. I'll need to dissect its purpose and how it fits within the overall driver structure. Let's see what's happening in there. I'm going to look for any obvious red flags, potential bottlenecks, or areas that seem overly complex or inefficient. I'll be paying close attention to resource allocation, interrupt handling, and any interactions with the ACPI tables. I'll try and determine how well it's designed to be reliable, and maintainable. This probe function is the gateway, so it's a critical place to start. |
| 8/2 | 2026/08/20 17:46 | tool | grepper |
0mArgs:{
"Expression": "ideapad_acpi_add"
}Results: {
"Output": "drivers/platform/x86/lenovo/ideapad-laptop.c=2510=static inline void ideapad_wmi_driver_unregister(void) { }\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2515- */\ndrivers/platform/x86/lenovo/ideapad-laptop.c:2516:static int ideapad_acpi_add(struct platform_device *pdev)\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2517-{\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c=2686=static struct platform_driver ideapad_acpi_driver = {\ndrivers/platform/x86/lenovo/ideapad-laptop.c:2687:\t.probe = ideapad_acpi_add,\ndrivers/platform/x86/lenovo/ideapad-laptop.c-2688-\t.remove = ideapad_acpi_remove,\n"
} |
| 9/2 | 2026/08/20 17:46 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 17003 output: 25 thoughts: 573 Thoughts: **My Analysis of this Patch** Okay, so this patch seems a bit complex at first glance. It's touching `ideapad_acpi_add`, which is a platform driver probe function, which makes me think it's focused on specific hardware. But then I see modifications to the core LED trigger code! That's a red flag – a platform driver shouldn't be messing with core subsystems unless there's a really good reason, and it's done carefully. The files touched are all over the place: `led-class.c`, `led-triggers.c`, and some specific device drivers like `leds-cros_ec.c`, `leds-turris-omnia.c`, and even `ledtrig-netdev.c`. First thing's first, I need to understand if these core changes are even *reachable*. Let's dig into the specific changes in `led-class.c`. I see `brightness_store` now calling `led_trigger_remove_hw_control`, a new `trigger_may_offload` sysfs attribute, and `led_classdev_unregister` setting `LED_UNREGISTERING`. In `led-triggers.c`, I see a new `led_trigger_is_hw_controlled`, `led_trigger_set`, `led_trigger_remove_hw_control`, `trigger_may_offload_show`, and `led_trigger_notify_hw_control_changed`. Okay, so `brightness_store` and `trigger_may_offload_show` are sysfs entries, so those are definitely reachable by *any* LED device. Now I need to think about how these core changes interact with actual hardware or emulated devices. Are there any LED devices emulated in QEMU? Yes, definitely. `mac80211_hwsim` creates LEDs, and the `input` subsystem creates LEDs, like keyboard LEDs. Even if `vkms` doesn't, a standard Linux system definitely has plenty of reachable LEDs. And the change to `ledtrig-netdev.c` is especially concerning, since that's a network device LED trigger, so definitely reachable. Let's look at the `ledtrig-netdev.c` changes more closely. I see `netdev_trig_offloaded`, which just returns `trigger_data->hw_control`, and that's being set in `.offloaded` in `netdev_led_trigger`. Ah, here's the kicker, the core change in `led-triggers.c` adds `led_trigger_notify_hw_control_changed`, which seems specific, and is only called by `ideapad-laptop.c` in this patch. But... wait, `led_trigger_notify_hw_control_changed` is exposed as an `EXPORT_SYMBOL_GPL`! That's bad. That means it's available for other modules to use, even though the only caller *in this patch* is `ideapad-laptop.c`. This needs a second look, and I will check the kernel sources, and perhaps other drivers to see if the symbol has other calls. This is potentially a serious design flaw! I need to investigate further. |
| 10/2 | 2026/08/20 17:46 | tool | grepper |
0mArgs:{
"Expression": "led_trigger_notify_hw_control_changed"
}Results: {
"Output": "Documentation/leds/leds-class.rst=345=flags before registering. To update the current trigger accordingly, call\nDocumentation/leds/leds-class.rst:346:`led_trigger_notify_hw_control_changed` on the LED classdev.\nDocumentation/leds/leds-class.rst-347-\n--\ndrivers/leds/led-triggers.c=496=static void led_trigger_do_hw_control_transition(struct led_classdev *led_cdev, bool activate,\n--\ndrivers/leds/led-triggers.c-523-\ndrivers/leds/led-triggers.c:524:void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev, bool activate)\ndrivers/leds/led-triggers.c-525-{\n--\ndrivers/leds/led-triggers.c-550-}\ndrivers/leds/led-triggers.c:551:EXPORT_SYMBOL_GPL(led_trigger_notify_hw_control_changed);\ndrivers/leds/led-triggers.c-552-#endif /* CONFIG_LEDS_TRIGGERS_HW_CHANGED */\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c=1757=static void ideapad_kbd_bl_notify_hw_control(struct ideapad_private *priv,\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c-1768-\tif (hw_control != last_hw_control)\ndrivers/platform/x86/lenovo/ideapad-laptop.c:1769:\t\tled_trigger_notify_hw_control_changed(\u0026priv-\u003ekbd_bl.led, hw_control);\ndrivers/platform/x86/lenovo/ideapad-laptop.c-1770-}\n--\ninclude/linux/leds.h=606=led_trigger_get_brightness(const struct led_trigger *trigger)\n--\ninclude/linux/leds.h-613-#ifdef CONFIG_LEDS_TRIGGERS_HW_CHANGED\ninclude/linux/leds.h:614:void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev, bool activate);\ninclude/linux/leds.h-615-#else\ninclude/linux/leds.h:616:static inline void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev,\ninclude/linux/leds.h-617-\t\t\t\t\t\t\t bool activate) {}\n"
} |
| 11/2 | 2026/08/20 17:46 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 18933 output: 22 thoughts: 124 Thoughts: **Analyzing LED Trigger Control Flow** Okay, so I'm focusing on how this LED hardware control works. From what I'm seeing, `led_trigger_notify_hw_control_changed` seems to be specific to the `ideapad-laptop.c` driver, which is interesting. However, the more fundamental changes related to the LED functionality are located in `led-class.c` and `led-triggers.c`, and these seem to be exposed through the sysfs interface. That's where it gets more interesting and potentially problematic for the user to be aware of. For instance, the `trigger_may_offload_show` function, which might offer insight into whether the trigger can be managed by the hardware or if we have control, is reachable for *any* LED device registered in the system. The same applies to `led_trigger_remove_hw_control`. Thinking deeper, this is crucial. `led_trigger_remove_hw_control` gets called from `brightness_store` when someone writes a value to the `/sys/class/leds/<led>/brightness` sysfs entry. Which means it is exposed directly. I should check `trigger_may_offload_show` next, to understand the current situation. |
| 12/2 | 2026/08/20 17:46 | tool | grepper |
0mArgs:{
"Expression": "trigger_may_offload_show"
}Results: {
"Output": "drivers/leds/led-triggers.c=377=EXPORT_SYMBOL_GPL(led_trigger_set_default);\ndrivers/leds/led-triggers.c-378-\ndrivers/leds/led-triggers.c:379:ssize_t trigger_may_offload_show(struct device *dev,\ndrivers/leds/led-triggers.c-380-\t\t\t\t struct device_attribute *attr, char *buf)\n--\ndrivers/leds/led-triggers.c-402-}\ndrivers/leds/led-triggers.c:403:EXPORT_SYMBOL_GPL(trigger_may_offload_show);\ndrivers/leds/led-triggers.c-404-\n--\ndrivers/leds/leds.h=27=ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,\n--\ndrivers/leds/leds.h-29-\t\t\tloff_t pos, size_t count);\ndrivers/leds/leds.h:30:ssize_t trigger_may_offload_show(struct device *dev,\ndrivers/leds/leds.h-31-\t\t\t\t struct device_attribute *attr, char *buf);\n"
} |
| 13/2 | 2026/08/20 17:46 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 19657 output: 24 thoughts: 67 Thoughts: **Digging into the `led-class.c` code** Okay, hold on a second. I was looking for a direct call to `trigger_may_offload_show` within the `led-class.c` file, but I'm not seeing it. That seems odd, I was sure it would be used here. Let me retrace my steps. Ah, that's it! `DEVICE_ATTR_RO(trigger_may_offload)`…right, the macro. That's how it's done. The macro expands into `dev_attr_trigger_may_offload`, and *that* structure definition is what then references `trigger_may_offload_show`. Clever use of abstraction there. Okay, got it. Back on track. |
| 14/2 | 2026/08/20 17:47 | tool | grepper |
0mArgs:{
"Expression": "dev_attr_trigger_may_offload"
}Results: {
"Output": "drivers/leds/led-class.c=101=static struct attribute *led_trigger_attrs[] = {\ndrivers/leds/led-class.c:102:\t\u0026dev_attr_trigger_may_offload.attr,\ndrivers/leds/led-class.c-103-\tNULL\n--\ndrivers/leds/led-class.c=106=static umode_t led_trigger_is_visible(struct kobject *kobj,\n--\ndrivers/leds/led-class.c-112-\ndrivers/leds/led-class.c:113:\tif (attr == \u0026dev_attr_trigger_may_offload.attr)\ndrivers/leds/led-class.c-114-\t\treturn led_cdev-\u003ehw_control_trigger ? attr-\u003emode : 0;\n"
} |
| 15/2 | 2026/08/20 17:47 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 20131 output: 19 thoughts: 63 Thoughts: **Investigating the `trigger_may_offload` Visibility** Okay, so I'm digging into this `trigger_may_offload` thing, and it looks like its visibility is directly tied to whether or not the `led_cdev->hw_control_trigger` flag is set. Makes sense. But here's the question that's burning: Are there any actual LED devices with that `hw_control_trigger` flag set that are accessible within a QEMU environment? I need to know if this is even relevant in the configurations I'm working with, or if it's just theoretical. Time to fire up the search tools and see what I can find by hunting for instances of `hw_control_trigger`. Let's see what the system reveals. |
| 16/2 | 2026/08/20 17:47 | tool | grepper |
0mArgs:{
"Expression": "hw_control_trigger"
}Results: {
"Output": "Documentation/leds/leds-class.rst=248=LED driver must define the following value to support hw control:\nDocumentation/leds/leds-class.rst-249-\nDocumentation/leds/leds-class.rst:250: - hw_control_trigger:\nDocumentation/leds/leds-class.rst-251- unique trigger name supported by the LED in hw control\n--\nDocumentation/leds/leds-class.rst=329=declare that the private trigger provides hardware control for the associated\nDocumentation/leds/leds-class.rst:330:LED classdev, set the `hw_control_trigger` string to the trigger's name. Since\nDocumentation/leds/leds-class.rst-331-both the LED classdev and the private trigger are in the same LED driver, it's\n--\nDocumentation/leds/leds-class.rst=349=trigger must have been properly registered (see above) and named after\nDocumentation/leds/leds-class.rst:350:`hw_control_trigger`.\nDocumentation/leds/leds-class.rst-351-\n--\ndrivers/leds/led-class.c=106=static umode_t led_trigger_is_visible(struct kobject *kobj,\n--\ndrivers/leds/led-class.c-113-\tif (attr == \u0026dev_attr_trigger_may_offload.attr)\ndrivers/leds/led-class.c:114:\t\treturn led_cdev-\u003ehw_control_trigger ? attr-\u003emode : 0;\ndrivers/leds/led-class.c-115-\n--\ndrivers/leds/led-triggers.c=39=static bool __led_trigger_is_hw_controlled(struct led_classdev *led_cdev)\n--\ndrivers/leds/led-triggers.c-45-\ndrivers/leds/led-triggers.c:46:\tif (!led_cdev-\u003ehw_control_trigger ||\ndrivers/leds/led-triggers.c:47:\t strcmp(led_cdev-\u003ehw_control_trigger, led_cdev-\u003etrigger-\u003ename))\ndrivers/leds/led-triggers.c-48-\t\treturn false;\n--\ndrivers/leds/led-triggers.c=379=ssize_t trigger_may_offload_show(struct device *dev,\n--\ndrivers/leds/led-triggers.c-392-\toffloaded = __led_trigger_is_hw_controlled(led_cdev);\ndrivers/leds/led-triggers.c:393:\thit = offloaded || (trig \u0026\u0026 !strcmp(led_cdev-\u003ehw_control_trigger, trig-\u003ename));\ndrivers/leds/led-triggers.c-394-\n--\ndrivers/leds/led-triggers.c-397-\t\t\t offloaded ? \"[\" : (hit ? \"\u003c\" : \"\"),\ndrivers/leds/led-triggers.c:398:\t\t\t led_cdev-\u003ehw_control_trigger,\ndrivers/leds/led-triggers.c-399-\t\t\t offloaded ? \"]\" : (hit ? \"\u003e\" : \"\"));\n--\ndrivers/leds/led-triggers.c=524=void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev, bool activate)\n--\ndrivers/leds/led-triggers.c-531-\tif (WARN_ON(!(led_cdev-\u003eflags \u0026 LED_TRIG_HW_CHANGED) ||\ndrivers/leds/led-triggers.c:532:\t\t !led_cdev-\u003ehw_control_trigger || !led_cdev-\u003etrigger_type))\ndrivers/leds/led-triggers.c-533-\t\treturn;\n--\ndrivers/leds/led-triggers.c-537-\t\t\tif (trig-\u003etrigger_type == led_cdev-\u003etrigger_type \u0026\u0026\ndrivers/leds/led-triggers.c:538:\t\t\t !strcmp(trig-\u003ename, led_cdev-\u003ehw_control_trigger)) {\ndrivers/leds/led-triggers.c-539-\t\t\t\tguard(rwsem_write)(\u0026led_cdev-\u003etrigger_lock);\n--\ndrivers/leds/led-triggers.c-548-\t\t\"%s() is called, but the private trigger (%s) is not properly registered\\n\",\ndrivers/leds/led-triggers.c:549:\t\t__func__, led_cdev-\u003ehw_control_trigger);\ndrivers/leds/led-triggers.c-550-}\n--\ndrivers/leds/leds-cros_ec.c=166=static int cros_ec_led_probe_one(struct device *dev, struct cros_ec_device *cros_ec,\n--\ndrivers/leds/leds-cros_ec.c-221-\tled_cdev-\u003edefault_trigger = cros_ec_led_trigger.name;\ndrivers/leds/leds-cros_ec.c:222:\tled_cdev-\u003ehw_control_trigger = cros_ec_led_trigger.name;\ndrivers/leds/leds-cros_ec.c-223-\n--\ndrivers/leds/leds-turris-omnia.c=211=static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,\n--\ndrivers/leds/leds-turris-omnia.c-259-\tcdev-\u003edefault_trigger = omnia_hw_trigger.name;\ndrivers/leds/leds-turris-omnia.c:260:\tcdev-\u003ehw_control_trigger = omnia_hw_trigger.name;\ndrivers/leds/leds-turris-omnia.c-261-\n--\ndrivers/leds/trigger/ledtrig-netdev.c=157=static bool supports_hw_control(struct led_classdev *led_cdev)\n--\ndrivers/leds/trigger/ledtrig-netdev.c-162-\ndrivers/leds/trigger/ledtrig-netdev.c:163:\treturn !strcmp(led_cdev-\u003ehw_control_trigger, led_cdev-\u003etrigger-\u003ename);\ndrivers/leds/trigger/ledtrig-netdev.c-164-}\n--\ndrivers/net/dsa/mv88e6xxx/leds.c=745=int mv88e6xxx_port_setup_leds(struct mv88e6xxx_chip *chip, int port)\n--\ndrivers/net/dsa/mv88e6xxx/leds.c-819-\t\t}\ndrivers/net/dsa/mv88e6xxx/leds.c:820:\t\tl-\u003ehw_control_trigger = \"netdev\";\ndrivers/net/dsa/mv88e6xxx/leds.c-821-\n--\ndrivers/net/dsa/qca/qca8k-leds.c=365=qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int port_num)\n--\ndrivers/net/dsa/qca/qca8k-leds.c-426-\t\tport_led-\u003ecdev.hw_control_get_device = qca8k_cled_hw_control_get_device;\ndrivers/net/dsa/qca/qca8k-leds.c:427:\t\tport_led-\u003ecdev.hw_control_trigger = \"netdev\";\ndrivers/net/dsa/qca/qca8k-leds.c-428-\t\tinit_data.default_label = \":port\";\n--\ndrivers/net/ethernet/intel/igc/igc_leds.c=239=static int igc_setup_ldev(struct igc_led_classdev *ldev,\n--\ndrivers/net/ethernet/intel/igc/igc_leds.c-253-\tled_cdev-\u003ebrightness_set_blocking = igc_led_brightness_set_blocking;\ndrivers/net/ethernet/intel/igc/igc_leds.c:254:\tled_cdev-\u003ehw_control_trigger = \"netdev\";\ndrivers/net/ethernet/intel/igc/igc_leds.c-255-\tled_cdev-\u003ehw_control_is_supported = igc_led_hw_control_is_supported;\n--\ndrivers/net/ethernet/realtek/r8169_leds.c=129=static void rtl8168_setup_ldev(struct r8169_led_classdev *ldev,\n--\ndrivers/net/ethernet/realtek/r8169_leds.c-140-\tled_cdev-\u003ename = led_name;\ndrivers/net/ethernet/realtek/r8169_leds.c:141:\tled_cdev-\u003ehw_control_trigger = \"netdev\";\ndrivers/net/ethernet/realtek/r8169_leds.c-142-\tled_cdev-\u003eflags |= LED_RETAIN_AT_SHUTDOWN;\n--\ndrivers/net/ethernet/realtek/r8169_leds.c=228=static void rtl8125_setup_led_ldev(struct r8169_led_classdev *ldev,\n--\ndrivers/net/ethernet/realtek/r8169_leds.c-239-\tled_cdev-\u003ename = led_name;\ndrivers/net/ethernet/realtek/r8169_leds.c:240:\tled_cdev-\u003ehw_control_trigger = \"netdev\";\ndrivers/net/ethernet/realtek/r8169_leds.c-241-\tled_cdev-\u003eflags |= LED_RETAIN_AT_SHUTDOWN;\n--\ndrivers/net/phy/phy_device.c=3301=static int of_phy_led(struct phy_device *phydev,\n--\ndrivers/net/phy/phy_device.c-3358-\t\tcdev-\u003ehw_control_get = phy_led_hw_control_get;\ndrivers/net/phy/phy_device.c:3359:\t\tcdev-\u003ehw_control_trigger = \"netdev\";\ndrivers/net/phy/phy_device.c-3360-\t}\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c=1798=static int ideapad_kbd_bl_init(struct ideapad_private *priv)\n--\ndrivers/platform/x86/lenovo/ideapad-laptop.c-1835-\t\tpriv-\u003ekbd_bl.led.trigger_type = \u0026ideapad_kbd_bl_auto_trigger_type;\ndrivers/platform/x86/lenovo/ideapad-laptop.c:1836:\t\tpriv-\u003ekbd_bl.led.hw_control_trigger = ideapad_kbd_bl_auto_trigger.name;\ndrivers/platform/x86/lenovo/ideapad-laptop.c-1837-\n--\ninclude/linux/leds.h=91=struct led_classdev {\n--\ninclude/linux/leds.h-194-\t/* Unique trigger name supported by LED set in hw control mode */\ninclude/linux/leds.h:195:\tconst char\t\t*hw_control_trigger;\ninclude/linux/leds.h-196-\t/*\n"
} |
| 17/2 | 2026/08/20 17:47 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 23235 output: 23 thoughts: 414 Thoughts: **My LED Trigger Hunting Expedition** Okay, so I'm seeing that `hw_control_trigger` is being set by a bunch of network device triggers – `igc`, `r8169`, generic `phy_device.c`, `qca8k`, and `mv88e6xxx`. Hmm, `phy_device.c` is the *generic* PHY layer, which is interesting. My immediate thought is, are there any of these PHY drivers that support LEDs and that I can actually *reach* when running QEMU? Let's see… I know that `macb`, `e1000e`, `igb`, and `r8169` all might be candidates. Wait, but `r8169` is a PCI device and that's something QEMU emulates! I can use it with either `-device rtl8139`, `-device e1000` or `-device igb`. Hold on, though; `r8169` is for the Realtek 8169, whereas QEMU emulates `rtl8139` which is different. But then there's `igc` which is for Intel I225, not supported by QEMU. QEMU *does* support `e1000`, `e1000e`, and `igb`, though. Ah, wait a minute, `phy_device.c` is used by *many* network drivers! Alright, let's broaden the search a bit. What about these other LED driver files I'm seeing? `leds-cros_ec.c`… ChromeOS EC LEDs. `leds-turris-omnia.c`… Turris Omnia LEDs. Nope, `ideapad-laptop.c` would be great but that's not emulated. But then, I had a flash of insight. The core LED changes are in `led-class.c` and `led-triggers.c`, and those are *reachable* if *any* LED device with the `hw_control_trigger` is present, OR if I just write to `/sys/class/leds/<led>/brightness`. This write to `/sys/class/leds/<led>/brightness` call calls `led_trigger_remove_hw_control`! This is where I should focus next. Let's dig into `led_trigger_remove_hw_control`. |
| 18/2 | 2026/08/20 17:47 | tool | grepper |
0mArgs:{
"Expression": "led_trigger_remove_hw_control"
}Results: {
"Output": "drivers/leds/led-class.c=47=static ssize_t brightness_store(struct device *dev,\n--\ndrivers/leds/led-class.c-67-\telse\ndrivers/leds/led-class.c:68:\t\tled_trigger_remove_hw_control(led_cdev);\ndrivers/leds/led-class.c-69-\n--\ndrivers/leds/led-triggers.c=323=EXPORT_SYMBOL_GPL(led_trigger_remove);\ndrivers/leds/led-triggers.c-324-\ndrivers/leds/led-triggers.c:325:void led_trigger_remove_hw_control(struct led_classdev *led_cdev)\ndrivers/leds/led-triggers.c-326-{\n--\ndrivers/leds/led-triggers.c-331-}\ndrivers/leds/led-triggers.c:332:EXPORT_SYMBOL_GPL(led_trigger_remove_hw_control);\ndrivers/leds/led-triggers.c-333-\n--\ninclude/linux/leds.h=537=void led_trigger_remove(struct led_classdev *led_cdev);\ninclude/linux/leds.h:538:void led_trigger_remove_hw_control(struct led_classdev *led_cdev);\ninclude/linux/leds.h-539-\n--\ninclude/linux/leds.h=591=static inline void led_trigger_remove(struct led_classdev *led_cdev) {}\ninclude/linux/leds.h:592:static inline void led_trigger_remove_hw_control(struct led_classdev *led_cdev) {}\ninclude/linux/leds.h-593-\n"
} |
| 19/2 | 2026/08/20 17:47 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 24653 output: 22 thoughts: 1175 Thoughts: **Reaching the Relevant LED Code** Okay, so here's the breakdown of my thinking: the changes related to hardware-controlled LED triggers are definitely *reachable* in the kernel, and have functional impact. Specifically, `led_trigger_remove_hw_control` gets called from `brightness_store` *every* time brightness is set to non-zero, which is pretty significant. `brightness_store`, in `led-class.c`, seems like a good starting point to trace the calls. Looking closer, `led_trigger_remove_hw_control` calls `__led_trigger_is_hw_controlled`, so that is also important to consider. And of course, `led_trigger_set` was modified, and that's reachable too when changing triggers via sysfs. This means there's a lot of potential attack surface in core LED functionality. I need to confirm if specific triggers are reachable, since that can add additional code paths. `ideapad-laptop.c` is not reachable in standard QEMU, so I can ignore it for now. But, `ledtrig-netdev.c` *is* reachable if we use the `netdev` trigger! We can set the trigger of any LED to `netdev` via sysfs, which opens up this entire driver. This seems highly relevant. **Configuration Considerations** Next, I need to make sure the relevant kernel config options are enabled. `LEDS_TRIGGERS_HW_CHANGED` is key, and it seems to default to the value of `LEDS_BRIGHTNESS_HW_CHANGED` based on the Kconfig file. I'll need to check if these are enabled by default in the builds I'm working with and make sure I add this to EnableConfigs if necessary. Also, `LEDS_CLASS`, `LEDS_TRIGGERS`, and `LEDS_TRIGGER_NETDEV` are likely useful to add as well. **Targeting Fuzzing** Now, let's identify the *specific* functions I should focus fuzzing on. Based on the analysis, these look like the most critical ones: * `led_trigger_is_hw_controlled` * `led_trigger_remove_hw_control` * `trigger_may_offload_show` * `netdev_trig_offloaded` Although `led_trigger_notify_hw_control_changed` is present, it's not reachable in QEMU, so it's probably not the best target for fuzzing. Also, `led_trigger_set` is reachable, and wraps `__led_trigger_set`, so I will target `__led_trigger_set` for fuzzing. I'll also quickly verify the signature of `netdev_trig_offloaded` to make sure there are no surprises there. |
| 20/2 | 2026/08/20 17:47 | tool | grepper |
0mArgs:{
"Expression": "netdev_trig_offloaded"
}Results: {
"Output": "drivers/leds/trigger/ledtrig-netdev.c=744=static void netdev_trig_deactivate(struct led_classdev *led_cdev)\n--\ndrivers/leds/trigger/ledtrig-netdev.c-756-\ndrivers/leds/trigger/ledtrig-netdev.c:757:static bool netdev_trig_offloaded(struct led_classdev *led_cdev)\ndrivers/leds/trigger/ledtrig-netdev.c-758-{\n--\ndrivers/leds/trigger/ledtrig-netdev.c=764=static struct led_trigger netdev_led_trigger = {\n--\ndrivers/leds/trigger/ledtrig-netdev.c-767-\t.deactivate = netdev_trig_deactivate,\ndrivers/leds/trigger/ledtrig-netdev.c:768:\t.offloaded = netdev_trig_offloaded,\ndrivers/leds/trigger/ledtrig-netdev.c-769-\t.groups = netdev_trig_groups,\n"
} |
| 21/2 | 2026/08/20 17:47 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 26756 output: 25 thoughts: 560 Thoughts: **Analyzing LED Trigger Function Symbol Export and Reachability** Okay, so I'm thinking about how these LED trigger functions are being used and how we need to handle their symbol visibility, especially when considering offloading and reachability in the context of QEMU. It's clear that `netdev_trig_offloaded` is interesting; even though it's static, the fact that it's passed as a function pointer to `.offloaded` means it won't be fully inlined. It'll exist as a standalone function because its address is taken. Now, the instructions are clear: we should prioritize non-static, non-inlined entry points over internal static helpers. Keeping that in mind, let's look at what's available and *reachable*. I'm zeroing in on `led_trigger_is_hw_controlled`, `led_trigger_remove_hw_control`, and `trigger_may_offload_show` as potential candidates. I confirmed that `led_trigger_set` is, in fact, exported. Next, I checked `led_trigger_notify_hw_control_changed`. It *is* exported, but it's only called from `ideapad-laptop.c`. Since that's not something reachable in a QEMU environment, I'm crossing it off the list for `FocusSymbols`. It's out. Moving on, I confirmed that `trigger_may_offload_show` is exported, with its signature: ```c ssize_t trigger_may_offload_show(struct device *dev, struct device_attribute *attr, char *buf) ``` Then, I validated that `led_trigger_remove_hw_control` is exported: ```c void led_trigger_remove_hw_control(struct led_classdev *led_cdev) ``` And finally, `led_trigger_is_hw_controlled` is also exported: ```c bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev) ``` Are there any other new functions, though? Checking other files, I found: * In `led-class.c`: `led_trigger_is_visible` (static) -- Ignore. * In `leds-cros_ec.c`: `cros_ec_led_trigger_offloaded` (static, usually not reachable in QEMU because it relies on the ChromeOS EC) -- Not of interest. * In `leds-turris-omnia.c`: `omnia_hwtrig_offloaded` (static, requires the Turris Omnia MCU) -- Not applicable here. Therefore, the core reachable functions are definitively: * `led_trigger_is_hw_controlled` * `led_trigger_remove_hw_control` * `trigger_may_offload_show` Finally, before I sign off on this, I'll quickly double-check if the `LEDS_TRIGGERS_HW_CHANGED` symbol needs any additional dependencies that might influence this. |
| 22/2 | 2026/08/20 17:47 | tool | grepper |
0mArgs:{
"Expression": "config LEDS_TRIGGERS_HW_CHANGED"
}Results: {
"Output": "drivers/leds/trigger/Kconfig=10=if LEDS_TRIGGERS\ndrivers/leds/trigger/Kconfig-11-\ndrivers/leds/trigger/Kconfig:12:config LEDS_TRIGGERS_HW_CHANGED\ndrivers/leds/trigger/Kconfig-13-\tbool \"LED hardware-initiated trigger transition support\"\n"
} |
| 23/2 | 2026/08/20 17:47 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 28118 output: 25 thoughts: 121 Thoughts: **My Configuration Strategy** Okay, so the `LEDS_TRIGGERS` setting is the key here, it dictates a lot. My initial assessment is that `EnableConfigs` needs to encompass: `LEDS_CLASS`, `LEDS_TRIGGERS`, naturally `LEDS_TRIGGERS_HW_CHANGED` and then `LEDS_TRIGGER_NETDEV`, which I need to test thoroughly for those netdev offload changes. Wait a minute, I need to make sure I consider that `LEDS_BRIGHTNESS_HW_CHANGED` is the default for `LEDS_TRIGGERS_HW_CHANGED`. Given this default, I need to check `LEDS_BRIGHTNESS_HW_CHANGED`. |
| 24/2 | 2026/08/20 17:47 | tool | grepper |
0mArgs:{
"Expression": "config LEDS_BRIGHTNESS_HW_CHANGED"
}Results: {
"Output": "drivers/leds/Kconfig=39=config LEDS_CLASS_MULTICOLOR\n--\ndrivers/leds/Kconfig-48-\ndrivers/leds/Kconfig:49:config LEDS_BRIGHTNESS_HW_CHANGED\ndrivers/leds/Kconfig-50-\tbool \"LED Class brightness_hw_changed attribute support\"\n"
} |
| 25/2 | 2026/08/20 17:47 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 28515 output: 196 thoughts: 454 Thoughts: **My Analysis of LED Trigger Hardware Offloading** Okay, so we need to ensure that `LEDS_BRIGHTNESS_HW_CHANGED` is enabled; just to be safe, given the implications of these changes. Let's break this down systematically. The core of this patch introduces hardware-initiated LED trigger transitions and the new `trigger_may_offload` sysfs attribute to examine the supported triggers and their states. It's touching core LED and trigger subsystems, which are, critically, accessible via sysfs for *any* LED device. The modifications to the `netdev` LED trigger to report its offloaded state are also relevant. These core-level changes and the `netdev` trigger modifications are reachable in virtualized environments, and therefore have a direct functional impact. This is where we need to focus. Key symbols to hone in on for the fuzzing analysis are: `led_trigger_is_hw_controlled`, `led_trigger_remove_hw_control`, and `trigger_may_offload_show`. We're dealing with the following configs: `LEDS_CLASS`, `LEDS_TRIGGERS`, `LEDS_TRIGGERS_HW_CHANGED`, and `LEDS_TRIGGER_NETDEV`. We can expect interactions with these. Now, let's consider other exported functions. We see that `led_trigger_set` has been modified, but it's an existing function. The instructions suggest focusing on non-hot-path functions. Changing triggers, which is when `led_trigger_set` is called, isn't a hot path. Still, since the new functions are more specific, let's focus on those. And `__led_trigger_set` is static, so we don't need to consider it. `trigger_may_offload_show` is reachable; we can read `/sys/class/leds/<led>/trigger_may_offload`. Check. `led_trigger_remove_hw_control` is also reachable; writing to `/sys/class/leds/<led>/brightness`. Check. Finally, is `led_trigger_is_hw_controlled` reachable? Yes, it's called by both `led_trigger_remove_hw_control` and `trigger_may_offload_show`. And it's also exported. Double check. Okay, I'm confident in this analysis. I will use set-results to provide the focused analysis. |
| 26/2 | 2026/08/20 17:48 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"LEDS_CLASS",
"LEDS_TRIGGERS",
"LEDS_TRIGGERS_HW_CHANGED",
"LEDS_TRIGGER_NETDEV"
],
"FocusSymbols": [
"led_trigger_is_hw_controlled",
"led_trigger_remove_hw_control",
"trigger_may_offload_show"
],
"Reasoning": "The patch introduces support for hardware-initiated LED trigger transitions and a new sysfs attribute `trigger_may_offload` to query supported triggers and their states. It modifies the core LED class and trigger subsystems, which are reachable via sysfs for any LED device. It also updates the `netdev` LED trigger to report its offloaded state. These core changes and the `netdev` trigger modifications are reachable in virtualized environments and have functional impact.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"LEDS_CLASS",
"LEDS_TRIGGERS",
"LEDS_TRIGGERS_HW_CHANGED",
"LEDS_TRIGGER_NETDEV"
],
"FocusSymbols": [
"led_trigger_is_hw_controlled",
"led_trigger_remove_hw_control",
"trigger_may_offload_show"
],
"Reasoning": "The patch introduces support for hardware-initiated LED trigger transitions and a new sysfs attribute `trigger_may_offload` to query supported triggers and their states. It modifies the core LED class and trigger subsystems, which are reachable via sysfs for any LED device. It also updates the `netdev` LED trigger to report its offloaded state. These core changes and the `netdev` trigger modifications are reachable in virtualized environments and have functional impact.",
"WorthFuzzing": true
} |
| 27/1 | 2026/08/20 17:48 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 28/2 | 2026/08/20 17:48 | agent | kmsan-evaluator |
0mModel:best-expensive Args: null Results: {
"KMSANReasoning": "The patch series modifies the LED subsystem to support hardware-initiated trigger transitions, adding a new sysfs attribute `trigger_may_offload` and modifying several LED drivers to support this feature. The changes involve adding new callbacks (`offloaded`), modifying existing ones, and adding new logic to handle hardware control transitions.\n\nThere are no new structures sent to user space, no complex data structures allocated where uninitialized fields could be read later, and no conditional logic that depends on potentially uninitialized variables. The sysfs attribute uses `sysfs_emit`, which is safe. The changes primarily involve control flow and state management within the LED subsystem and drivers.\n\nAny potential bugs introduced by these changes, such as out-of-bounds accesses, NULL pointer dereferences, or locking issues, would be caught by standard KASAN, LOCKDEP, or other standard bug detectors. There is no risk of uninitialized memory usage or info-leaks that would require a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: For your convenience, here is the diff of the changes:
commit 2533c2922f89dde807e90d3942b7376dcf715d33
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Aug 20 17:46:18 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led
index d4c918cc11a12..2a13c77aee229 100644
--- a/Documentation/ABI/testing/sysfs-class-led
+++ b/Documentation/ABI/testing/sysfs-class-led
@@ -78,6 +78,31 @@ Description:
(which would often be configured in the device tree for the
hardware).
+What: /sys/class/leds/<led>/trigger_may_offload
+Date: August 2026
+KernelVersion: 7.3
+Contact: linux-leds@vger.kernel.org
+Description:
+ Names and states of triggers that may be offloaded to hardware.
+ Such triggers are also called "hardware control trigger" in some
+ context.
+
+ Only exists when the LED supports trigger offload.
+
+ Reading this file returns a list of triggers that are capable to
+ be offloaded. The optional brackets around the trigger name
+ indicate the state of the current trigger:
+
+ - `foo_trigger`: the trigger is not selected.
+ - `<foo_trigger>`: the trigger is selected, but falls back to
+ software blink for some reason (e.g., incompatible trigger
+ parameters)
+ - `[foo_trigger]`: the trigger is selected and offloaded to
+ hardware.
+
+ The "netdev" trigger also provides a custom attribute to
+ indicate its state, see `/sys/class/leds/<led>/offloaded`.
+
What: /sys/class/leds/<led>/inverted
Date: January 2011
KernelVersion: 2.6.38
diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev
index ed46b37ab8a28..a5146ea1e3e61 100644
--- a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev
+++ b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev
@@ -75,6 +75,9 @@ Description:
If 1, the LED blinking in requested mode is offloaded to
hardware.
+ LED trigger core also provides a generic attribute for this
+ purpose, see `/sys/class/leds/<led>/trigger_may_offload`.
+
What: /sys/class/leds/<led>/link_10
Date: Jun 2023
KernelVersion: 6.5
diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst
index 3913966cfdac0..adbc57b9f49c3 100644
--- a/Documentation/leds/leds-class.rst
+++ b/Documentation/leds/leds-class.rst
@@ -242,6 +242,9 @@ ops and needs to declare specific support for the supported triggers.
With hw control we refer to the LED driven by hardware.
+A sysfs attribute `trigger_may_offload` is provided for userspace to
+query supported triggers and their states.
+
LED driver must define the following value to support hw control:
- hw_control_trigger:
@@ -298,6 +301,15 @@ LED driver must implement the following API to support hw control:
Returns a pointer to a struct device or NULL if nothing
is currently attached.
+LED trigger should implement the following API to indicate hw control:
+ - offloaded:
+ return a boolean indicating if the trigger is currently
+ offloaded to hardware.
+
+ If a trigger doesn't implement this callback, the default
+ value will be true for private triggers and false for generic
+ ones.
+
LED driver can activate additional modes by default to workaround the
impossibility of supporting each different mode on the supported trigger.
Examples are hardcoding the blink speed to a set interval, enable special
@@ -311,9 +323,69 @@ the end use hw_control_set to activate hw control.
A trigger can use hw_control_get to check if a LED is already in hw control
and init their flags.
+Alternatively, a private trigger can be implemented along with the LED driver if
+the LED's hardware control doesn't fit any generic trigger. To associate the
+private trigger with the LED classdev, their `trigger_type` must be the same. To
+declare that the private trigger provides hardware control for the associated
+LED classdev, set the `hw_control_trigger` string to the trigger's name. Since
+both the LED classdev and the private trigger are in the same LED driver, it's
+not necessary for them to coordinate via `hw_control_*` callbacks.
+
When the LED is in hw control, no software blink is possible and doing so
will effectively disable hw control.
+Hardware-initiated trigger transition
+=====================================
+
+Some hardware can autonomously activate/deactivate hardware control. After that,
+the LED hardware notifies the LED driver.
+
+If the driver can detect such transitions and thus wants to notify the LED core
+to update the current trigger then the `LED_TRIG_HW_CHANGED` flag must be set in
+flags before registering. To update the current trigger accordingly, call
+`led_trigger_notify_hw_control_changed` on the LED classdev.
+
+This capability is restricted to the LED device's private trigger. The private
+trigger must have been properly registered (see above) and named after
+`hw_control_trigger`.
+
+Only two transitions are defined:
+
+- "none" => private trigger:
+ This happens when the hardware autonomously activates hardware control
+ and when "none" (i.e., no trigger) is currently active. If the private
+ trigger is already active when the method is called, this is essentially
+ a no-op.
+
+ The activation sequence for the private trigger will be executed as
+ normal.
+
+ The LED driver and its private trigger must be able to handle the
+ activation sequence even if the hardware is currently in hardware
+ control.
+
+ If error occurs in the activation sequence, the LED Trigger core reverts
+ the effective trigger to "none".
+
+- private trigger => "none"
+ This happens when the hardware autonomously deactivates hardware control
+ and when the private trigger is currently active. If "none" (i.e., no
+ trigger) is active when the method is called, this is essentially a
+ no-op.
+
+ The deactivation sequence for the private trigger will be executed as
+ normal, except that the current LED brightness is retained. The reason
+ for keeping the brightness unchanged is that some hardware may choose a
+ specific brightness instead of simply turning off the LED after
+ autonomously deactivating hardware control.
+
+ The LED driver and its private trigger must be able to handle the
+ deactivation sequence even if the hardware is not currently in hardware
+ control.
+
+If the current trigger is neither the private trigger nor "none", no transition
+will be made.
+
Known Issues
============
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index a51b0ed538864..771a6e6c659be 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -27,16 +27,6 @@ static LIST_HEAD(leds_lookup_list);
static struct workqueue_struct *leds_wq;
-static bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)
-{
-#ifdef CONFIG_LEDS_TRIGGERS
- guard(rwsem_read)(&led_cdev->trigger_lock);
- return led_cdev->trigger && led_cdev->trigger->trigger_type;
-#else
- return false;
-#endif
-}
-
static ssize_t brightness_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -74,6 +64,9 @@ static ssize_t brightness_store(struct device *dev,
if (state == LED_OFF)
led_trigger_remove(led_cdev);
+ else
+ led_trigger_remove_hw_control(led_cdev);
+
led_set_brightness(led_cdev, state);
ret = size;
@@ -103,8 +96,30 @@ static const struct bin_attribute *const led_trigger_bin_attrs[] = {
&bin_attr_trigger,
NULL,
};
+
+static DEVICE_ATTR_RO(trigger_may_offload);
+static struct attribute *led_trigger_attrs[] = {
+ &dev_attr_trigger_may_offload.attr,
+ NULL
+};
+
+static umode_t led_trigger_is_visible(struct kobject *kobj,
+ struct attribute *attr,
+ int idx)
+{
+ struct device *dev = kobj_to_dev(kobj);
+ struct led_classdev *led_cdev = dev_get_drvdata(dev);
+
+ if (attr == &dev_attr_trigger_may_offload.attr)
+ return led_cdev->hw_control_trigger ? attr->mode : 0;
+
+ return attr->mode;
+}
+
static const struct attribute_group led_trigger_group = {
.bin_attrs = led_trigger_bin_attrs,
+ .attrs = led_trigger_attrs,
+ .is_visible = led_trigger_is_visible,
};
#endif
@@ -618,12 +633,13 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
#ifdef CONFIG_LEDS_TRIGGERS
down_write(&led_cdev->trigger_lock);
+ led_cdev->flags |= LED_UNREGISTERING;
if (led_cdev->trigger)
led_trigger_set(led_cdev, NULL);
up_write(&led_cdev->trigger_lock);
-#endif
-
+#else
led_cdev->flags |= LED_UNREGISTERING;
+#endif
/* Stop blinking */
led_stop_software_blink(led_cdev);
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index b1223218bda11..32c9d19374c4e 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -7,9 +7,12 @@
* Author: Richard Purdie <rpurdie@openedhand.com>
*/
+#include <linux/bug.h>
+#include <linux/cleanup.h>
#include <linux/export.h>
#include <linux/kernel.h>
#include <linux/list.h>
+#include <linux/lockdep.h>
#include <linux/spinlock.h>
#include <linux/device.h>
#include <linux/timer.h>
@@ -33,6 +36,34 @@ trigger_relevant(struct led_classdev *led_cdev, struct led_trigger *trig)
return !trig->trigger_type || trig->trigger_type == led_cdev->trigger_type;
}
+static bool __led_trigger_is_hw_controlled(struct led_classdev *led_cdev)
+{
+ lockdep_assert_held(&led_cdev->trigger_lock);
+
+ if (!led_cdev->trigger)
+ return false;
+
+ if (!led_cdev->hw_control_trigger ||
+ strcmp(led_cdev->hw_control_trigger, led_cdev->trigger->name))
+ return false;
+
+ if (led_cdev->trigger->offloaded)
+ return led_cdev->trigger->offloaded(led_cdev);
+
+ dev_warn_once(led_cdev->dev, "hw control trigger %s doesn't implement offloaded()\n",
+ led_cdev->trigger->name);
+
+ /* Otherwise assume private triggers as always offloaded. */
+ return led_cdev->trigger->trigger_type;
+}
+
+bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)
+{
+ guard(rwsem_read)(&led_cdev->trigger_lock);
+ return __led_trigger_is_hw_controlled(led_cdev);
+}
+EXPORT_SYMBOL_GPL(led_trigger_is_hw_controlled);
+
ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
const struct bin_attribute *bin_attr, char *buf,
loff_t pos, size_t count)
@@ -163,13 +194,17 @@ ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
EXPORT_SYMBOL_GPL(led_trigger_read);
/* Caller must ensure led_cdev->trigger_lock held */
-int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
+static int __led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig,
+ bool hw_triggered)
{
char *event = NULL;
char *envp[2];
const char *name;
int ret;
+ if ((led_cdev->flags & LED_UNREGISTERING) && trig)
+ return -ENODEV;
+
if (!led_cdev->trigger && !trig)
return 0;
@@ -194,7 +229,21 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
led_cdev->trigger_data = NULL;
led_cdev->activated = false;
led_cdev->flags &= ~LED_INIT_DEFAULT_TRIGGER;
- led_set_brightness(led_cdev, LED_OFF);
+
+ /*
+ * Hardware may have selected a new brightness level during its
+ * hardware control transition, so only reset brightness if we
+ * are switching to another trigger or if the switching is not
+ * hardware triggered.
+ *
+ * Note that this does not apply to the error path, as running
+ * into the error path implies a none => private trigger
+ * transition. This hints that the LED driver and its private
+ * trigger must have some fundamental bugs, so don't bother
+ * leaving the LED in an undefined state.
+ */
+ if (trig || !hw_triggered)
+ led_set_brightness(led_cdev, LED_OFF);
}
if (trig) {
spin_lock(&trig->leddev_list_lock);
@@ -258,6 +307,11 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
return ret;
}
+
+int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
+{
+ return __led_trigger_set(led_cdev, trig, false);
+}
EXPORT_SYMBOL_GPL(led_trigger_set);
void led_trigger_remove(struct led_classdev *led_cdev)
@@ -268,6 +322,15 @@ void led_trigger_remove(struct led_classdev *led_cdev)
}
EXPORT_SYMBOL_GPL(led_trigger_remove);
+void led_trigger_remove_hw_control(struct led_classdev *led_cdev)
+{
+ guard(rwsem_write)(&led_cdev->trigger_lock);
+
+ if (__led_trigger_is_hw_controlled(led_cdev))
+ led_trigger_set(led_cdev, NULL);
+}
+EXPORT_SYMBOL_GPL(led_trigger_remove_hw_control);
+
static bool led_match_default_trigger(struct led_classdev *led_cdev,
struct led_trigger *trig)
{
@@ -313,6 +376,32 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
}
EXPORT_SYMBOL_GPL(led_trigger_set_default);
+ssize_t trigger_may_offload_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct led_classdev *led_cdev = dev_get_drvdata(dev);
+ struct led_trigger *trig;
+ bool hit, offloaded;
+ int len;
+
+ guard(mutex)(&led_cdev->led_access);
+ guard(rwsem_read)(&led_cdev->trigger_lock);
+
+ trig = led_cdev->trigger;
+
+ offloaded = __led_trigger_is_hw_controlled(led_cdev);
+ hit = offloaded || (trig && !strcmp(led_cdev->hw_control_trigger, trig->name));
+
+ /* [offloaded] <active_but_not_offloaded> inactive */
+ len = sysfs_emit(buf, "%s%s%s\n",
+ offloaded ? "[" : (hit ? "<" : ""),
+ led_cdev->hw_control_trigger,
+ offloaded ? "]" : (hit ? ">" : ""));
+
+ return len;
+}
+EXPORT_SYMBOL_GPL(trigger_may_offload_show);
+
/* LED Trigger Interface */
int led_trigger_register(struct led_trigger *trig)
@@ -403,6 +492,65 @@ int devm_led_trigger_register(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_led_trigger_register);
+#ifdef CONFIG_LEDS_TRIGGERS_HW_CHANGED
+static void led_trigger_do_hw_control_transition(struct led_classdev *led_cdev, bool activate,
+ struct led_trigger *hc_trig)
+{
+ int err = 0;
+
+ if (!led_cdev->trigger) {
+ /* "none" => private trigger. */
+ if (activate)
+ err = __led_trigger_set(led_cdev, hc_trig, true);
+ } else if (led_cdev->trigger == hc_trig) {
+ /* private trigger => "none". */
+ if (!activate)
+ err = __led_trigger_set(led_cdev, NULL, true);
+ } else {
+ /* Other trigger is active. */
+ dev_dbg(led_cdev->dev,
+ "Ignoring hw control transition (%s %s) while %s is active",
+ activate ? "activate" : "deactivate", hc_trig->name,
+ led_cdev->trigger->name);
+
+ return;
+ }
+
+ if (err)
+ dev_warn(led_cdev->dev, "Failed to %s %s in hw control transition: %d",
+ activate ? "activate" : "deactivate", hc_trig->name, err);
+}
+
+void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev, bool activate)
+{
+ struct led_trigger *trig;
+
+ might_sleep();
+
+ /* Restricted to private triggers. */
+ if (WARN_ON(!(led_cdev->flags & LED_TRIG_HW_CHANGED) ||
+ !led_cdev->hw_control_trigger || !led_cdev->trigger_type))
+ return;
+
+ scoped_guard(rwsem_read, &triggers_list_lock) {
+ list_for_each_entry(trig, &trigger_list, next_trig) {
+ if (trig->trigger_type == led_cdev->trigger_type &&
+ !strcmp(trig->name, led_cdev->hw_control_trigger)) {
+ guard(rwsem_write)(&led_cdev->trigger_lock);
+
+ led_trigger_do_hw_control_transition(led_cdev, activate, trig);
+ return;
+ }
+ }
+ }
+
+ dev_err(led_cdev->dev,
+ "%s() is called, but the private trigger (%s) is not properly registered\n",
+ __func__, led_cdev->hw_control_trigger);
+}
+EXPORT_SYMBOL_GPL(led_trigger_notify_hw_control_changed);
+#endif /* CONFIG_LEDS_TRIGGERS_HW_CHANGED */
+
/* Simple LED Trigger Interface */
void led_trigger_event(struct led_trigger *trig,
diff --git a/drivers/leds/leds-cros_ec.c b/drivers/leds/leds-cros_ec.c
index 1844d0cd5f528..6db83d0152775 100644
--- a/drivers/leds/leds-cros_ec.c
+++ b/drivers/leds/leds-cros_ec.c
@@ -85,12 +85,18 @@ static int cros_ec_led_trigger_activate(struct led_classdev *led_cdev)
return cros_ec_led_send_cmd(priv->cros_ec, &arg);
}
+static bool cros_ec_led_trigger_offloaded(struct led_classdev *led_cdev)
+{
+ return true;
+}
+
static struct led_hw_trigger_type cros_ec_led_trigger_type;
static struct led_trigger cros_ec_led_trigger = {
.name = "chromeos-auto",
.trigger_type = &cros_ec_led_trigger_type,
.activate = cros_ec_led_trigger_activate,
+ .offloaded = cros_ec_led_trigger_offloaded,
};
static int cros_ec_led_brightness_set_blocking(struct led_classdev *led_cdev,
diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c
index ed6a47bbb44f9..32d40d176d3f1 100644
--- a/drivers/leds/leds-turris-omnia.c
+++ b/drivers/leds/leds-turris-omnia.c
@@ -195,10 +195,16 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev)
err);
}
+static bool omnia_hwtrig_offloaded(struct led_classdev *cdev)
+{
+ return true;
+}
+
static struct led_trigger omnia_hw_trigger = {
.name = "omnia-mcu",
.activate = omnia_hwtrig_activate,
.deactivate = omnia_hwtrig_deactivate,
+ .offloaded = omnia_hwtrig_offloaded,
.trigger_type = &omnia_hw_trigger_type,
};
@@ -251,6 +257,7 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,
* by LED class from the linux,default-trigger property.
*/
cdev->default_trigger = omnia_hw_trigger.name;
+ cdev->hw_control_trigger = omnia_hw_trigger.name;
/* Put the LED into software mode */
ret = omnia_cmd_write_u8(client, OMNIA_CMD_LED_MODE, OMNIA_CMD_LED_MODE_LED(led->reg) |
diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
index bee46651e068f..b08a289397e46 100644
--- a/drivers/leds/leds.h
+++ b/drivers/leds/leds.h
@@ -27,6 +27,8 @@ ssize_t led_trigger_read(struct file *filp, struct kobject *kobj,
ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,
const struct bin_attribute *bin_attr, char *buf,
loff_t pos, size_t count);
+ssize_t trigger_may_offload_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
extern struct rw_semaphore leds_list_lock;
extern struct list_head leds_list;
diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
index c11282a74b5ac..a11d04ce4ab2c 100644
--- a/drivers/leds/trigger/Kconfig
+++ b/drivers/leds/trigger/Kconfig
@@ -9,6 +9,16 @@ menuconfig LEDS_TRIGGERS
if LEDS_TRIGGERS
+config LEDS_TRIGGERS_HW_CHANGED
+ bool "LED hardware-initiated trigger transition support"
+ default LEDS_BRIGHTNESS_HW_CHANGED
+ help
+ This option enables support for hardware initiated hardware control
+ transitions, where the LED hardware autonomously switches between
+ "none" (i.e., no trigger) and its private trigger.
+
+ See Documentation/leds/leds-class.rst for details.
+
config LEDS_TRIGGER_TIMER
tristate "LED Timer Trigger"
help
diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 64c078e997f28..a26109ca4b1c9 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -754,10 +754,18 @@ static void netdev_trig_deactivate(struct led_classdev *led_cdev)
kfree(trigger_data);
}
+static bool netdev_trig_offloaded(struct led_classdev *led_cdev)
+{
+ struct led_netdev_data *trigger_data = led_get_trigger_data(led_cdev);
+
+ return trigger_data->hw_control;
+}
+
static struct led_trigger netdev_led_trigger = {
.name = "netdev",
.activate = netdev_trig_activate,
.deactivate = netdev_trig_deactivate,
+ .offloaded = netdev_trig_offloaded,
.groups = netdev_trig_groups,
};
diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
index 4443f40ef8aa7..e92b1e9007951 100644
--- a/drivers/platform/x86/lenovo/Kconfig
+++ b/drivers/platform/x86/lenovo/Kconfig
@@ -16,6 +16,7 @@ config IDEAPAD_LAPTOP
select INPUT_SPARSEKMAP
select NEW_LEDS
select LEDS_CLASS
+ select LEDS_TRIGGERS
help
This is a driver for Lenovo IdeaPad netbooks contains drivers for
rfkill switch, hotkey, fan control and backlight control.
diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
index 8213524504eeb..5442cbfe3969b 100644
--- a/drivers/platform/x86/lenovo/ideapad-laptop.c
+++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
@@ -9,14 +9,18 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/acpi.h>
+#include <linux/atomic.h>
#include <linux/backlight.h>
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/cleanup.h>
+#include <linux/compiler.h>
+#include <linux/container_of.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/device.h>
+#include <linux/dev_printk.h>
#include <linux/dmi.h>
#include <linux/i8042.h>
#include <linux/init.h>
@@ -26,9 +30,11 @@
#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/platform_profile.h>
#include <linux/power_supply.h>
+#include <linux/printk.h>
#include <linux/rfkill.h>
#include <linux/seq_file.h>
#include <linux/string_choices.h>
@@ -134,10 +140,31 @@ enum {
};
/*
- * These correspond to the number of supported states - 1
- * Future keyboard types may need a new system, if there's a collision
- * KBD_BL_TRISTATE_AUTO has no way to report or set the auto state
- * so it effectively has 3 states, but needs to handle 4
+ * The enumeration has two purposes:
+ * - as an internal identifier for all known types of keyboard backlight
+ * - as a mandatory parameter of the KBLC command
+ *
+ * For each type, the hardware brightness values are defined as follows:
+ * +--------------------------+----------+-----+------+------+
+ * | Hardware brightness | 0 | 1 | 2 | 3 |
+ * | Type | | | | |
+ * +--------------------------+----------+-----+------+------+
+ * | KBD_BL_STANDARD | off | on | N/A | N/A |
+ * +--------------------------+----------+-----+------+------+
+ * | KBD_BL_TRISTATE | off | low | high | N/A |
+ * +--------------------------+----------+-----+------+------+
+ * | KBD_BL_TRISTATE_AUTO | off | low | high | auto |
+ * +--------------------------+----------+-----+------+------+
+ *
+ * We map LED classdev brightness for KBD_BL_TRISTATE_AUTO as follows:
+ * +--------------------------+----------+-----+------+
+ * | LED classdev brightness | 0 | 1 | 2 |
+ * | Operation | | | |
+ * +--------------------------+----------+-----+------+
+ * | Read | off/auto | low | high |
+ * +--------------------------+----------+-----+------+
+ * | Write | off | low | high |
+ * +--------------------------+----------+-----+------+
*/
enum {
KBD_BL_STANDARD = 1,
@@ -145,6 +172,8 @@ enum {
KBD_BL_TRISTATE_AUTO = 3,
};
+#define KBD_BL_AUTO_MODE_HW_BRIGHTNESS 3
+
#define KBD_BL_QUERY_TYPE 0x1
#define KBD_BL_TRISTATE_TYPE 0x5
#define KBD_BL_TRISTATE_AUTO_TYPE 0x7
@@ -203,7 +232,9 @@ struct ideapad_private {
bool initialized;
int type;
struct led_classdev led;
- unsigned int last_brightness;
+ atomic_t last_hw_brightness;
+
+ struct mutex notif_mutex; /* protects notifications */
} kbd_bl;
struct {
bool initialized;
@@ -1592,7 +1623,24 @@ static int ideapad_kbd_bl_check_tristate(int type)
return (type == KBD_BL_TRISTATE) || (type == KBD_BL_TRISTATE_AUTO);
}
-static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)
+static int ideapad_kbd_bl_brightness_parse(struct ideapad_private *priv, int hw_brightness)
+{
+ /* Off, low or high */
+ if (hw_brightness <= priv->kbd_bl.led.max_brightness)
+ return hw_brightness;
+
+ /* Auto (controlled by EC according to ALS), report as off */
+ if (priv->kbd_bl.type == KBD_BL_TRISTATE_AUTO &&
+ hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS)
+ return 0;
+
+ /* Unknown value */
+ dev_warn(&priv->platform_device->dev,
+ "Unknown keyboard backlight value: %d", hw_brightness);
+ return -EINVAL;
+}
+
+static int ideapad_kbd_bl_hw_brightness_get(struct ideapad_private *priv)
{
unsigned long value;
int err;
@@ -1606,21 +1654,7 @@ static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)
if (err)
return err;
- /* Convert returned value to brightness level */
- value = FIELD_GET(KBD_BL_GET_BRIGHTNESS, value);
-
- /* Off, low or high */
- if (value <= priv->kbd_bl.led.max_brightness)
- return value;
-
- /* Auto, report as off */
- if (value == priv->kbd_bl.led.max_brightness + 1)
- return 0;
-
- /* Unknown value */
- dev_warn(&priv->platform_device->dev,
- "Unknown keyboard backlight value: %lu", value);
- return -EINVAL;
+ return FIELD_GET(KBD_BL_GET_BRIGHTNESS, value);
}
err = eval_hals(priv->adev->handle, &value);
@@ -1630,6 +1664,16 @@ static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)
return !!test_bit(HALS_KBD_BL_STATE_BIT, &value);
}
+static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv)
+{
+ int hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);
+
+ if (hw_brightness < 0)
+ return hw_brightness;
+
+ return ideapad_kbd_bl_brightness_parse(priv, hw_brightness);
+}
+
static enum led_brightness ideapad_kbd_bl_led_cdev_brightness_get(struct led_classdev *led_cdev)
{
struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);
@@ -1637,62 +1681,123 @@ static enum led_brightness ideapad_kbd_bl_led_cdev_brightness_get(struct led_cla
return ideapad_kbd_bl_brightness_get(priv);
}
-static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, unsigned int brightness)
+static int ideapad_kbd_bl_hw_brightness_set(struct ideapad_private *priv, int hw_brightness)
{
- int err;
unsigned long value;
int type = priv->kbd_bl.type;
+ int err;
if (ideapad_kbd_bl_check_tristate(type)) {
- if (brightness > priv->kbd_bl.led.max_brightness)
- return -EINVAL;
-
- value = FIELD_PREP(KBD_BL_SET_BRIGHTNESS, brightness) |
+ value = FIELD_PREP(KBD_BL_SET_BRIGHTNESS, hw_brightness) |
FIELD_PREP(KBD_BL_COMMAND_TYPE, type) |
KBD_BL_COMMAND_SET;
err = exec_kblc(priv->adev->handle, value);
} else {
- err = exec_sals(priv->adev->handle, brightness ? SALS_KBD_BL_ON : SALS_KBD_BL_OFF);
+ value = hw_brightness ? SALS_KBD_BL_ON : SALS_KBD_BL_OFF;
+ err = exec_sals(priv->adev->handle, value);
}
-
if (err)
return err;
- priv->kbd_bl.last_brightness = brightness;
+ atomic_set(&priv->kbd_bl.last_hw_brightness, hw_brightness);
return 0;
}
+static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, int brightness)
+{
+ if (brightness > priv->kbd_bl.led.max_brightness)
+ return -EINVAL;
+
+ return ideapad_kbd_bl_hw_brightness_set(priv, brightness);
+}
+
static int ideapad_kbd_bl_led_cdev_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);
+ /*
+ * When deinitializing: It must be the side effect of led_cdev
+ * unregistration when our private trigger is active. We've set
+ * LED_RETAIN_AT_SHUTDOWN to retain led_cdev brightness level.
+ * To do the same for auto mode, gate changes and return early.
+ */
+ if (unlikely(!priv->kbd_bl.initialized))
+ return 0;
+
return ideapad_kbd_bl_brightness_set(priv, brightness);
}
+static bool ideapad_kbd_bl_auto_trigger_offloaded(struct led_classdev *led_cdev)
+{
+ struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);
+
+ return atomic_read(&priv->kbd_bl.last_hw_brightness) == KBD_BL_AUTO_MODE_HW_BRIGHTNESS;
+}
+
+static int ideapad_kbd_bl_auto_trigger_activate(struct led_classdev *led_cdev)
+{
+ struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led);
+
+ return ideapad_kbd_bl_hw_brightness_set(priv, KBD_BL_AUTO_MODE_HW_BRIGHTNESS);
+}
+
+static struct led_hw_trigger_type ideapad_kbd_bl_auto_trigger_type;
+
+static struct led_trigger ideapad_kbd_bl_auto_trigger = {
+ .name = "ideapad-auto",
+ .trigger_type = &ideapad_kbd_bl_auto_trigger_type,
+ .activate = ideapad_kbd_bl_auto_trigger_activate,
+ .offloaded = ideapad_kbd_bl_auto_trigger_offloaded,
+};
+
+static bool ideapad_kbd_bl_auto_trigger_registered;
+
+static void ideapad_kbd_bl_notify_hw_control(struct ideapad_private *priv,
+ int hw_brightness, int last_hw_brightness)
+{
+ bool hw_control, last_hw_control;
+
+ if (!ideapad_kbd_bl_auto_trigger_registered || priv->kbd_bl.type != KBD_BL_TRISTATE_AUTO)
+ return;
+
+ hw_control = hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS;
+ last_hw_control = last_hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS;
+
+ if (hw_control != last_hw_control)
+ led_trigger_notify_hw_control_changed(&priv->kbd_bl.led, hw_control);
+}
+
static void ideapad_kbd_bl_notify(struct ideapad_private *priv)
{
- int brightness;
+ int hw_brightness, brightness, last_hw_brightness;
if (!priv->kbd_bl.initialized)
return;
- brightness = ideapad_kbd_bl_brightness_get(priv);
- if (brightness < 0)
+ guard(mutex)(&priv->kbd_bl.notif_mutex);
+
+ hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);
+ if (hw_brightness < 0)
return;
- if (brightness == priv->kbd_bl.last_brightness)
+ brightness = ideapad_kbd_bl_brightness_parse(priv, hw_brightness);
+ if (brightness < 0)
+ return; /* Reject insane values early. */
+
+ last_hw_brightness = atomic_xchg(&priv->kbd_bl.last_hw_brightness, hw_brightness);
+ if (hw_brightness == last_hw_brightness)
return;
- priv->kbd_bl.last_brightness = brightness;
+ ideapad_kbd_bl_notify_hw_control(priv, hw_brightness, last_hw_brightness);
led_classdev_notify_brightness_hw_changed(&priv->kbd_bl.led, brightness);
}
static int ideapad_kbd_bl_init(struct ideapad_private *priv)
{
- int brightness, err;
+ int hw_brightness, err;
if (!priv->features.kbd_bl)
return -ENODEV;
@@ -1700,28 +1805,73 @@ static int ideapad_kbd_bl_init(struct ideapad_private *priv)
if (WARN_ON(priv->kbd_bl.initialized))
return -EEXIST;
- if (ideapad_kbd_bl_check_tristate(priv->kbd_bl.type))
- priv->kbd_bl.led.max_brightness = 2;
- else
- priv->kbd_bl.led.max_brightness = 1;
+ err = devm_mutex_init(&priv->platform_device->dev, &priv->kbd_bl.notif_mutex);
+ if (err)
+ return err;
- brightness = ideapad_kbd_bl_brightness_get(priv);
- if (brightness < 0)
- return brightness;
+ hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);
+ if (hw_brightness < 0)
+ return hw_brightness;
+
+ atomic_set(&priv->kbd_bl.last_hw_brightness, hw_brightness);
- priv->kbd_bl.last_brightness = brightness;
priv->kbd_bl.led.name = "platform::" LED_FUNCTION_KBD_BACKLIGHT;
priv->kbd_bl.led.brightness_get = ideapad_kbd_bl_led_cdev_brightness_get;
priv->kbd_bl.led.brightness_set_blocking = ideapad_kbd_bl_led_cdev_brightness_set;
priv->kbd_bl.led.flags = LED_BRIGHT_HW_CHANGED | LED_RETAIN_AT_SHUTDOWN;
- err = led_classdev_register(&priv->platform_device->dev, &priv->kbd_bl.led);
- if (err)
+ switch (priv->kbd_bl.type) {
+ case KBD_BL_TRISTATE_AUTO:
+ priv->kbd_bl.led.max_brightness = 2;
+
+ if (!ideapad_kbd_bl_auto_trigger_registered) {
+ dev_warn(&priv->platform_device->dev,
+ "Could not provide LED trigger %s for keyboard backlight\n",
+ ideapad_kbd_bl_auto_trigger.name);
+ break;
+ }
+
+ priv->kbd_bl.led.flags |= LED_TRIG_HW_CHANGED;
+ priv->kbd_bl.led.trigger_type = &ideapad_kbd_bl_auto_trigger_type;
+ priv->kbd_bl.led.hw_control_trigger = ideapad_kbd_bl_auto_trigger.name;
+
+ /* Hardware remembers the last brightness level, including auto mode. */
+ if (hw_brightness == KBD_BL_AUTO_MODE_HW_BRIGHTNESS)
+ priv->kbd_bl.led.default_trigger = ideapad_kbd_bl_auto_trigger.name;
+
+ break;
+ case KBD_BL_TRISTATE:
+ priv->kbd_bl.led.max_brightness = 2;
+ break;
+ case KBD_BL_STANDARD:
+ priv->kbd_bl.led.max_brightness = 1;
+ break;
+ default:
+ /* This has already been validated by ideapad_check_features(). */
+ unreachable();
+ }
+
+ /* Reject insane values. */
+ err = ideapad_kbd_bl_brightness_parse(priv, hw_brightness);
+ if (err < 0)
return err;
+ /* Queue notifications, as kbd_bl.initialized is about to be set. */
+ guard(mutex)(&priv->kbd_bl.notif_mutex);
+
+ /*
+ * Setting kbd_bl.initialized after led_classdev_register() could lead
+ * to race conditions in ideapad_kbd_bl_led_cdev_brightness_set() where
+ * kbd_bl.initialized is checked, so set it now. It can be reverted back
+ * if the LED classdev failed to register.
+ */
priv->kbd_bl.initialized = true;
- return 0;
+ err = led_classdev_register(&priv->platform_device->dev, &priv->kbd_bl.led);
+ if (err)
+ priv->kbd_bl.initialized = false;
+
+ return err;
}
static void ideapad_kbd_bl_exit(struct ideapad_private *priv)
@@ -2548,17 +2698,30 @@ static int __init ideapad_laptop_init(void)
{
int err;
+ err = led_trigger_register(&ideapad_kbd_bl_auto_trigger);
+ if (err) {
+ pr_warn("Failed to register LED trigger %s: %d\n",
+ ideapad_kbd_bl_auto_trigger.name, err);
+ } else {
+ ideapad_kbd_bl_auto_trigger_registered = true;
+ }
+
err = ideapad_wmi_driver_register();
if (err)
- return err;
+ goto err_ledtrig;
err = platform_driver_register(&ideapad_acpi_driver);
- if (err) {
- ideapad_wmi_driver_unregister();
- return err;
- }
+ if (err)
+ goto err_wmi;
return 0;
+
+err_wmi:
+ ideapad_wmi_driver_unregister();
+err_ledtrig:
+ if (ideapad_kbd_bl_auto_trigger_registered)
+ led_trigger_unregister(&ideapad_kbd_bl_auto_trigger);
+ return err;
}
module_init(ideapad_laptop_init)
@@ -2566,6 +2729,9 @@ static void __exit ideapad_laptop_exit(void)
{
platform_driver_unregister(&ideapad_acpi_driver);
ideapad_wmi_driver_unregister();
+
+ if (ideapad_kbd_bl_auto_trigger_registered)
+ led_trigger_unregister(&ideapad_kbd_bl_auto_trigger);
}
module_exit(ideapad_laptop_exit)
diff --git a/include/linux/leds.h b/include/linux/leds.h
index b16b803cc1ac5..167598962b73e 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -109,6 +109,7 @@ struct led_classdev {
#define LED_INIT_DEFAULT_TRIGGER BIT(23)
#define LED_REJECT_NAME_CONFLICT BIT(24)
#define LED_MULTI_COLOR BIT(25)
+#define LED_TRIG_HW_CHANGED BIT(26)
/* set_brightness_work / blink_timer flags, atomic, private. */
unsigned long work_flags;
@@ -485,6 +486,7 @@ struct led_trigger {
const char *name;
int (*activate)(struct led_classdev *led_cdev);
void (*deactivate)(struct led_classdev *led_cdev);
+ bool (*offloaded)(struct led_classdev *led_cdev);
/* Brightness set by led_trigger_event */
enum led_brightness brightness;
@@ -533,6 +535,9 @@ void led_trigger_blink_oneshot(struct led_trigger *trigger,
void led_trigger_set_default(struct led_classdev *led_cdev);
int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger);
void led_trigger_remove(struct led_classdev *led_cdev);
+void led_trigger_remove_hw_control(struct led_classdev *led_cdev);
+
+bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev);
static inline void led_set_trigger_data(struct led_classdev *led_cdev,
void *trigger_data)
@@ -584,6 +589,13 @@ static inline int led_trigger_set(struct led_classdev *led_cdev,
}
static inline void led_trigger_remove(struct led_classdev *led_cdev) {}
+static inline void led_trigger_remove_hw_control(struct led_classdev *led_cdev) {}
+
+static inline bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)
+{
+ return false;
+}
+
static inline void led_set_trigger_data(struct led_classdev *led_cdev) {}
static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
{
@@ -598,6 +610,13 @@ led_trigger_get_brightness(const struct led_trigger *trigger)
#endif /* CONFIG_LEDS_TRIGGERS */
+#ifdef CONFIG_LEDS_TRIGGERS_HW_CHANGED
+void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev, bool activate);
+#else
+static inline void led_trigger_notify_hw_control_changed(struct led_classdev *led_cdev,
+ bool activate) {}
+#endif
+
/* Trigger specific enum */
enum led_trigger_netdev_modes {
TRIGGER_NETDEV_LINK = 0,
|
| 29/3 | 2026/08/20 17:48 | llm | kmsan-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 15074 output: 227 thoughts: 1915 Thoughts: **LED Subsystem Patch Series Review: Uninitialized Memory Analysis** Okay, let's break this down. This patch series is aiming to enhance the LED subsystem, specifically enabling hardware-initiated trigger transitions. The primary goal seems to be supporting hardware control triggers, like keyboard backlights, which I'm familiar with from previous reviews. The introduction of the `trigger_may_offload` sysfs attribute is the key change here, and I need to ensure it's implemented safely. First, I reviewed `trigger_may_offload_show` in `led-triggers.c`. It looks like it uses `sysfs_emit`, which I know is safe for handling data exposed to userspace. I verified that `led_cdev->hw_control_trigger` is a string pointer, so the potential for a buffer overflow is handled by that function. Next, I examined `__led_trigger_is_hw_controlled`. There's no obvious uninitialized memory usage here. The code checks for `hw_control_trigger` being NULL before using it, preventing a potential crash. The `offloaded()` callback, if present, is called, but it's not a source of uninitialized memory. If it's not present, a warning is issued, which is good practice. I also looked at the modifications in `ideapad-laptop.c`. The `ideapad_kbd_bl_auto_trigger_activate`, `ideapad_kbd_bl_notify_hw_control`, and `ideapad_kbd_bl_notify` functions all seem fine. These functions carefully handle state transitions and callbacks. There are no obvious risks of uninitialized variables being used in those functions. Finally, I reviewed `led_trigger_notify_hw_control_changed`. The code has robust checks to ensure that the required trigger and control are registered correctly and are not called from a place that would cause locking issues. The use of `scoped_guard` on the `triggers_list_lock` is good to see as well. In summary, the patch series seems well-written and doesn't introduce any obvious risks of uninitialized memory usage or information leaks. No new structures are exposed to userspace with uninitialized fields. There's careful handling of pointers and proper use of locking. Any potential errors related to out-of-bounds accesses, NULL pointer dereferences, or locking would be caught by existing debug systems. Therefore, given my experience, a dedicated KMSAN fuzzing session is not needed. NeedsKMSAN will be set to false. |
| 30/3 | 2026/08/20 17:48 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series modifies the LED subsystem to support hardware-initiated trigger transitions, adding a new sysfs attribute `trigger_may_offload` and modifying several LED drivers to support this feature. The changes involve adding new callbacks (`offloaded`), modifying existing ones, and adding new logic to handle hardware control transitions.\n\nThere are no new structures sent to user space, no complex data structures allocated where uninitialized fields could be read later, and no conditional logic that depends on potentially uninitialized variables. The sysfs attribute uses `sysfs_emit`, which is safe. The changes primarily involve control flow and state management within the LED subsystem and drivers.\n\nAny potential bugs introduced by these changes, such as out-of-bounds accesses, NULL pointer dereferences, or locking issues, would be caught by standard KASAN, LOCKDEP, or other standard bug detectors. There is no risk of uninitialized memory usage or info-leaks that would require a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series modifies the LED subsystem to support hardware-initiated trigger transitions, adding a new sysfs attribute `trigger_may_offload` and modifying several LED drivers to support this feature. The changes involve adding new callbacks (`offloaded`), modifying existing ones, and adding new logic to handle hardware control transitions.\n\nThere are no new structures sent to user space, no complex data structures allocated where uninitialized fields could be read later, and no conditional logic that depends on potentially uninitialized variables. The sysfs attribute uses `sysfs_emit`, which is safe. The changes primarily involve control flow and state management within the LED subsystem and drivers.\n\nAny potential bugs introduced by these changes, such as out-of-bounds accesses, NULL pointer dereferences, or locking issues, would be caught by standard KASAN, LOCKDEP, or other standard bug detectors. There is no risk of uninitialized memory usage or info-leaks that would require a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|