lkml.org 
[lkml]   [2021]   [Dec]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] hwmon: Add "label" attribute
Date
If a label is defined in the device tree for this device add that
to the device specific attributes. This is useful for userspace to
be able to identify an individual device when multiple identical
chips are present in the system.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Tested-by: Cosmin Tanislav <cosmin.tanislav@analog.com>
---
drivers/hwmon/hwmon.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 3501a3ead4ba..15826260a463 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -71,8 +71,23 @@ name_show(struct device *dev, struct device_attribute *attr, char *buf)
}
static DEVICE_ATTR_RO(name);

+static ssize_t
+label_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ const char *label;
+ int ret;
+
+ ret = device_property_read_string(dev, "label", &label);
+ if (ret < 0)
+ return ret;
+
+ return sysfs_emit(buf, "%s\n", label);
+}
+static DEVICE_ATTR_RO(label);
+
static struct attribute *hwmon_dev_attrs[] = {
&dev_attr_name.attr,
+ &dev_attr_label.attr,
NULL
};

@@ -81,7 +96,12 @@ static umode_t hwmon_dev_name_is_visible(struct kobject *kobj,
{
struct device *dev = kobj_to_dev(kobj);

- if (to_hwmon_device(dev)->name == NULL)
+ if (attr == &dev_attr_name.attr &&
+ to_hwmon_device(dev)->name == NULL)
+ return 0;
+
+ if (attr == &dev_attr_label.attr &&
+ !device_property_present(dev, "label"))
return 0;

return attr->mode;
--
2.34.1
\
 
 \ /
  Last update: 2021-12-21 18:51    [W:0.072 / U:0.236 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site