From: Heiner Kallweit <hkallweit1@gmail.com>
To: Pavel Machek <pavel@ucw.cz>
Cc: "linux-leds@vger.kernel.org" <linux-leds@vger.kernel.org>
Subject: [PATCH] leds: class: don't expose brightness attributes if needed callbacks aren't implemented
Date: Sat, 24 Jul 2021 22:25:01 +0200 [thread overview]
Message-ID: <6f61a6e8-147f-18de-2cbe-1a52f01e1529@gmail.com> (raw)
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
reply other threads:[~2021-07-24 20:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6f61a6e8-147f-18de-2cbe-1a52f01e1529@gmail.com \
--to=hkallweit1@gmail.com \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).