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>
This commit is contained in:
Lukas Wunner 2024-04-20 22:00:02 +02:00 committed by Greg Kroah-Hartman
parent 3cc50d07be
commit aa1fd9cdab
2 changed files with 8 additions and 21 deletions

View File

@ -101,14 +101,7 @@ struct i5k_amb_data {
unsigned int num_attrs; unsigned int num_attrs;
}; };
static ssize_t name_show(struct device *dev, struct device_attribute *devattr, static DEVICE_STRING_ATTR_RO(name, 0444, DRVNAME);
char *buf)
{
return sprintf(buf, "%s\n", DRVNAME);
}
static DEVICE_ATTR_RO(name);
static struct platform_device *amb_pdev; static struct platform_device *amb_pdev;
@ -373,7 +366,7 @@ static int i5k_amb_hwmon_init(struct platform_device *pdev)
} }
} }
res = device_create_file(&pdev->dev, &dev_attr_name); res = device_create_file(&pdev->dev, &dev_attr_name.attr);
if (res) if (res)
goto exit_remove; goto exit_remove;
@ -386,7 +379,7 @@ static int i5k_amb_hwmon_init(struct platform_device *pdev)
return res; return res;
exit_remove: exit_remove:
device_remove_file(&pdev->dev, &dev_attr_name); device_remove_file(&pdev->dev, &dev_attr_name.attr);
for (i = 0; i < data->num_attrs; i++) for (i = 0; i < data->num_attrs; i++)
device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr); device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr);
kfree(data->attrs); kfree(data->attrs);
@ -561,7 +554,7 @@ static void i5k_amb_remove(struct platform_device *pdev)
struct i5k_amb_data *data = platform_get_drvdata(pdev); struct i5k_amb_data *data = platform_get_drvdata(pdev);
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
device_remove_file(&pdev->dev, &dev_attr_name); device_remove_file(&pdev->dev, &dev_attr_name.attr);
for (i = 0; i < data->num_attrs; i++) for (i = 0; i < data->num_attrs; i++)
device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr); device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr);
kfree(data->attrs); kfree(data->attrs);

View File

@ -256,12 +256,7 @@ static struct ibmpex_bmc_data *get_bmc_data(int iface)
return NULL; return NULL;
} }
static ssize_t name_show(struct device *dev, struct device_attribute *devattr, static DEVICE_STRING_ATTR_RO(name, 0444, DRVNAME);
char *buf)
{
return sprintf(buf, "%s\n", DRVNAME);
}
static SENSOR_DEVICE_ATTR_RO(name, name, 0);
static ssize_t ibmpex_show_sensor(struct device *dev, static ssize_t ibmpex_show_sensor(struct device *dev,
struct device_attribute *devattr, struct device_attribute *devattr,
@ -415,8 +410,7 @@ static int ibmpex_find_sensors(struct ibmpex_bmc_data *data)
if (err) if (err)
goto exit_remove; goto exit_remove;
err = device_create_file(data->bmc_device, err = device_create_file(data->bmc_device, &dev_attr_name.attr);
&sensor_dev_attr_name.dev_attr);
if (err) if (err)
goto exit_remove; goto exit_remove;
@ -425,7 +419,7 @@ static int ibmpex_find_sensors(struct ibmpex_bmc_data *data)
exit_remove: exit_remove:
device_remove_file(data->bmc_device, device_remove_file(data->bmc_device,
&sensor_dev_attr_reset_high_low.dev_attr); &sensor_dev_attr_reset_high_low.dev_attr);
device_remove_file(data->bmc_device, &sensor_dev_attr_name.dev_attr); device_remove_file(data->bmc_device, &dev_attr_name.attr);
for (i = 0; i < data->num_sensors; i++) for (i = 0; i < data->num_sensors; i++)
for (j = 0; j < PEX_NUM_SENSOR_FUNCS; j++) { for (j = 0; j < PEX_NUM_SENSOR_FUNCS; j++) {
if (!data->sensors[i].attr[j].dev_attr.attr.name) if (!data->sensors[i].attr[j].dev_attr.attr.name)
@ -516,7 +510,7 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data)
device_remove_file(data->bmc_device, device_remove_file(data->bmc_device,
&sensor_dev_attr_reset_high_low.dev_attr); &sensor_dev_attr_reset_high_low.dev_attr);
device_remove_file(data->bmc_device, &sensor_dev_attr_name.dev_attr); device_remove_file(data->bmc_device, &dev_attr_name.attr);
for (i = 0; i < data->num_sensors; i++) for (i = 0; i < data->num_sensors; i++)
for (j = 0; j < PEX_NUM_SENSOR_FUNCS; j++) { for (j = 0; j < PEX_NUM_SENSOR_FUNCS; j++) {
if (!data->sensors[i].attr[j].dev_attr.attr.name) if (!data->sensors[i].attr[j].dev_attr.attr.name)