[PATCH] leds: class: don't expose brightness attributes if needed callbacks aren't implemented

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <hkallweit1@xxxxxxxxx>
---
 drivers/leds/led-class.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index f704391d5..742d59296 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -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,
 };
 
-- 
2.32.0




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux