leds: class: don't expose brightness attributes if needed callbacks aren't implemented
PATCH 1/1 leds: class: don't expose brightness attributes if needed callbacks aren't implemented
If neither brightness_set nor brightness_set_blocking callback is implemented (e.g. for a LED supporting HW triggers only), then exposing the brightness-related sysfs attributes doesn't make sense.
Signed-off-by Heiner Kallweit <[email protected]>
--- drivers/leds/led-class.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/leds/led-class.c +13 -0
@@ -74,6 +74,18 @@ static ssize_t max_brightness_show(struct device *dev, }static DEVICE_ATTR_RO (max_brightness); +static umode_t led_brightness_attrs_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 (!led_cdev->brightness_set && !led_cdev->brightness_set_blocking) +return 0 ; + +return attr->mode; +} +#ifdef CONFIG_LEDS_TRIGGERS static BIN_ATTR(trigger, 0644, led_trigger_read, led_trigger_write, 0); static struct bin_attribute *led_trigger_bin_attrs[] = {
@@ -92,6 +104,7 @@ static struct attribute *led_class_attrs[] = { };static const struct attribute_group led_group = { + .is_visible = led_brightness_attrs_visible, .attrs = led_class_attrs, };
Signature · 1 line
2.32.0