leds: trigger: Move led_trigger_is_hw_controlled() to the right place

Currently led_trigger_is_hw_controlled() is placed at led-class.c, which
is not an right place as it falls into the triggers namespace and does
triggers stuff.

Move it into led-triggers.c, and split it into locked and unlocked
variant for convenience.

Fixes: b819dc7d8f ("leds: core: Report ENODATA for brightness of hardware controlled LED")
Acked-by: Ike Panhc <ikepanhc@gmail.com>
Signed-off-by: Rong Zhang <i@rong.moe>
Link: https://patch.msgid.link/20260921-leds-trigger-hw-changed-v7-2-fe3cdb6dec51@rong.moe
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
Rong Zhang 2026-09-21 03:40:16 +08:00 committed by Lee Jones
parent 6887f40dad
commit 7879d62774
3 changed files with 27 additions and 10 deletions

View File

@ -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)
{

View File

@ -7,9 +7,11 @@
* Author: Richard Purdie <rpurdie@openedhand.com>
*/
#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 +35,23 @@ 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;
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)

View File

@ -534,6 +534,8 @@ 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);
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 +586,12 @@ static inline int led_trigger_set(struct led_classdev *led_cdev,
}
static inline void led_trigger_remove(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)
{