Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Lukas Wunner and committed by
Greg Kroah-Hartman
aa1fd9cd 3cc50d07

+8 -21
+4 -11
drivers/hwmon/i5k_amb.c
··· 101 101 unsigned int num_attrs; 102 102 }; 103 103 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); 112 105 113 106 static struct platform_device *amb_pdev; 114 107 ··· 366 373 } 367 374 } 368 375 369 - res = device_create_file(&pdev->dev, &dev_attr_name); 376 + res = device_create_file(&pdev->dev, &dev_attr_name.attr); 370 377 if (res) 371 378 goto exit_remove; 372 379 ··· 379 386 return res; 380 387 381 388 exit_remove: 382 - device_remove_file(&pdev->dev, &dev_attr_name); 389 + device_remove_file(&pdev->dev, &dev_attr_name.attr); 383 390 for (i = 0; i < data->num_attrs; i++) 384 391 device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr); 385 392 kfree(data->attrs); ··· 554 561 struct i5k_amb_data *data = platform_get_drvdata(pdev); 555 562 556 563 hwmon_device_unregister(data->hwmon_dev); 557 - device_remove_file(&pdev->dev, &dev_attr_name); 564 + device_remove_file(&pdev->dev, &dev_attr_name.attr); 558 565 for (i = 0; i < data->num_attrs; i++) 559 566 device_remove_file(&pdev->dev, &data->attrs[i].s_attr.dev_attr); 560 567 kfree(data->attrs);
+4 -10
drivers/hwmon/ibmpex.c
··· 256 256 return NULL; 257 257 } 258 258 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); 265 260 266 261 static ssize_t ibmpex_show_sensor(struct device *dev, 267 262 struct device_attribute *devattr, ··· 410 415 if (err) 411 416 goto exit_remove; 412 417 413 - err = device_create_file(data->bmc_device, 414 - &sensor_dev_attr_name.dev_attr); 418 + err = device_create_file(data->bmc_device, &dev_attr_name.attr); 415 419 if (err) 416 420 goto exit_remove; 417 421 ··· 419 425 exit_remove: 420 426 device_remove_file(data->bmc_device, 421 427 &sensor_dev_attr_reset_high_low.dev_attr); 422 - device_remove_file(data->bmc_device, &sensor_dev_attr_name.dev_attr); 428 + device_remove_file(data->bmc_device, &dev_attr_name.attr); 423 429 for (i = 0; i < data->num_sensors; i++) 424 430 for (j = 0; j < PEX_NUM_SENSOR_FUNCS; j++) { 425 431 if (!data->sensors[i].attr[j].dev_attr.attr.name) ··· 510 516 511 517 device_remove_file(data->bmc_device, 512 518 &sensor_dev_attr_reset_high_low.dev_attr); 513 - device_remove_file(data->bmc_device, &sensor_dev_attr_name.dev_attr); 519 + device_remove_file(data->bmc_device, &dev_attr_name.attr); 514 520 for (i = 0; i < data->num_sensors; i++) 515 521 for (j = 0; j < PEX_NUM_SENSOR_FUNCS; j++) { 516 522 if (!data->sensors[i].attr[j].dev_attr.attr.name)