aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Le Goater <clg@fr.ibm.com>2015-04-08 13:19:47 -0400
committerGuenter Roeck <linux@roeck-us.net>2015-04-08 13:34:19 -0400
commit9e4f74b11925d033dcbe429f1fb6202cab03ad8f (patch)
treeb75229d60f4bc2cc7402b93df84b67124afdaaec
parentfa3f70d62844bd91880ea634c06b46585fefd74b (diff)
hwmon: (ibmpowernv) add a helper routine create_hwmon_attr
This should shorten a bit the code necessary to create a hmwon attribute. Signed-off-by: Cédric Le Goater <clg@fr.ibm.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/ibmpowernv.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
index 99ca5362dbca..ebf335c71990 100644
--- a/drivers/hwmon/ibmpowernv.c
+++ b/drivers/hwmon/ibmpowernv.c
@@ -232,6 +232,21 @@ static int populate_attr_groups(struct platform_device *pdev)
232 return 0; 232 return 0;
233} 233}
234 234
235static void create_hwmon_attr(struct sensor_data *sdata, const char *attr_name,
236 ssize_t (*show)(struct device *dev,
237 struct device_attribute *attr,
238 char *buf))
239{
240 snprintf(sdata->name, MAX_ATTR_LEN, "%s%d_%s",
241 sensor_groups[sdata->type].name, sdata->hwmon_index,
242 attr_name);
243
244 sysfs_attr_init(&sdata->dev_attr.attr);
245 sdata->dev_attr.attr.name = sdata->name;
246 sdata->dev_attr.attr.mode = S_IRUGO;
247 sdata->dev_attr.show = show;
248}
249
235/* 250/*
236 * Iterate through the device tree for each child of 'sensors' node, create 251 * Iterate through the device tree for each child of 'sensors' node, create
237 * a sysfs attribute file, the file is named by translating the DT node name 252 * a sysfs attribute file, the file is named by translating the DT node name
@@ -290,14 +305,7 @@ static int create_device_attrs(struct platform_device *pdev)
290 sdata[count].hwmon_index = 305 sdata[count].hwmon_index =
291 get_sensor_hwmon_index(&sdata[count], sdata, count); 306 get_sensor_hwmon_index(&sdata[count], sdata, count);
292 307
293 snprintf(sdata[count].name, MAX_ATTR_LEN, "%s%d_%s", 308 create_hwmon_attr(&sdata[count], attr_name, show_sensor);
294 sensor_groups[type].name, sdata[count].hwmon_index,
295 attr_name);
296
297 sysfs_attr_init(&sdata[count].dev_attr.attr);
298 sdata[count].dev_attr.attr.name = sdata[count].name;
299 sdata[count].dev_attr.attr.mode = S_IRUGO;
300 sdata[count].dev_attr.show = show_sensor;
301 309
302 pgroups[type]->attrs[sensor_groups[type].attr_count++] = 310 pgroups[type]->attrs[sensor_groups[type].attr_count++] =
303 &sdata[count++].dev_attr.attr; 311 &sdata[count++].dev_attr.attr;