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

scsi: 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>
Link: https://lore.kernel.org/r/b11792137186f5a6794f12fdf891d0c6d51b3557.1713608122.git.lukas@wunner.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Lukas Wunner and committed by
Greg Kroah-Hartman
9bb8e306 3182459b

+16 -55
+7 -21
drivers/scsi/bfa/bfad_attr.c
··· 854 854 } 855 855 856 856 static ssize_t 857 - bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr, 858 - char *buf) 859 - { 860 - return sysfs_emit(buf, "%s\n", BFAD_DRIVER_VERSION); 861 - } 862 - 863 - static ssize_t 864 857 bfad_im_optionrom_version_show(struct device *dev, 865 858 struct device_attribute *attr, char *buf) 866 859 { ··· 895 902 } 896 903 897 904 static ssize_t 898 - bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr, 899 - char *buf) 900 - { 901 - return sysfs_emit(buf, "%s\n", BFAD_DRIVER_NAME); 902 - } 903 - 904 - static ssize_t 905 905 bfad_im_num_of_discovered_ports_show(struct device *dev, 906 906 struct device_attribute *attr, char *buf) 907 907 { ··· 930 944 bfad_im_symbolic_name_show, NULL); 931 945 static DEVICE_ATTR(hardware_version, S_IRUGO, 932 946 bfad_im_hw_version_show, NULL); 933 - static DEVICE_ATTR(driver_version, S_IRUGO, 934 - bfad_im_drv_version_show, NULL); 947 + static DEVICE_STRING_ATTR_RO(driver_version, S_IRUGO, 948 + BFAD_DRIVER_VERSION); 935 949 static DEVICE_ATTR(option_rom_version, S_IRUGO, 936 950 bfad_im_optionrom_version_show, NULL); 937 951 static DEVICE_ATTR(firmware_version, S_IRUGO, 938 952 bfad_im_fw_version_show, NULL); 939 953 static DEVICE_ATTR(number_of_ports, S_IRUGO, 940 954 bfad_im_num_of_ports_show, NULL); 941 - static DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL); 955 + static DEVICE_STRING_ATTR_RO(driver_name, S_IRUGO, BFAD_DRIVER_NAME); 942 956 static DEVICE_ATTR(number_of_discovered_ports, S_IRUGO, 943 957 bfad_im_num_of_discovered_ports_show, NULL); 944 958 ··· 949 963 &dev_attr_node_name.attr, 950 964 &dev_attr_symbolic_name.attr, 951 965 &dev_attr_hardware_version.attr, 952 - &dev_attr_driver_version.attr, 966 + &dev_attr_driver_version.attr.attr, 953 967 &dev_attr_option_rom_version.attr, 954 968 &dev_attr_firmware_version.attr, 955 969 &dev_attr_number_of_ports.attr, 956 - &dev_attr_driver_name.attr, 970 + &dev_attr_driver_name.attr.attr, 957 971 &dev_attr_number_of_discovered_ports.attr, 958 972 NULL, 959 973 }; ··· 974 988 &dev_attr_node_name.attr, 975 989 &dev_attr_symbolic_name.attr, 976 990 &dev_attr_hardware_version.attr, 977 - &dev_attr_driver_version.attr, 991 + &dev_attr_driver_version.attr.attr, 978 992 &dev_attr_option_rom_version.attr, 979 993 &dev_attr_firmware_version.attr, 980 994 &dev_attr_number_of_ports.attr, 981 - &dev_attr_driver_name.attr, 995 + &dev_attr_driver_name.attr.attr, 982 996 &dev_attr_number_of_discovered_ports.attr, 983 997 NULL, 984 998 };
+2 -9
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
··· 3613 3613 kfree(vscsi); 3614 3614 } 3615 3615 3616 - static ssize_t system_id_show(struct device *dev, 3617 - struct device_attribute *attr, char *buf) 3618 - { 3619 - return sysfs_emit(buf, "%s\n", system_id); 3620 - } 3621 - 3622 3616 static ssize_t partition_number_show(struct device *dev, 3623 3617 struct device_attribute *attr, char *buf) 3624 3618 { ··· 3976 3982 3977 3983 static void ibmvscsis_dev_release(struct device *dev) {}; 3978 3984 3979 - static struct device_attribute dev_attr_system_id = 3980 - __ATTR(system_id, S_IRUGO, system_id_show, NULL); 3985 + static DEVICE_STRING_ATTR_RO(system_id, S_IRUGO, system_id); 3981 3986 3982 3987 static struct device_attribute dev_attr_partition_number = 3983 3988 __ATTR(partition_number, S_IRUGO, partition_number_show, NULL); ··· 3985 3992 __ATTR(unit_address, S_IRUGO, unit_address_show, NULL); 3986 3993 3987 3994 static struct attribute *ibmvscsis_dev_attrs[] = { 3988 - &dev_attr_system_id.attr, 3995 + &dev_attr_system_id.attr.attr, 3989 3996 &dev_attr_partition_number.attr, 3990 3997 &dev_attr_unit_address.attr, 3991 3998 };
+2 -8
drivers/scsi/mvsas/mv_init.c
··· 691 691 .remove = mvs_pci_remove, 692 692 }; 693 693 694 - static ssize_t driver_version_show(struct device *cdev, 695 - struct device_attribute *attr, char *buffer) 696 - { 697 - return sysfs_emit(buffer, "%s\n", DRV_VERSION); 698 - } 699 - 700 - static DEVICE_ATTR_RO(driver_version); 694 + static DEVICE_STRING_ATTR_RO(driver_version, 0444, DRV_VERSION); 701 695 702 696 static ssize_t interrupt_coalescing_store(struct device *cdev, 703 697 struct device_attribute *attr, ··· 766 772 } 767 773 768 774 static struct attribute *mvst_host_attrs[] = { 769 - &dev_attr_driver_version.attr, 775 + &dev_attr_driver_version.attr.attr, 770 776 &dev_attr_interrupt_coalescing.attr, 771 777 NULL, 772 778 };
+2 -9
drivers/scsi/qla2xxx/qla_attr.c
··· 1068 1068 /* Scsi_Host attributes. */ 1069 1069 1070 1070 static ssize_t 1071 - qla2x00_driver_version_show(struct device *dev, 1072 - struct device_attribute *attr, char *buf) 1073 - { 1074 - return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str); 1075 - } 1076 - 1077 - static ssize_t 1078 1071 qla2x00_fw_version_show(struct device *dev, 1079 1072 struct device_attribute *attr, char *buf) 1080 1073 { ··· 2405 2412 static DEVICE_ATTR(dport_diagnostics, 0444, 2406 2413 qla2x00_dport_diagnostics_show, NULL); 2407 2414 2408 - static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_driver_version_show, NULL); 2415 + static DEVICE_STRING_ATTR_RO(driver_version, S_IRUGO, qla2x00_version_str); 2409 2416 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL); 2410 2417 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL); 2411 2418 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL); ··· 2471 2478 static DEVICE_ATTR(fw_attr, 0444, qla2x00_fw_attr_show, NULL); 2472 2479 2473 2480 static struct attribute *qla2x00_host_attrs[] = { 2474 - &dev_attr_driver_version.attr, 2481 + &dev_attr_driver_version.attr.attr, 2475 2482 &dev_attr_fw_version.attr, 2476 2483 &dev_attr_serial_num.attr, 2477 2484 &dev_attr_isp_name.attr,
+3 -8
drivers/scsi/smartpqi/smartpqi_init.c
··· 6892 6892 return scnprintf(buffer, PAGE_SIZE, "%s\n", ctrl_info->firmware_version); 6893 6893 } 6894 6894 6895 - static ssize_t pqi_driver_version_show(struct device *dev, 6896 - struct device_attribute *attr, char *buffer) 6897 - { 6898 - return scnprintf(buffer, PAGE_SIZE, "%s\n", DRIVER_VERSION BUILD_TIMESTAMP); 6899 - } 6900 - 6901 6895 static ssize_t pqi_serial_number_show(struct device *dev, 6902 6896 struct device_attribute *attr, char *buffer) 6903 6897 { ··· 7060 7066 return count; 7061 7067 } 7062 7068 7063 - static DEVICE_ATTR(driver_version, 0444, pqi_driver_version_show, NULL); 7069 + static DEVICE_STRING_ATTR_RO(driver_version, 0444, 7070 + DRIVER_VERSION BUILD_TIMESTAMP); 7064 7071 static DEVICE_ATTR(firmware_version, 0444, pqi_firmware_version_show, NULL); 7065 7072 static DEVICE_ATTR(model, 0444, pqi_model_show, NULL); 7066 7073 static DEVICE_ATTR(serial_number, 0444, pqi_serial_number_show, NULL); ··· 7078 7083 pqi_host_enable_r6_writes_show, pqi_host_enable_r6_writes_store); 7079 7084 7080 7085 static struct attribute *pqi_shost_attrs[] = { 7081 - &dev_attr_driver_version.attr, 7086 + &dev_attr_driver_version.attr.attr, 7082 7087 &dev_attr_firmware_version.attr, 7083 7088 &dev_attr_model.attr, 7084 7089 &dev_attr_serial_number.attr,