Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit aa1fd9c

Browse files
l1kgregkh
authored andcommitted
hwmon: Use device_show_string() helper for sysfs attributes
Deduplicate sysfs ->show() callbacks which expose a string at a static memory location. Use the newly introduced device_show_string() helper in the driver core instead by declaring those sysfs attributes with DEVICE_STRING_ATTR_RO(). No functional change intended. Signed-off-by: Lukas Wunner <lukas@wunner.de> Acked-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/23c2031acaa64f1c02f00e817c3f7e4466d17ab2.1713608122.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3cc50d0 commit aa1fd9c

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

drivers/hwmon/i5k_amb.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,7 @@ struct i5k_amb_data {
101101
unsigned int num_attrs;
102102
};
103103

104-
static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
105-
char *buf)
106-
{
107-
return sprintf(buf, "%s\n", DRVNAME);
108-
}
109-
110-
111-
static DEVICE_ATTR_RO(name);
104+
static DEVICE_STRING_ATTR_RO(name, 0444, DRVNAME);
112105

113106
static struct platform_device *amb_pdev;
114107

@@ -373,7 +366,7 @@ static int i5k_amb_hwmon_init(struct platform_device *pdev)
373366
}
374367
}
375368

376-
res = device_create_file(&pdev->dev, &dev_attr_name);
369+
res = device_create_file(&pdev->dev, &dev_attr_name.attr);
377370
if (res)
378371
goto exit_remove;
379372

@@ -386,7 +379,7 @@ static int i5k_amb_hwmon_init(struct platform_device *pdev)
386379
return res;
387380

388381
exit_remove:
389-
device_remove_file(&pdev->dev, &dev_attr_name);
382+
device_remove_file(&pdev->dev, &dev_attr_name.attr);
390383
for (i = 0; i < data->num_attrs; i++)
391384
device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr);
392385
kfree(data->attrs);
@@ -561,7 +554,7 @@ static void i5k_amb_remove(struct platform_device *pdev)
561554
struct i5k_amb_data *data = platform_get_drvdata(pdev);
562555

563556
hwmon_device_unregister(data->hwmon_dev);
564-
device_remove_file(&pdev->dev, &dev_attr_name);
557+
device_remove_file(&pdev->dev, &dev_attr_name.attr);
565558
for (i = 0; i < data->num_attrs; i++)
566559
device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr);
567560
kfree(data->attrs);

drivers/hwmon/ibmpex.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,7 @@ static struct ibmpex_bmc_data *get_bmc_data(int iface)
256256
return NULL;
257257
}
258258

259-
static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
260-
char *buf)
261-
{
262-
return sprintf(buf, "%s\n", DRVNAME);
263-
}
264-
static SENSOR_DEVICE_ATTR_RO(name, name, 0);
259+
static DEVICE_STRING_ATTR_RO(name, 0444, DRVNAME);
265260

266261
static ssize_t ibmpex_show_sensor(struct device *dev,
267262
struct device_attribute *devattr,
@@ -415,8 +410,7 @@ static int ibmpex_find_sensors(struct ibmpex_bmc_data *data)
415410
if (err)
416411
goto exit_remove;
417412

418-
err = device_create_file(data->bmc_device,
419-
&sensor_dev_attr_name.dev_attr);
413+
err = device_create_file(data->bmc_device, &dev_attr_name.attr);
420414
if (err)
421415
goto exit_remove;
422416

@@ -425,7 +419,7 @@ static int ibmpex_find_sensors(struct ibmpex_bmc_data *data)
425419
exit_remove:
426420
device_remove_file(data->bmc_device,
427421
&sensor_dev_attr_reset_high_low.dev_attr);
428-
device_remove_file(data->bmc_device, &sensor_dev_attr_name.dev_attr);
422+
device_remove_file(data->bmc_device, &dev_attr_name.attr);
429423
for (i = 0; i < data->num_sensors; i++)
430424
for (j = 0; j < PEX_NUM_SENSOR_FUNCS; j++) {
431425
if (!data->sensors[i].attr[j].dev_attr.attr.name)
@@ -516,7 +510,7 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data)
516510

517511
device_remove_file(data->bmc_device,
518512
&sensor_dev_attr_reset_high_low.dev_attr);
519-
device_remove_file(data->bmc_device, &sensor_dev_attr_name.dev_attr);
513+
device_remove_file(data->bmc_device, &dev_attr_name.attr);
520514
for (i = 0; i < data->num_sensors; i++)
521515
for (j = 0; j < PEX_NUM_SENSOR_FUNCS; j++) {
522516
if (!data->sensors[i].attr[j].dev_attr.attr.name)

0 commit comments

Comments
 (0)