linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: class: don't expose brightness attributes if needed callbacks aren't implemented
@ 2021-07-24 20:25 Heiner Kallweit
  0 siblings, 0 replies; only message in thread
From: Heiner Kallweit @ 2021-07-24 20:25 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-leds@vger.kernel.org

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-24 20:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-24 20:25 [PATCH] leds: class: don't expose brightness attributes if needed callbacks aren't implemented Heiner Kallweit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).