diff mbox series

leds: triggers: Improve handling of LEDs supporting hw triggers only

Message ID cfacb5b8-e7bf-c7c8-c5ab-4a8048a67db2@gmail.com
State New
Headers show
Series leds: triggers: Improve handling of LEDs supporting hw triggers only | expand

Commit Message

Heiner Kallweit July 22, 2021, 8:16 p.m. UTC
A LED supporting HW triggers only (example: network PHY LED indicating
100M link or 1000M link or ..) may have none of the software LED
control callbacks implemented. As of today the software LED control
triggers would be available nevertheless. This doesn't make sense.
If a LED supports HW triggers only, offer only the matching HW triggers.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/leds/led-triggers.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 4e7b78a84..48924bad2 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -27,10 +27,23 @@  LIST_HEAD(trigger_list);
 
  /* Used by LED Class */
 
-static inline bool
-trigger_relevant(struct led_classdev *led_cdev, struct led_trigger *trig)
+static bool led_hw_trig_only(struct led_classdev *led_cdev)
 {
-	return !trig->trigger_type || trig->trigger_type == led_cdev->trigger_type;
+	return !led_cdev->brightness_set && !led_cdev->brightness_set_blocking &&
+	       !led_cdev->blink_set && !led_cdev->pattern_set;
+}
+
+static bool trigger_relevant(struct led_classdev *led_cdev,
+			     struct led_trigger *trig)
+{
+	if (trig->trigger_type == led_cdev->trigger_type)
+		return true;
+
+	/* LED supports matching hw triggers only */
+	if (led_hw_trig_only(led_cdev))
+		return false;
+
+	return !trig->trigger_type;
 }
 
 ssize_t led_trigger_write(struct file *filp, struct kobject *kobj,