2024-03-19 06:40:29

by Zhijian Li (Fujitsu)

[permalink] [raw]
Subject: [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family

Per filesystems/sysfs.rst, show() should only use sysfs_emit()
or sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

sprintf() and scnprintf() will be converted as well if they have.

Generally, this patch is generated by
make coccicheck M=<path/to/file> MODE=patch \
COCCI=scripts/coccinelle/api/device_attr_show.cocci

No functional change intended

CC: Adaptec OEM Raid Solutions <[email protected]>
CC: "James E.J. Bottomley" <[email protected]>
CC: "Martin K. Petersen" <[email protected]>
CC: [email protected]
Signed-off-by: Li Zhijian <[email protected]>
---
This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
Split them per subsystem so that the maintainer can review it easily
[1] https://lore.kernel.org/lkml/[email protected]/

Signed-off-by: Li Zhijian <[email protected]>
---
drivers/scsi/aacraid/linit.c | 78 ++++++++++++++++--------------------
1 file changed, 35 insertions(+), 43 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 68f4dbcfff49..a9c7e3e0ca33 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -558,11 +558,11 @@ static ssize_t aac_show_raid_level(struct device *dev, struct device_attribute *
struct scsi_device *sdev = to_scsi_device(dev);
struct aac_dev *aac = (struct aac_dev *)(sdev->host->hostdata);
if (sdev_channel(sdev) != CONTAINER_CHANNEL)
- return snprintf(buf, PAGE_SIZE, sdev->no_uld_attach
- ? "Hidden\n" :
+ return sysfs_emit(buf, sdev->no_uld_attach ? "Hidden\n" :
((aac->jbod && (sdev->type == TYPE_DISK)) ? "JBOD\n" : ""));
- return snprintf(buf, PAGE_SIZE, "%s\n",
- get_container_type(aac->fsa_dev[sdev_id(sdev)].type));
+
+ return sysfs_emit(buf, "%s\n",
+ get_container_type(aac->fsa_dev[sdev_id(sdev)].type));
}

static struct device_attribute aac_raid_level_attr = {
@@ -585,12 +585,12 @@ static ssize_t aac_show_unique_id(struct device *dev,
if (sdev_channel(sdev) == CONTAINER_CHANNEL)
memcpy(sn, aac->fsa_dev[sdev_id(sdev)].identifier, sizeof(sn));

- return snprintf(buf, 16 * 2 + 2,
- "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
- sn[0], sn[1], sn[2], sn[3],
- sn[4], sn[5], sn[6], sn[7],
- sn[8], sn[9], sn[10], sn[11],
- sn[12], sn[13], sn[14], sn[15]);
+ return sysfs_emit(buf,
+ "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
+ sn[0], sn[1], sn[2], sn[3],
+ sn[4], sn[5], sn[6], sn[7],
+ sn[8], sn[9], sn[10], sn[11],
+ sn[12], sn[13], sn[14], sn[15]);
}

static struct device_attribute aac_unique_id_attr = {
@@ -1195,10 +1195,9 @@ static ssize_t aac_show_model(struct device *device,
++cp;
while (*cp == ' ')
++cp;
- len = snprintf(buf, PAGE_SIZE, "%s\n", cp);
+ len = sysfs_emit(buf, "%s\n", cp);
} else
- len = snprintf(buf, PAGE_SIZE, "%s\n",
- aac_drivers[dev->cardtype].model);
+ len = sysfs_emit(buf, "%s\n", aac_drivers[dev->cardtype].model);
return len;
}

@@ -1214,12 +1213,11 @@ static ssize_t aac_show_vendor(struct device *device,
char *cp = sup_adap_info->adapter_type_text;
while (*cp && *cp != ' ')
++cp;
- len = snprintf(buf, PAGE_SIZE, "%.*s\n",
- (int)(cp - (char *)sup_adap_info->adapter_type_text),
- sup_adap_info->adapter_type_text);
+ len = sysfs_emit(buf, "%.*s\n",
+ (int)(cp - (char *)sup_adap_info->adapter_type_text),
+ sup_adap_info->adapter_type_text);
} else
- len = snprintf(buf, PAGE_SIZE, "%s\n",
- aac_drivers[dev->cardtype].vname);
+ len = sysfs_emit(buf, "%s\n", aac_drivers[dev->cardtype].vname);
return len;
}

@@ -1230,23 +1228,19 @@ static ssize_t aac_show_flags(struct device *cdev,
struct aac_dev *dev = (struct aac_dev*)class_to_shost(cdev)->hostdata;

if (nblank(dprintk(x)))
- len = snprintf(buf, PAGE_SIZE, "dprintk\n");
+ len = sysfs_emit(buf, "dprintk\n");
#ifdef AAC_DETAILED_STATUS_INFO
- len += scnprintf(buf + len, PAGE_SIZE - len,
- "AAC_DETAILED_STATUS_INFO\n");
+ len += sysfs_emit_at(buf, len, "AAC_DETAILED_STATUS_INFO\n");
#endif
if (dev->raw_io_interface && dev->raw_io_64)
- len += scnprintf(buf + len, PAGE_SIZE - len,
- "SAI_READ_CAPACITY_16\n");
+ len += sysfs_emit_at(buf, len, "SAI_READ_CAPACITY_16\n");
if (dev->jbod)
- len += scnprintf(buf + len, PAGE_SIZE - len,
- "SUPPORTED_JBOD\n");
+ len += sysfs_emit_at(buf, len, "SUPPORTED_JBOD\n");
if (dev->supplement_adapter_info.supported_options2 &
AAC_OPTION_POWER_MANAGEMENT)
- len += scnprintf(buf + len, PAGE_SIZE - len,
- "SUPPORTED_POWER_MANAGEMENT\n");
+ len += sysfs_emit_at(buf, len, "SUPPORTED_POWER_MANAGEMENT\n");
if (dev->msi)
- len += scnprintf(buf + len, PAGE_SIZE - len, "PCI_HAS_MSI\n");
+ len += sysfs_emit_at(buf, len, "PCI_HAS_MSI\n");
return len;
}

@@ -1258,9 +1252,9 @@ static ssize_t aac_show_kernel_version(struct device *device,
int len, tmp;

tmp = le32_to_cpu(dev->adapter_info.kernelrev);
- len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n",
- tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
- le32_to_cpu(dev->adapter_info.kernelbuild));
+ len = sysfs_emit(buf, "%d.%d-%d[%d]\n",
+ tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
+ le32_to_cpu(dev->adapter_info.kernelbuild));
return len;
}

@@ -1272,9 +1266,9 @@ static ssize_t aac_show_monitor_version(struct device *device,
int len, tmp;

tmp = le32_to_cpu(dev->adapter_info.monitorrev);
- len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n",
- tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
- le32_to_cpu(dev->adapter_info.monitorbuild));
+ len = sysfs_emit(buf, "%d.%d-%d[%d]\n",
+ tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
+ le32_to_cpu(dev->adapter_info.monitorbuild));
return len;
}

@@ -1286,9 +1280,9 @@ static ssize_t aac_show_bios_version(struct device *device,
int len, tmp;

tmp = le32_to_cpu(dev->adapter_info.biosrev);
- len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n",
- tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
- le32_to_cpu(dev->adapter_info.biosbuild));
+ len = sysfs_emit(buf, "%d.%d-%d[%d]\n",
+ tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
+ le32_to_cpu(dev->adapter_info.biosbuild));
return len;
}

@@ -1296,7 +1290,7 @@ static ssize_t aac_show_driver_version(struct device *device,
struct device_attribute *attr,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%s\n", aac_driver_version);
+ return sysfs_emit(buf, "%s\n", aac_driver_version);
}

static ssize_t aac_show_serial_number(struct device *device,
@@ -1322,15 +1316,13 @@ static ssize_t aac_show_serial_number(struct device *device,
static ssize_t aac_show_max_channel(struct device *device,
struct device_attribute *attr, char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n",
- class_to_shost(device)->max_channel);
+ return sysfs_emit(buf, "%d\n", class_to_shost(device)->max_channel);
}

static ssize_t aac_show_max_id(struct device *device,
struct device_attribute *attr, char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n",
- class_to_shost(device)->max_id);
+ return sysfs_emit(buf, "%d\n", class_to_shost(device)->max_id);
}

static ssize_t aac_store_reset_adapter(struct device *device,
@@ -1360,7 +1352,7 @@ static ssize_t aac_show_reset_adapter(struct device *device,
tmp = aac_adapter_check_health(dev);
if ((tmp == 0) && dev->in_reset)
tmp = -EBUSY;
- len = snprintf(buf, PAGE_SIZE, "0x%x\n", tmp);
+ len = sysfs_emit(buf, "0x%x\n", tmp);
return len;
}

--
2.29.2



2024-03-19 06:42:58

by Zhijian Li (Fujitsu)

[permalink] [raw]
Subject: [PATCH v2 18/25] scsi: pmcraid: Convert sprintf() family to sysfs_emit() family

Per filesystems/sysfs.rst, show() should only use sysfs_emit()
or sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

sprintf() and scnprintf() will be converted as well if they have.

Generally, this patch is generated by
make coccicheck M=<path/to/file> MODE=patch \
COCCI=scripts/coccinelle/api/device_attr_show.cocci

No functional change intended

CC: "James E.J. Bottomley" <[email protected]>
CC: "Martin K. Petersen" <[email protected]>
CC: [email protected]
Signed-off-by: Li Zhijian <[email protected]>
---
This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
Split them per subsystem so that the maintainer can review it easily
[1] https://lore.kernel.org/lkml/[email protected]/
---
drivers/scsi/pmcraid.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index e8bcc3a88732..56376d335b21 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -3538,7 +3538,7 @@ static ssize_t pmcraid_show_log_level(
struct Scsi_Host *shost = class_to_shost(dev);
struct pmcraid_instance *pinstance =
(struct pmcraid_instance *)shost->hostdata;
- return snprintf(buf, PAGE_SIZE, "%d\n", pinstance->current_log_level);
+ return sysfs_emit(buf, "%d\n", pinstance->current_log_level);
}

/**
@@ -3599,8 +3599,7 @@ static ssize_t pmcraid_show_drv_version(
char *buf
)
{
- return snprintf(buf, PAGE_SIZE, "version: %s\n",
- PMCRAID_DRIVER_VERSION);
+ return sysfs_emit(buf, "version: %s\n", PMCRAID_DRIVER_VERSION);
}

static struct device_attribute pmcraid_driver_version_attr = {
@@ -3632,9 +3631,8 @@ static ssize_t pmcraid_show_adapter_id(
u32 adapter_id = pci_dev_id(pinstance->pdev);
u32 aen_group = pmcraid_event_family.id;

- return snprintf(buf, PAGE_SIZE,
- "adapter id: %d\nminor: %d\naen group: %d\n",
- adapter_id, MINOR(pinstance->cdev.dev), aen_group);
+ return sysfs_emit(buf, "adapter id: %d\nminor: %d\naen group: %d\n",
+ adapter_id, MINOR(pinstance->cdev.dev), aen_group);
}

static struct device_attribute pmcraid_adapter_id_attr = {
--
2.29.2


2024-03-19 06:43:21

by Zhijian Li (Fujitsu)

[permalink] [raw]
Subject: [PATCH v2 10/25] scsi: qla4xxx: Convert sprintf() family to sysfs_emit() family

Per filesystems/sysfs.rst, show() should only use sysfs_emit()
or sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

sprintf() and scnprintf() will be converted as well if they have.

Generally, this patch is generated by
make coccicheck M=<path/to/file> MODE=patch \
COCCI=scripts/coccinelle/api/device_attr_show.cocci

No functional change intended

CC: Nilesh Javali <[email protected]>
CC: Manish Rangankar <[email protected]>
CC: [email protected]
CC: "James E.J. Bottomley" <[email protected]>
CC: "Martin K. Petersen" <[email protected]>
CC: [email protected]
Signed-off-by: Li Zhijian <[email protected]>
---
This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
Split them per subsystem so that the maintainer can review it easily
[1] https://lore.kernel.org/lkml/[email protected]/
---
drivers/scsi/qla4xxx/ql4_attr.c | 54 +++++++++++++++++----------------
1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/qla4xxx/ql4_attr.c b/drivers/scsi/qla4xxx/ql4_attr.c
index abfa6ef60480..f250f13506e7 100644
--- a/drivers/scsi/qla4xxx/ql4_attr.c
+++ b/drivers/scsi/qla4xxx/ql4_attr.c
@@ -156,13 +156,13 @@ qla4xxx_fw_version_show(struct device *dev,
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));

if (is_qla80XX(ha))
- return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
- ha->fw_info.fw_major, ha->fw_info.fw_minor,
- ha->fw_info.fw_patch, ha->fw_info.fw_build);
+ return sysfs_emit(buf, "%d.%02d.%02d (%x)\n",
+ ha->fw_info.fw_major, ha->fw_info.fw_minor,
+ ha->fw_info.fw_patch, ha->fw_info.fw_build);
else
- return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n",
- ha->fw_info.fw_major, ha->fw_info.fw_minor,
- ha->fw_info.fw_patch, ha->fw_info.fw_build);
+ return sysfs_emit(buf, "%d.%02d.%02d.%02d\n",
+ ha->fw_info.fw_major, ha->fw_info.fw_minor,
+ ha->fw_info.fw_patch, ha->fw_info.fw_build);
}

static ssize_t
@@ -170,7 +170,7 @@ qla4xxx_serial_num_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
- return snprintf(buf, PAGE_SIZE, "%s\n", ha->serial_number);
+ return sysfs_emit(buf, "%s\n", ha->serial_number);
}

static ssize_t
@@ -178,8 +178,8 @@ qla4xxx_iscsi_version_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
- return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fw_info.iscsi_major,
- ha->fw_info.iscsi_minor);
+ return sysfs_emit(buf, "%d.%02d\n", ha->fw_info.iscsi_major,
+ ha->fw_info.iscsi_minor);
}

static ssize_t
@@ -187,9 +187,11 @@ qla4xxx_optrom_version_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
- return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n",
- ha->fw_info.bootload_major, ha->fw_info.bootload_minor,
- ha->fw_info.bootload_patch, ha->fw_info.bootload_build);
+ return sysfs_emit(buf, "%d.%02d.%02d.%02d\n",
+ ha->fw_info.bootload_major,
+ ha->fw_info.bootload_minor,
+ ha->fw_info.bootload_patch,
+ ha->fw_info.bootload_build);
}

static ssize_t
@@ -197,7 +199,7 @@ qla4xxx_board_id_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
- return snprintf(buf, PAGE_SIZE, "0x%08X\n", ha->board_id);
+ return sysfs_emit(buf, "0x%08X\n", ha->board_id);
}

static ssize_t
@@ -207,8 +209,8 @@ qla4xxx_fw_state_show(struct device *dev, struct device_attribute *attr,
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));

qla4xxx_get_firmware_state(ha);
- return snprintf(buf, PAGE_SIZE, "0x%08X%8X\n", ha->firmware_state,
- ha->addl_fw_state);
+ return sysfs_emit(buf, "0x%08X%8X\n", ha->firmware_state,
+ ha->addl_fw_state);
}

static ssize_t
@@ -220,7 +222,7 @@ qla4xxx_phy_port_cnt_show(struct device *dev, struct device_attribute *attr,
if (is_qla40XX(ha))
return -ENOSYS;

- return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_cnt);
+ return sysfs_emit(buf, "0x%04X\n", ha->phy_port_cnt);
}

static ssize_t
@@ -232,7 +234,7 @@ qla4xxx_phy_port_num_show(struct device *dev, struct device_attribute *attr,
if (is_qla40XX(ha))
return -ENOSYS;

- return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_num);
+ return sysfs_emit(buf, "0x%04X\n", ha->phy_port_num);
}

static ssize_t
@@ -244,7 +246,7 @@ qla4xxx_iscsi_func_cnt_show(struct device *dev, struct device_attribute *attr,
if (is_qla40XX(ha))
return -ENOSYS;

- return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->iscsi_pci_func_cnt);
+ return sysfs_emit(buf, "0x%04X\n", ha->iscsi_pci_func_cnt);
}

static ssize_t
@@ -253,7 +255,7 @@ qla4xxx_hba_model_show(struct device *dev, struct device_attribute *attr,
{
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));

- return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_name);
+ return sysfs_emit(buf, "%s\n", ha->model_name);
}

static ssize_t
@@ -261,8 +263,8 @@ qla4xxx_fw_timestamp_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
- return snprintf(buf, PAGE_SIZE, "%s %s\n", ha->fw_info.fw_build_date,
- ha->fw_info.fw_build_time);
+ return sysfs_emit(buf, "%s %s\n", ha->fw_info.fw_build_date,
+ ha->fw_info.fw_build_time);
}

static ssize_t
@@ -270,7 +272,7 @@ qla4xxx_fw_build_user_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
- return snprintf(buf, PAGE_SIZE, "%s\n", ha->fw_info.fw_build_user);
+ return sysfs_emit(buf, "%s\n", ha->fw_info.fw_build_user);
}

static ssize_t
@@ -278,7 +280,7 @@ qla4xxx_fw_ext_timestamp_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
- return snprintf(buf, PAGE_SIZE, "%s\n", ha->fw_info.extended_timestamp);
+ return sysfs_emit(buf, "%s\n", ha->fw_info.extended_timestamp);
}

static ssize_t
@@ -300,7 +302,7 @@ qla4xxx_fw_load_src_show(struct device *dev, struct device_attribute *attr,
break;
}

- return snprintf(buf, PAGE_SIZE, "%s\n", load_src);
+ return sysfs_emit(buf, "%s\n", load_src);
}

static ssize_t
@@ -309,8 +311,8 @@ qla4xxx_fw_uptime_show(struct device *dev, struct device_attribute *attr,
{
struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
qla4xxx_about_firmware(ha);
- return snprintf(buf, PAGE_SIZE, "%u.%u secs\n", ha->fw_uptime_secs,
- ha->fw_uptime_msecs);
+ return sysfs_emit(buf, "%u.%u secs\n", ha->fw_uptime_secs,
+ ha->fw_uptime_msecs);
}

static DEVICE_ATTR(fw_version, S_IRUGO, qla4xxx_fw_version_show, NULL);
--
2.29.2


2024-03-19 06:44:34

by Zhijian Li (Fujitsu)

[permalink] [raw]
Subject: [PATCH v2 03/25] scsi: arcmsr: Convert sprintf() family to sysfs_emit() family

Per filesystems/sysfs.rst, show() should only use sysfs_emit()
or sysfs_emit_at() when formatting the value to be returned to user space.

coccinelle complains that there are still a couple of functions that use
snprintf(). Convert them to sysfs_emit().

sprintf() and scnprintf() will be converted as well if they have.

Generally, this patch is generated by
make coccicheck M=<path/to/file> MODE=patch \
COCCI=scripts/coccinelle/api/device_attr_show.cocci

No functional change intended

CC: "James E.J. Bottomley" <[email protected]>
CC: "Martin K. Petersen" <[email protected]>
CC: [email protected]
Signed-off-by: Li Zhijian <[email protected]>
---
This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
Split them per subsystem so that the maintainer can review it easily
[1] https://lore.kernel.org/lkml/[email protected]/
---
drivers/scsi/arcmsr/arcmsr_attr.c | 40 ++++++++-----------------------
1 file changed, 10 insertions(+), 30 deletions(-)

diff --git a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c
index baeb5e795690..3dfbe771e8b9 100644
--- a/drivers/scsi/arcmsr/arcmsr_attr.c
+++ b/drivers/scsi/arcmsr/arcmsr_attr.c
@@ -258,9 +258,7 @@ static ssize_t
arcmsr_attr_host_driver_version(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return snprintf(buf, PAGE_SIZE,
- "%s\n",
- ARCMSR_DRIVER_VERSION);
+ return sysfs_emit(buf, "%s\n", ARCMSR_DRIVER_VERSION);
}

static ssize_t
@@ -270,9 +268,7 @@ arcmsr_attr_host_driver_posted_cmd(struct device *dev,
struct Scsi_Host *host = class_to_shost(dev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- atomic_read(&acb->ccboutstandingcount));
+ return sysfs_emit(buf, "%4d\n", atomic_read(&acb->ccboutstandingcount));
}

static ssize_t
@@ -282,9 +278,7 @@ arcmsr_attr_host_driver_reset(struct device *dev,
struct Scsi_Host *host = class_to_shost(dev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->num_resets);
+ return sysfs_emit(buf, "%4d\n", acb->num_resets);
}

static ssize_t
@@ -294,9 +288,7 @@ arcmsr_attr_host_driver_abort(struct device *dev,
struct Scsi_Host *host = class_to_shost(dev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->num_aborts);
+ return sysfs_emit(buf, "%4d\n", acb->num_aborts);
}

static ssize_t
@@ -306,9 +298,7 @@ arcmsr_attr_host_fw_model(struct device *dev, struct device_attribute *attr,
struct Scsi_Host *host = class_to_shost(dev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;
- return snprintf(buf, PAGE_SIZE,
- "%s\n",
- acb->firm_model);
+ return sysfs_emit(buf, "%s\n", acb->firm_model);
}

static ssize_t
@@ -319,9 +309,7 @@ arcmsr_attr_host_fw_version(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;

- return snprintf(buf, PAGE_SIZE,
- "%s\n",
- acb->firm_version);
+ return sysfs_emit(buf, "%s\n", acb->firm_version);
}

static ssize_t
@@ -332,9 +320,7 @@ arcmsr_attr_host_fw_request_len(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;

- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->firm_request_len);
+ return sysfs_emit(buf, "%4d\n", acb->firm_request_len);
}

static ssize_t
@@ -345,9 +331,7 @@ arcmsr_attr_host_fw_numbers_queue(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;

- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->firm_numbers_queue);
+ return sysfs_emit(buf, "%4d\n", acb->firm_numbers_queue);
}

static ssize_t
@@ -358,9 +342,7 @@ arcmsr_attr_host_fw_sdram_size(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;

- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->firm_sdram_size);
+ return sysfs_emit(buf, "%4d\n", acb->firm_sdram_size);
}

static ssize_t
@@ -371,9 +353,7 @@ arcmsr_attr_host_fw_hd_channels(struct device *dev,
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *) host->hostdata;

- return snprintf(buf, PAGE_SIZE,
- "%4d\n",
- acb->firm_hd_channels);
+ return sysfs_emit(buf, "%4d\n", acb->firm_hd_channels);
}

static DEVICE_ATTR(host_driver_version, S_IRUGO, arcmsr_attr_host_driver_version, NULL);
--
2.29.2


2024-04-12 02:06:20

by Martin K. Petersen

[permalink] [raw]
Subject: Re: (subset) [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family

On Tue, 19 Mar 2024 14:31:08 +0800, Li Zhijian wrote:

> Per filesystems/sysfs.rst, show() should only use sysfs_emit()
> or sysfs_emit_at() when formatting the value to be returned to user space.
>
> coccinelle complains that there are still a couple of functions that use
> snprintf(). Convert them to sysfs_emit().
>
> sprintf() and scnprintf() will be converted as well if they have.
>
> [...]

Applied to 6.10/scsi-queue, thanks!

[12/25] scsi: snic: Convert sprintf() family to sysfs_emit() family
https://git.kernel.org/mkp/scsi/c/eab302e89f3d

--
Martin K. Petersen Oracle Linux Engineering