Linux-SCSI Archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family
@ 2024-03-19  6:31 Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 02/25] scsi: aic94xx: " Li Zhijian
                   ` (24 more replies)
  0 siblings, 25 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Adaptec OEM Raid Solutions, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi

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 <aacraid@microsemi.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/

Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
 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


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 02/25] scsi: aic94xx: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 03/25] scsi: arcmsr: " Li Zhijian
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/aic94xx/aic94xx_init.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index 8a3340d8d7ad..39d1617834de 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -264,8 +264,7 @@ static ssize_t asd_show_dev_rev(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
 	struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev);
-	return snprintf(buf, PAGE_SIZE, "%s\n",
-			asd_dev_rev[asd_ha->revision_id]);
+	return sysfs_emit(buf, "%s\n", asd_dev_rev[asd_ha->revision_id]);
 }
 static DEVICE_ATTR(aic_revision, S_IRUGO, asd_show_dev_rev, NULL);
 
@@ -273,7 +272,7 @@ static ssize_t asd_show_dev_bios_build(struct device *dev,
 				       struct device_attribute *attr,char *buf)
 {
 	struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev);
-	return snprintf(buf, PAGE_SIZE, "%d\n", asd_ha->hw_prof.bios.bld);
+	return sysfs_emit(buf, "%d\n", asd_ha->hw_prof.bios.bld);
 }
 static DEVICE_ATTR(bios_build, S_IRUGO, asd_show_dev_bios_build, NULL);
 
@@ -281,7 +280,7 @@ static ssize_t asd_show_dev_pcba_sn(struct device *dev,
 				    struct device_attribute *attr, char *buf)
 {
 	struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev);
-	return snprintf(buf, PAGE_SIZE, "%s\n", asd_ha->hw_prof.pcba_sn);
+	return sysfs_emit(buf, "%s\n", asd_ha->hw_prof.pcba_sn);
 }
 static DEVICE_ATTR(pcba_sn, S_IRUGO, asd_show_dev_pcba_sn, NULL);
 
@@ -452,9 +451,9 @@ static ssize_t asd_show_update_bios(struct device *dev,
 	if (asd_ha->bios_status != FLASH_IN_PROGRESS)
 		asd_ha->bios_status = FLASH_OK;
 
-	return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
-			flash_error_table[i].err_code,
-			flash_error_table[i].reason);
+	return sysfs_emit(buf, "status=%x %s\n",
+			  flash_error_table[i].err_code,
+			  flash_error_table[i].reason);
 }
 
 static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 03/25] scsi: arcmsr: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 02/25] scsi: aic94xx: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 04/25] scsi: be2iscsi: " Li Zhijian
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 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


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 04/25] scsi: be2iscsi: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 02/25] scsi: aic94xx: " Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 03/25] scsi: arcmsr: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 05/25] scsi: fcoe: Convert sprintf() family to sysfs_emit() family (part 1) Li Zhijian
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Ketan Mukadam, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi

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: Ketan Mukadam <ketan.mukadam@broadcom.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/be2iscsi/be_mgmt.c | 36 ++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/be2iscsi/be_mgmt.c b/drivers/scsi/be2iscsi/be_mgmt.c
index 4e899ec1477d..4174e71932a6 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.c
+++ b/drivers/scsi/be2iscsi/be_mgmt.c
@@ -1142,7 +1142,7 @@ ssize_t
 beiscsi_drvr_ver_disp(struct device *dev, struct device_attribute *attr,
 		       char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, BE_NAME "\n");
+	return sysfs_emit(buf, BE_NAME "\n");
 }
 
 /**
@@ -1161,7 +1161,7 @@ beiscsi_fw_ver_disp(struct device *dev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%s\n", phba->fw_ver_str);
+	return sysfs_emit(buf, "%s\n", phba->fw_ver_str);
 }
 
 /**
@@ -1185,12 +1185,11 @@ beiscsi_active_session_disp(struct device *dev, struct device_attribute *attr,
 		if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
 			avlbl_cids = BEISCSI_ULP_AVLBL_CID(phba, ulp_num);
 			total_cids = BEISCSI_GET_CID_COUNT(phba, ulp_num);
-			len += scnprintf(buf+len, PAGE_SIZE - len,
-					 "ULP%d : %d\n", ulp_num,
-					 (total_cids - avlbl_cids));
+			len += sysfs_emit_at(buf, len, "ULP%d : %d\n", ulp_num,
+					     (total_cids - avlbl_cids));
 		} else
-			len += scnprintf(buf+len, PAGE_SIZE - len,
-					 "ULP%d : %d\n", ulp_num, 0);
+			len += sysfs_emit_at(buf, len, "ULP%d : %d\n", ulp_num,
+					     0);
 	}
 
 	return len;
@@ -1215,12 +1214,11 @@ beiscsi_free_session_disp(struct device *dev, struct device_attribute *attr,
 
 	for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
 		if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported))
-			len += scnprintf(buf+len, PAGE_SIZE - len,
-					 "ULP%d : %d\n", ulp_num,
+			len += sysfs_emit_at(buf, len, "ULP%d : %d\n", ulp_num,
 					 BEISCSI_ULP_AVLBL_CID(phba, ulp_num));
 		else
-			len += scnprintf(buf+len, PAGE_SIZE - len,
-					 "ULP%d : %d\n", ulp_num, 0);
+			len += sysfs_emit_at(buf, len, "ULP%d : %d\n", ulp_num,
+					     0);
 	}
 
 	return len;
@@ -1248,16 +1246,16 @@ beiscsi_adap_family_disp(struct device *dev, struct device_attribute *attr,
 	case BE_DEVICE_ID1:
 	case OC_DEVICE_ID1:
 	case OC_DEVICE_ID2:
-		return snprintf(buf, PAGE_SIZE,
-				"Obsolete/Unsupported BE2 Adapter Family\n");
+		return sysfs_emit(buf,
+				  "Obsolete/Unsupported BE2 Adapter Family\n");
 	case BE_DEVICE_ID2:
 	case OC_DEVICE_ID3:
-		return snprintf(buf, PAGE_SIZE, "BE3-R Adapter Family\n");
+		return sysfs_emit(buf, "BE3-R Adapter Family\n");
 	case OC_SKH_ID1:
-		return snprintf(buf, PAGE_SIZE, "Skyhawk-R Adapter Family\n");
+		return sysfs_emit(buf, "Skyhawk-R Adapter Family\n");
 	default:
-		return snprintf(buf, PAGE_SIZE,
-				"Unknown Adapter Family: 0x%x\n", dev_id);
+		return sysfs_emit(buf, "Unknown Adapter Family: 0x%x\n",
+				  dev_id);
 	}
 }
 
@@ -1277,8 +1275,8 @@ beiscsi_phys_port_disp(struct device *dev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct beiscsi_hba *phba = iscsi_host_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "Port Identifier : %u\n",
-			phba->fw_config.phys_port);
+	return sysfs_emit(buf, "Port Identifier : %u\n",
+			  phba->fw_config.phys_port);
 }
 
 void beiscsi_offload_cxn_v0(struct beiscsi_offload_params *params,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 05/25] scsi: fcoe: Convert sprintf() family to sysfs_emit() family (part 1)
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (2 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 04/25] scsi: be2iscsi: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 06/25] scsi: fcoe: Convert sprintf() family to sysfs_emit() family (part 2) Li Zhijian
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Hannes Reinecke, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi

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: Hannes Reinecke <hare@suse.de>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/fcoe/fcoe_sysfs.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
index 453665ac6020..46a2f7f0669f 100644
--- a/drivers/scsi/fcoe/fcoe_sysfs.c
+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
@@ -228,7 +228,6 @@ static char *fcf_state_names[] = {
 	[ FCOE_FCF_STATE_CONNECTED ]    = "Connected",
 };
 fcoe_enum_name_search(fcf_state, fcf_state, fcf_state_names)
-#define FCOE_FCF_STATE_MAX_NAMELEN 50
 
 static ssize_t show_fcf_state(struct device *dev,
 			      struct device_attribute *attr,
@@ -239,7 +238,7 @@ static ssize_t show_fcf_state(struct device *dev,
 	name = get_fcoe_fcf_state_name(fcf->state);
 	if (!name)
 		return -EINVAL;
-	return snprintf(buf, FCOE_FCF_STATE_MAX_NAMELEN, "%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 static FCOE_DEVICE_ATTR(fcf, state, S_IRUGO, show_fcf_state, NULL);
 
@@ -254,8 +253,7 @@ static ssize_t show_ctlr_mode(struct device *dev,
 	name = get_fcoe_ctlr_mode_name(ctlr->mode);
 	if (!name)
 		return -EINVAL;
-	return snprintf(buf, FCOE_MAX_MODENAME_LEN,
-			"%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 
 static ssize_t store_ctlr_mode(struct device *dev,
@@ -345,7 +343,6 @@ static char *ctlr_enabled_state_names[] = {
 };
 fcoe_enum_name_search(ctlr_enabled_state, ctlr_enabled_state,
 		      ctlr_enabled_state_names)
-#define FCOE_CTLR_ENABLED_MAX_NAMELEN 50
 
 static ssize_t show_ctlr_enabled_state(struct device *dev,
 				       struct device_attribute *attr,
@@ -357,8 +354,7 @@ static ssize_t show_ctlr_enabled_state(struct device *dev,
 	name = get_fcoe_ctlr_enabled_state_name(ctlr->enabled);
 	if (!name)
 		return -EINVAL;
-	return snprintf(buf, FCOE_CTLR_ENABLED_MAX_NAMELEN,
-			"%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 
 static FCOE_DEVICE_ATTR(ctlr, enabled, S_IRUGO | S_IWUSR,
@@ -396,7 +392,7 @@ static ssize_t show_ctlr_fip_resp(struct device *dev,
 	struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
 	struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr);
 
-	return sprintf(buf, "%d\n", fip->fip_resp ? 1 : 0);
+	return sysfs_emit(buf, "%d\n", fip->fip_resp ? 1 : 0);
 }
 
 static FCOE_DEVICE_ATTR(ctlr, fip_vlan_responder, S_IRUGO | S_IWUSR,
@@ -439,7 +435,7 @@ static ssize_t show_ctlr_r_a_tov(struct device *dev,
 	struct fcoe_ctlr_device *ctlr_dev = dev_to_ctlr(dev);
 	struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
 
-	return sprintf(buf, "%d\n", ctlr->lp->r_a_tov);
+	return sysfs_emit(buf, "%d\n", ctlr->lp->r_a_tov);
 }
 
 static FCOE_DEVICE_ATTR(ctlr, r_a_tov, S_IRUGO | S_IWUSR,
@@ -466,7 +462,7 @@ static ssize_t show_ctlr_e_d_tov(struct device *dev,
 	struct fcoe_ctlr_device *ctlr_dev = dev_to_ctlr(dev);
 	struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
 
-	return sprintf(buf, "%d\n", ctlr->lp->e_d_tov);
+	return sysfs_emit(buf, "%d\n", ctlr->lp->e_d_tov);
 }
 
 static FCOE_DEVICE_ATTR(ctlr, e_d_tov, S_IRUGO | S_IWUSR,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 06/25] scsi: fcoe: Convert sprintf() family to sysfs_emit() family (part 2)
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (3 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 05/25] scsi: fcoe: Convert sprintf() family to sysfs_emit() family (part 1) Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 07/25] scsi: megaraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

This focuses on abused cases in macros

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/fcoe/fcoe_sysfs.c | 82 +++++++++++++++++-----------------
 1 file changed, 41 insertions(+), 41 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
index 46a2f7f0669f..2baa1d6456fc 100644
--- a/drivers/scsi/fcoe/fcoe_sysfs.c
+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
@@ -134,7 +134,7 @@ static int fcoe_fcf_set_dev_loss_tmo(struct fcoe_fcf_device *fcf,
 struct device_attribute device_attr_fcoe_##_prefix##_##_name =	\
 	__ATTR(_name, _mode, _show, _store)
 
-#define fcoe_ctlr_show_function(field, format_string, sz, cast)	\
+#define fcoe_ctlr_show_function(field, format_string, cast)	\
 static ssize_t show_fcoe_ctlr_device_##field(struct device *dev, \
 					    struct device_attribute *attr, \
 					    char *buf)			\
@@ -142,11 +142,11 @@ static ssize_t show_fcoe_ctlr_device_##field(struct device *dev, \
 	struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);		\
 	if (ctlr->f->get_fcoe_ctlr_##field)				\
 		ctlr->f->get_fcoe_ctlr_##field(ctlr);			\
-	return snprintf(buf, sz, format_string,				\
-			cast fcoe_ctlr_##field(ctlr));			\
+	return sysfs_emit(buf, format_string,				\
+			  cast fcoe_ctlr_##field(ctlr));		\
 }
 
-#define fcoe_fcf_show_function(field, format_string, sz, cast)	\
+#define fcoe_fcf_show_function(field, format_string, cast)	\
 static ssize_t show_fcoe_fcf_device_##field(struct device *dev,	\
 					   struct device_attribute *attr, \
 					   char *buf)			\
@@ -155,55 +155,55 @@ static ssize_t show_fcoe_fcf_device_##field(struct device *dev,	\
 	struct fcoe_ctlr_device *ctlr = fcoe_fcf_dev_to_ctlr_dev(fcf);	\
 	if (ctlr->f->get_fcoe_fcf_##field)				\
 		ctlr->f->get_fcoe_fcf_##field(fcf);			\
-	return snprintf(buf, sz, format_string,				\
-			cast fcoe_fcf_##field(fcf));			\
+	return sysfs_emit(buf, format_string,				\
+			  cast fcoe_fcf_##field(fcf));			\
 }
 
-#define fcoe_ctlr_private_show_function(field, format_string, sz, cast)	\
+#define fcoe_ctlr_private_show_function(field, format_string, cast)	\
 static ssize_t show_fcoe_ctlr_device_##field(struct device *dev, \
 					    struct device_attribute *attr, \
 					    char *buf)			\
 {									\
 	struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);		\
-	return snprintf(buf, sz, format_string, cast fcoe_ctlr_##field(ctlr)); \
+	return sysfs_emit(buf, format_string, cast fcoe_ctlr_##field(ctlr)); \
 }
 
-#define fcoe_fcf_private_show_function(field, format_string, sz, cast)	\
+#define fcoe_fcf_private_show_function(field, format_string, cast)	\
 static ssize_t show_fcoe_fcf_device_##field(struct device *dev,	\
 					   struct device_attribute *attr, \
 					   char *buf)			\
 {								\
 	struct fcoe_fcf_device *fcf = dev_to_fcf(dev);			\
-	return snprintf(buf, sz, format_string, cast fcoe_fcf_##field(fcf)); \
+	return sysfs_emit(buf, format_string, cast fcoe_fcf_##field(fcf)); \
 }
 
-#define fcoe_ctlr_private_rd_attr(field, format_string, sz)		\
-	fcoe_ctlr_private_show_function(field, format_string, sz, )	\
+#define fcoe_ctlr_private_rd_attr(field, format_string)		\
+	fcoe_ctlr_private_show_function(field, format_string, )	\
 	static FCOE_DEVICE_ATTR(ctlr, field, S_IRUGO,			\
 				show_fcoe_ctlr_device_##field, NULL)
 
-#define fcoe_ctlr_rd_attr(field, format_string, sz)			\
-	fcoe_ctlr_show_function(field, format_string, sz, )		\
+#define fcoe_ctlr_rd_attr(field, format_string)			\
+	fcoe_ctlr_show_function(field, format_string, )		\
 	static FCOE_DEVICE_ATTR(ctlr, field, S_IRUGO,			\
 				show_fcoe_ctlr_device_##field, NULL)
 
-#define fcoe_fcf_rd_attr(field, format_string, sz)			\
-	fcoe_fcf_show_function(field, format_string, sz, )		\
+#define fcoe_fcf_rd_attr(field, format_string)			\
+	fcoe_fcf_show_function(field, format_string, )		\
 	static FCOE_DEVICE_ATTR(fcf, field, S_IRUGO,			\
 				show_fcoe_fcf_device_##field, NULL)
 
-#define fcoe_fcf_private_rd_attr(field, format_string, sz)		\
-	fcoe_fcf_private_show_function(field, format_string, sz, )	\
+#define fcoe_fcf_private_rd_attr(field, format_string)		\
+	fcoe_fcf_private_show_function(field, format_string, )	\
 	static FCOE_DEVICE_ATTR(fcf, field, S_IRUGO,			\
 				show_fcoe_fcf_device_##field, NULL)
 
-#define fcoe_ctlr_private_rd_attr_cast(field, format_string, sz, cast)	\
-	fcoe_ctlr_private_show_function(field, format_string, sz, (cast)) \
+#define fcoe_ctlr_private_rd_attr_cast(field, format_string, cast)	\
+	fcoe_ctlr_private_show_function(field, format_string, (cast)) \
 	static FCOE_DEVICE_ATTR(ctlr, field, S_IRUGO,			\
 				show_fcoe_ctlr_device_##field, NULL)
 
-#define fcoe_fcf_private_rd_attr_cast(field, format_string, sz, cast)	\
-	fcoe_fcf_private_show_function(field, format_string, sz, (cast)) \
+#define fcoe_fcf_private_rd_attr_cast(field, format_string, cast)	\
+	fcoe_fcf_private_show_function(field, format_string, (cast)) \
 	static FCOE_DEVICE_ATTR(fcf, field, S_IRUGO,			\
 				show_fcoe_fcf_device_##field, NULL)
 
@@ -489,30 +489,30 @@ store_private_fcoe_ctlr_fcf_dev_loss_tmo(struct device *dev,
 	mutex_unlock(&ctlr->lock);
 	return count;
 }
-fcoe_ctlr_private_show_function(fcf_dev_loss_tmo, "%d\n", 20, );
+fcoe_ctlr_private_show_function(fcf_dev_loss_tmo, "%d\n", );
 static FCOE_DEVICE_ATTR(ctlr, fcf_dev_loss_tmo, S_IRUGO | S_IWUSR,
 			show_fcoe_ctlr_device_fcf_dev_loss_tmo,
 			store_private_fcoe_ctlr_fcf_dev_loss_tmo);
 
 /* Link Error Status Block (LESB) */
-fcoe_ctlr_rd_attr(link_fail, "%u\n", 20);
-fcoe_ctlr_rd_attr(vlink_fail, "%u\n", 20);
-fcoe_ctlr_rd_attr(miss_fka, "%u\n", 20);
-fcoe_ctlr_rd_attr(symb_err, "%u\n", 20);
-fcoe_ctlr_rd_attr(err_block, "%u\n", 20);
-fcoe_ctlr_rd_attr(fcs_error, "%u\n", 20);
-
-fcoe_fcf_private_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
-fcoe_fcf_private_rd_attr_cast(switch_name, "0x%llx\n", 20, unsigned long long);
-fcoe_fcf_private_rd_attr(priority, "%u\n", 20);
-fcoe_fcf_private_rd_attr(fc_map, "0x%x\n", 20);
-fcoe_fcf_private_rd_attr(vfid, "%u\n", 20);
-fcoe_fcf_private_rd_attr(mac, "%pM\n", 20);
-fcoe_fcf_private_rd_attr(fka_period, "%u\n", 20);
-fcoe_fcf_rd_attr(selected, "%u\n", 20);
-fcoe_fcf_rd_attr(vlan_id, "%u\n", 20);
-
-fcoe_fcf_private_show_function(dev_loss_tmo, "%d\n", 20, )
+fcoe_ctlr_rd_attr(link_fail, "%u\n");
+fcoe_ctlr_rd_attr(vlink_fail, "%u\n");
+fcoe_ctlr_rd_attr(miss_fka, "%u\n");
+fcoe_ctlr_rd_attr(symb_err, "%u\n");
+fcoe_ctlr_rd_attr(err_block, "%u\n");
+fcoe_ctlr_rd_attr(fcs_error, "%u\n");
+
+fcoe_fcf_private_rd_attr_cast(fabric_name, "0x%llx\n", unsigned long long);
+fcoe_fcf_private_rd_attr_cast(switch_name, "0x%llx\n", unsigned long long);
+fcoe_fcf_private_rd_attr(priority, "%u\n");
+fcoe_fcf_private_rd_attr(fc_map, "0x%x\n");
+fcoe_fcf_private_rd_attr(vfid, "%u\n");
+fcoe_fcf_private_rd_attr(mac, "%pM\n");
+fcoe_fcf_private_rd_attr(fka_period, "%u\n");
+fcoe_fcf_rd_attr(selected, "%u\n");
+fcoe_fcf_rd_attr(vlan_id, "%u\n");
+
+fcoe_fcf_private_show_function(dev_loss_tmo, "%d\n", )
 static ssize_t
 store_fcoe_fcf_dev_loss_tmo(struct device *dev, struct device_attribute *attr,
 			    const char *buf, size_t count)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 07/25] scsi: megaraid: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (4 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 06/25] scsi: fcoe: Convert sprintf() family to sysfs_emit() family (part 2) Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 08/25] scsi: mpt3sas: " Li Zhijian
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Kashyap Desai, Sumit Saxena, Shivasharan S,
	Chandrakanth patil, James E.J. Bottomley, Martin K. Petersen,
	megaraidlinux.pdl, linux-scsi

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: Kashyap Desai <kashyap.desai@broadcom.com>
CC: Sumit Saxena <sumit.saxena@broadcom.com>
CC: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
CC: Chandrakanth patil <chandrakanth.patil@broadcom.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: megaraidlinux.pdl@broadcom.com
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 3d4f13da1ae8..07df615f43af 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -3333,8 +3333,8 @@ fw_crash_buffer_size_show(struct device *cdev,
 	struct megasas_instance *instance =
 		(struct megasas_instance *) shost->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)
-		((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE);
+	return sysfs_emit(buf, "%ld\n", (unsigned long)
+		((instance->fw_crash_buffer_size) * 1024 * 1024) / PAGE_SIZE);
 }
 
 static ssize_t
@@ -3379,14 +3379,14 @@ fw_crash_state_show(struct device *cdev,
 	struct megasas_instance *instance =
 		(struct megasas_instance *) shost->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state);
+	return sysfs_emit(buf, "%d\n", instance->fw_crash_state);
 }
 
 static ssize_t
 page_size_show(struct device *cdev,
 	struct device_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1);
+	return sysfs_emit(buf, "%ld\n", (unsigned long)PAGE_SIZE - 1);
 }
 
 static ssize_t
@@ -3396,7 +3396,8 @@ ldio_outstanding_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->ldio_outstanding));
+	return sysfs_emit(buf, "%d\n",
+			  atomic_read(&instance->ldio_outstanding));
 }
 
 static ssize_t
@@ -3406,7 +3407,7 @@ fw_cmds_outstanding_show(struct device *cdev,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->fw_outstanding));
+	return sysfs_emit(buf, "%d\n", atomic_read(&instance->fw_outstanding));
 }
 
 static ssize_t
@@ -3416,7 +3417,7 @@ enable_sdev_max_qd_show(struct device *cdev,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", instance->enable_sdev_max_qd);
+	return sysfs_emit(buf, "%d\n", instance->enable_sdev_max_qd);
 }
 
 static ssize_t
@@ -3470,8 +3471,7 @@ raid_map_id_show(struct device *cdev, struct device_attribute *attr,
 	struct megasas_instance *instance =
 			(struct megasas_instance *)shost->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "%ld\n",
-			(unsigned long)instance->map_id);
+	return sysfs_emit(buf, "%ld\n", (unsigned long)instance->map_id);
 }
 
 static DEVICE_ATTR_RW(fw_crash_buffer);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 08/25] scsi: mpt3sas: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (5 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 07/25] scsi: megaraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 09/25] scsi: pcmcia: " Li Zhijian
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Sathya Prakash, Sreekanth Reddy,
	Suganath Prabu Subramani, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi, MPT-FusionLinux.pdl

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: Sathya Prakash <sathya.prakash@broadcom.com>
CC: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
CC: Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
CC: MPT-FusionLinux.pdl@broadcom.com
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/mpt3sas/mpt3sas_ctl.c | 85 +++++++++++++++---------------
 1 file changed, 43 insertions(+), 42 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index 1c9fd26195b8..4ac3b13f7025 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -2876,11 +2876,11 @@ version_fw_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
-	    (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
-	    (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
-	    (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
-	    ioc->facts.FWVersion.Word & 0x000000FF);
+	return sysfs_emit(buf, "%02d.%02d.%02d.%02d\n",
+			  (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
+			  (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
+			  (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
+			  ioc->facts.FWVersion.Word & 0x000000FF);
 }
 static DEVICE_ATTR_RO(version_fw);
 
@@ -2901,11 +2901,11 @@ version_bios_show(struct device *cdev, struct device_attribute *attr,
 
 	u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
 
-	return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
-	    (version & 0xFF000000) >> 24,
-	    (version & 0x00FF0000) >> 16,
-	    (version & 0x0000FF00) >> 8,
-	    version & 0x000000FF);
+	return sysfs_emit(buf, "%02d.%02d.%02d.%02d\n",
+			  (version & 0xFF000000) >> 24,
+			  (version & 0x00FF0000) >> 16,
+			  (version & 0x0000FF00) >> 8,
+			  version & 0x000000FF);
 }
 static DEVICE_ATTR_RO(version_bios);
 
@@ -2924,8 +2924,9 @@ version_mpi_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%03x.%02x\n",
-	    ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8);
+	return sysfs_emit(buf, "%03x.%02x\n",
+			  ioc->facts.MsgVersion,
+			  ioc->facts.HeaderVersion >> 8);
 }
 static DEVICE_ATTR_RO(version_mpi);
 
@@ -2944,7 +2945,7 @@ version_product_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName);
+	return sysfs_emit(buf, "%s\n", ioc->manu_pg0.ChipName);
 }
 static DEVICE_ATTR_RO(version_product);
 
@@ -2963,8 +2964,8 @@ version_nvdata_persistent_show(struct device *cdev,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%08xh\n",
-	    le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
+	return sysfs_emit(buf, "%08xh\n",
+		le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
 }
 static DEVICE_ATTR_RO(version_nvdata_persistent);
 
@@ -2983,8 +2984,8 @@ version_nvdata_default_show(struct device *cdev, struct device_attribute
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%08xh\n",
-	    le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
+	return sysfs_emit(buf, "%08xh\n",
+		le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
 }
 static DEVICE_ATTR_RO(version_nvdata_default);
 
@@ -3003,7 +3004,7 @@ board_name_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName);
+	return sysfs_emit(buf, "%s\n", ioc->manu_pg0.BoardName);
 }
 static DEVICE_ATTR_RO(board_name);
 
@@ -3022,7 +3023,7 @@ board_assembly_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly);
+	return sysfs_emit(buf, "%s\n", ioc->manu_pg0.BoardAssembly);
 }
 static DEVICE_ATTR_RO(board_assembly);
 
@@ -3041,7 +3042,7 @@ board_tracer_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber);
+	return sysfs_emit(buf, "%s\n", ioc->manu_pg0.BoardTracerNumber);
 }
 static DEVICE_ATTR_RO(board_tracer);
 
@@ -3063,7 +3064,7 @@ io_delay_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
+	return sysfs_emit(buf, "%02d\n", ioc->io_missing_delay);
 }
 static DEVICE_ATTR_RO(io_delay);
 
@@ -3085,7 +3086,7 @@ device_delay_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
+	return sysfs_emit(buf, "%02d\n", ioc->device_missing_delay);
 }
 static DEVICE_ATTR_RO(device_delay);
 
@@ -3106,7 +3107,7 @@ fw_queue_depth_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit);
+	return sysfs_emit(buf, "%02d\n", ioc->facts.RequestCredit);
 }
 static DEVICE_ATTR_RO(fw_queue_depth);
 
@@ -3128,8 +3129,8 @@ host_sas_address_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
-	    (unsigned long long)ioc->sas_hba.sas_address);
+	return sysfs_emit(buf, "0x%016llx\n",
+			  (unsigned long long)ioc->sas_hba.sas_address);
 }
 static DEVICE_ATTR_RO(host_sas_address);
 
@@ -3148,7 +3149,7 @@ logging_level_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level);
+	return sysfs_emit(buf, "%08xh\n", ioc->logging_level);
 }
 static ssize_t
 logging_level_store(struct device *cdev, struct device_attribute *attr,
@@ -3184,7 +3185,7 @@ fwfault_debug_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug);
+	return sysfs_emit(buf, "%d\n", ioc->fwfault_debug);
 }
 static ssize_t
 fwfault_debug_store(struct device *cdev, struct device_attribute *attr,
@@ -3221,7 +3222,7 @@ ioc_reset_count_show(struct device *cdev, struct device_attribute *attr,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", ioc->ioc_reset_count);
+	return sysfs_emit(buf, "%d\n", ioc->ioc_reset_count);
 }
 static DEVICE_ATTR_RO(ioc_reset_count);
 
@@ -3249,7 +3250,7 @@ reply_queue_count_show(struct device *cdev,
 	else
 		reply_queue_count = 1;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", reply_queue_count);
+	return sysfs_emit(buf, "%d\n", reply_queue_count);
 }
 static DEVICE_ATTR_RO(reply_queue_count);
 
@@ -3314,7 +3315,7 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr,
 
 	/* BRM status is in bit zero of GPIOVal[24] */
 	backup_rail_monitor_status = le16_to_cpu(io_unit_pg3.GPIOVal[24]);
-	rc = snprintf(buf, PAGE_SIZE, "%d\n", (backup_rail_monitor_status & 1));
+	rc = sysfs_emit(buf, "%d\n", (backup_rail_monitor_status & 1));
 
  out:
 	mutex_unlock(&ioc->pci_access_mutex);
@@ -3371,7 +3372,7 @@ host_trace_buffer_size_show(struct device *cdev,
 		size = le32_to_cpu(request_data->Size);
 
 	ioc->ring_buffer_sz = size;
-	return snprintf(buf, PAGE_SIZE, "%d\n", size);
+	return sysfs_emit(buf, "%d\n", size);
 }
 static DEVICE_ATTR_RO(host_trace_buffer_size);
 
@@ -3458,12 +3459,12 @@ host_trace_buffer_enable_show(struct device *cdev,
 	if ((!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) ||
 	   ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
 	    MPT3_DIAG_BUFFER_IS_REGISTERED) == 0))
-		return snprintf(buf, PAGE_SIZE, "off\n");
+		return sysfs_emit(buf, "off\n");
 	else if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
 	    MPT3_DIAG_BUFFER_IS_RELEASED))
-		return snprintf(buf, PAGE_SIZE, "release\n");
+		return sysfs_emit(buf, "release\n");
 	else
-		return snprintf(buf, PAGE_SIZE, "post\n");
+		return sysfs_emit(buf, "post\n");
 }
 
 static ssize_t
@@ -3879,7 +3880,7 @@ drv_support_bitmap_show(struct device *cdev,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "0x%08x\n", ioc->drv_support_bitmap);
+	return sysfs_emit(buf, "0x%08x\n", ioc->drv_support_bitmap);
 }
 static DEVICE_ATTR_RO(drv_support_bitmap);
 
@@ -3899,7 +3900,7 @@ enable_sdev_max_qd_show(struct device *cdev,
 	struct Scsi_Host *shost = class_to_shost(cdev);
 	struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", ioc->enable_sdev_max_qd);
+	return sysfs_emit(buf, "%d\n", ioc->enable_sdev_max_qd);
 }
 
 /**
@@ -4047,8 +4048,8 @@ sas_address_show(struct device *dev, struct device_attribute *attr,
 	struct scsi_device *sdev = to_scsi_device(dev);
 	struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
-	    (unsigned long long)sas_device_priv_data->sas_target->sas_address);
+	return sysfs_emit(buf, "0x%016llx\n", (unsigned long long)
+			  sas_device_priv_data->sas_target->sas_address);
 }
 static DEVICE_ATTR_RO(sas_address);
 
@@ -4069,8 +4070,8 @@ sas_device_handle_show(struct device *dev, struct device_attribute *attr,
 	struct scsi_device *sdev = to_scsi_device(dev);
 	struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "0x%04x\n",
-	    sas_device_priv_data->sas_target->handle);
+	return sysfs_emit(buf, "0x%04x\n",
+			  sas_device_priv_data->sas_target->handle);
 }
 static DEVICE_ATTR_RO(sas_device_handle);
 
@@ -4107,8 +4108,8 @@ sas_ncq_prio_enable_show(struct device *dev,
 	struct scsi_device *sdev = to_scsi_device(dev);
 	struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
-			sas_device_priv_data->ncq_prio_enable);
+	return sysfs_emit(buf, "%d\n",
+			  sas_device_priv_data->ncq_prio_enable);
 }
 
 static ssize_t
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 09/25] scsi: pcmcia: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (6 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 08/25] scsi: mpt3sas: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 10/25] scsi: qla4xxx: " Li Zhijian
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/pcmcia/sym53c500_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 278c78d066c4..264eeb24b811 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -624,7 +624,7 @@ SYM53C500_show_pio(struct device *dev, struct device_attribute *attr,
 	struct sym53c500_data *data =
 	    (struct sym53c500_data *)SHp->hostdata;
 
-	return snprintf(buf, 4, "%d\n", data->fast_pio);
+	return sysfs_emit(buf, "%d\n", data->fast_pio);
 }
 
 static ssize_t
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 10/25] scsi: qla4xxx: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (7 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 09/25] scsi: pcmcia: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 11/25] scsi: smartpqi: " Li Zhijian
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Nilesh Javali, Manish Rangankar,
	GR-QLogic-Storage-Upstream, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi

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 <njavali@marvell.com>
CC: Manish Rangankar <mrangankar@marvell.com>
CC: GR-QLogic-Storage-Upstream@marvell.com
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 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


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 11/25] scsi: smartpqi: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (8 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 10/25] scsi: qla4xxx: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 12/25] scsi: snic: " Li Zhijian
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Don Brace, James E.J. Bottomley, Martin K. Petersen,
	storagedev, linux-scsi

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: Don Brace <don.brace@microchip.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: storagedev@microchip.com
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/smartpqi/smartpqi_init.c | 86 +++++++++++++--------------
 1 file changed, 41 insertions(+), 45 deletions(-)

diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 385180c98be4..b4ad519f049e 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -6889,13 +6889,13 @@ static ssize_t pqi_firmware_version_show(struct device *dev,
 	shost = class_to_shost(dev);
 	ctrl_info = shost_to_hba(shost);
 
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", ctrl_info->firmware_version);
+	return sysfs_emit(buffer, "%s\n", ctrl_info->firmware_version);
 }
 
 static ssize_t pqi_driver_version_show(struct device *dev,
 	struct device_attribute *attr, char *buffer)
 {
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", DRIVER_VERSION BUILD_TIMESTAMP);
+	return sysfs_emit(buffer, "%s\n", DRIVER_VERSION BUILD_TIMESTAMP);
 }
 
 static ssize_t pqi_serial_number_show(struct device *dev,
@@ -6907,7 +6907,7 @@ static ssize_t pqi_serial_number_show(struct device *dev,
 	shost = class_to_shost(dev);
 	ctrl_info = shost_to_hba(shost);
 
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", ctrl_info->serial_number);
+	return sysfs_emit(buffer, "%s\n", ctrl_info->serial_number);
 }
 
 static ssize_t pqi_model_show(struct device *dev,
@@ -6919,7 +6919,7 @@ static ssize_t pqi_model_show(struct device *dev,
 	shost = class_to_shost(dev);
 	ctrl_info = shost_to_hba(shost);
 
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", ctrl_info->model);
+	return sysfs_emit(buffer, "%s\n", ctrl_info->model);
 }
 
 static ssize_t pqi_vendor_show(struct device *dev,
@@ -6931,7 +6931,7 @@ static ssize_t pqi_vendor_show(struct device *dev,
 	shost = class_to_shost(dev);
 	ctrl_info = shost_to_hba(shost);
 
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", ctrl_info->vendor);
+	return sysfs_emit(buffer, "%s\n", ctrl_info->vendor);
 }
 
 static ssize_t pqi_host_rescan_store(struct device *dev,
@@ -6952,14 +6952,14 @@ static ssize_t pqi_lockup_action_show(struct device *dev,
 
 	for (i = 0; i < ARRAY_SIZE(pqi_lockup_actions); i++) {
 		if (pqi_lockup_actions[i].action == pqi_lockup_action)
-			count += scnprintf(buffer + count, PAGE_SIZE - count,
+			count += sysfs_emit_at(buffer, count,
 				"[%s] ", pqi_lockup_actions[i].name);
 		else
-			count += scnprintf(buffer + count, PAGE_SIZE - count,
+			count += sysfs_emit_at(buffer, count,
 				"%s ", pqi_lockup_actions[i].name);
 	}
 
-	count += scnprintf(buffer + count, PAGE_SIZE - count, "\n");
+	count += sysfs_emit_at(buffer, count, "\n");
 
 	return count;
 }
@@ -6990,8 +6990,8 @@ static ssize_t pqi_host_enable_stream_detection_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct pqi_ctrl_info *ctrl_info = shost_to_hba(shost);
 
-	return scnprintf(buffer, 10, "%x\n",
-			ctrl_info->enable_stream_detection);
+	return sysfs_emit(buffer, "%x\n",
+			  ctrl_info->enable_stream_detection);
 }
 
 static ssize_t pqi_host_enable_stream_detection_store(struct device *dev,
@@ -7018,7 +7018,7 @@ static ssize_t pqi_host_enable_r5_writes_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct pqi_ctrl_info *ctrl_info = shost_to_hba(shost);
 
-	return scnprintf(buffer, 10, "%x\n", ctrl_info->enable_r5_writes);
+	return sysfs_emit(buffer, "%x\n", ctrl_info->enable_r5_writes);
 }
 
 static ssize_t pqi_host_enable_r5_writes_store(struct device *dev,
@@ -7045,7 +7045,7 @@ static ssize_t pqi_host_enable_r6_writes_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct pqi_ctrl_info *ctrl_info = shost_to_hba(shost);
 
-	return scnprintf(buffer, 10, "%x\n", ctrl_info->enable_r6_writes);
+	return sysfs_emit(buffer, "%x\n", ctrl_info->enable_r6_writes);
 }
 
 static ssize_t pqi_host_enable_r6_writes_store(struct device *dev,
@@ -7128,13 +7128,16 @@ static ssize_t pqi_unique_id_show(struct device *dev,
 
 	spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
 
-	return scnprintf(buffer, PAGE_SIZE,
-		"%02X%02X%02X%02X%02X%02X%02X%02X"
-		"%02X%02X%02X%02X%02X%02X%02X%02X\n",
-		unique_id[0], unique_id[1], unique_id[2], unique_id[3],
-		unique_id[4], unique_id[5], unique_id[6], unique_id[7],
-		unique_id[8], unique_id[9], unique_id[10], unique_id[11],
-		unique_id[12], unique_id[13], unique_id[14], unique_id[15]);
+	return sysfs_emit(buffer, "%02X%02X%02X%02X%02X%02X%02X%02X"
+			  "%02X%02X%02X%02X%02X%02X%02X%02X\n",
+			  unique_id[0], unique_id[1], unique_id[2],
+			  unique_id[3],
+			  unique_id[4], unique_id[5], unique_id[6],
+			  unique_id[7],
+			  unique_id[8], unique_id[9], unique_id[10],
+			  unique_id[11],
+			  unique_id[12], unique_id[13], unique_id[14],
+			  unique_id[15]);
 }
 
 static ssize_t pqi_lunid_show(struct device *dev,
@@ -7164,7 +7167,7 @@ static ssize_t pqi_lunid_show(struct device *dev,
 
 	spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
 
-	return scnprintf(buffer, PAGE_SIZE, "0x%8phN\n", lunid);
+	return sysfs_emit(buffer, "0x%8phN\n", lunid);
 }
 
 #define MAX_PATHS	8
@@ -7208,13 +7211,12 @@ static ssize_t pqi_path_info_show(struct device *dev,
 		else
 			continue;
 
-		output_len += scnprintf(buf + output_len,
-					PAGE_SIZE - output_len,
-					"[%d:%d:%d:%d] %20.20s ",
-					ctrl_info->scsi_host->host_no,
-					device->bus, device->target,
-					device->lun,
-					scsi_device_type(device->devtype));
+		output_len += sysfs_emit_at(buf, output_len,
+					    "[%d:%d:%d:%d] %20.20s ",
+					    ctrl_info->scsi_host->host_no,
+					    device->bus, device->target,
+					    device->lun,
+					    scsi_device_type(device->devtype));
 
 		if (device->devtype == TYPE_RAID ||
 			pqi_is_logical_device(device))
@@ -7227,27 +7229,22 @@ static ssize_t pqi_path_info_show(struct device *dev,
 		if (phys_connector[1] < '0')
 			phys_connector[1] = '0';
 
-		output_len += scnprintf(buf + output_len,
-					PAGE_SIZE - output_len,
-					"PORT: %.2s ", phys_connector);
+		output_len += sysfs_emit_at(buf, output_len,
+					    "PORT: %.2s ", phys_connector);
 
 		box = device->box[i];
 		if (box != 0 && box != 0xFF)
-			output_len += scnprintf(buf + output_len,
-						PAGE_SIZE - output_len,
-						"BOX: %hhu ", box);
+			output_len += sysfs_emit_at(buf, output_len,
+						    "BOX: %hhu ", box);
 
 		if ((device->devtype == TYPE_DISK ||
 			device->devtype == TYPE_ZBC) &&
 			pqi_expose_device(device))
-			output_len += scnprintf(buf + output_len,
-						PAGE_SIZE - output_len,
-						"BAY: %hhu ", bay);
+			output_len += sysfs_emit_at(buf, output_len,
+						    "BAY: %hhu ", bay);
 
 end_buffer:
-		output_len += scnprintf(buf + output_len,
-					PAGE_SIZE - output_len,
-					"%s\n", active);
+		output_len += sysfs_emit_at(buf, output_len, "%s\n", active);
 	}
 
 	spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
@@ -7282,7 +7279,7 @@ static ssize_t pqi_sas_address_show(struct device *dev,
 
 	spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
 
-	return scnprintf(buffer, PAGE_SIZE, "0x%016llx\n", sas_address);
+	return sysfs_emit(buffer, "0x%016llx\n", sas_address);
 }
 
 static ssize_t pqi_ssd_smart_path_enabled_show(struct device *dev,
@@ -7346,7 +7343,7 @@ static ssize_t pqi_raid_level_show(struct device *dev,
 
 	spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
 
-	return scnprintf(buffer, PAGE_SIZE, "%s\n", raid_level);
+	return sysfs_emit(buffer, "%s\n", raid_level);
 }
 
 static ssize_t pqi_raid_bypass_cnt_show(struct device *dev,
@@ -7376,7 +7373,7 @@ static ssize_t pqi_raid_bypass_cnt_show(struct device *dev,
 
 	spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
 
-	return scnprintf(buffer, PAGE_SIZE, "0x%x\n", raid_bypass_cnt);
+	return sysfs_emit(buffer, "0x%x\n", raid_bypass_cnt);
 }
 
 static ssize_t pqi_sas_ncq_prio_enable_show(struct device *dev,
@@ -7402,8 +7399,7 @@ static ssize_t pqi_sas_ncq_prio_enable_show(struct device *dev,
 		return -ENODEV;
 	}
 
-	output_len = snprintf(buf, PAGE_SIZE, "%d\n",
-				device->ncq_prio_enable);
+	output_len = sysfs_emit(buf, "%d\n", device->ncq_prio_enable);
 	spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
 
 	return output_len;
@@ -7455,7 +7451,7 @@ static ssize_t pqi_numa_node_show(struct device *dev,
 	sdev = to_scsi_device(dev);
 	ctrl_info = shost_to_hba(sdev->host);
 
-	return scnprintf(buffer, PAGE_SIZE, "%d\n", ctrl_info->numa_node);
+	return sysfs_emit(buffer, "%d\n", ctrl_info->numa_node);
 }
 
 static DEVICE_ATTR(lunid, 0444, pqi_lunid_show, NULL);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 12/25] scsi: snic: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (9 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 11/25] scsi: smartpqi: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19 23:39   ` Karan Tilak Kumar (kartilak)
  2024-03-19  6:31 ` [PATCH v2 13/25] scsi: hpsa: " Li Zhijian
                   ` (13 subsequent siblings)
  24 siblings, 1 reply; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Karan Tilak Kumar, Sesidhar Baddela,
	James E.J. Bottomley, Martin K. Petersen, linux-scsi

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: Karan Tilak Kumar <kartilak@cisco.com>
CC: Sesidhar Baddela <sebaddel@cisco.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/snic/snic_attrs.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/snic/snic_attrs.c b/drivers/scsi/snic/snic_attrs.c
index 3ddbdbc3ded1..48bf82d042b4 100644
--- a/drivers/scsi/snic/snic_attrs.c
+++ b/drivers/scsi/snic/snic_attrs.c
@@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev,
 {
 	struct snic *snic = shost_priv(class_to_shost(dev));
 
-	return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
+	return sysfs_emit(buf, "%s\n", snic->name);
 }
 
 static ssize_t
@@ -23,8 +23,7 @@ snic_show_state(struct device *dev,
 {
 	struct snic *snic = shost_priv(class_to_shost(dev));
 
-	return snprintf(buf, PAGE_SIZE, "%s\n",
-			snic_state_str[snic_get_state(snic)]);
+	return sysfs_emit(buf, "%s\n", snic_state_str[snic_get_state(snic)]);
 }
 
 static ssize_t
@@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,
 		      struct device_attribute *attr,
 		      char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
+	return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION);
 }
 
 static ssize_t
@@ -45,8 +44,8 @@ snic_show_link_state(struct device *dev,
 	if (snic->config.xpt_type == SNIC_DAS)
 		snic->link_status = svnic_dev_link_status(snic->vdev);
 
-	return snprintf(buf, PAGE_SIZE, "%s\n",
-			(snic->link_status) ? "Link Up" : "Link Down");
+	return sysfs_emit(buf, "%s\n",
+			  (snic->link_status) ? "Link Up" : "Link Down");
 }
 
 static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 13/25] scsi: hpsa: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (10 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 12/25] scsi: snic: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 14/25] scsi: hptiop: " Li Zhijian
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Don Brace, James E.J. Bottomley, Martin K. Petersen,
	storagedev, linux-scsi

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: Don Brace <don.brace@microchip.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: storagedev@microchip.com
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/hpsa.c | 83 +++++++++++++++++++++------------------------
 1 file changed, 38 insertions(+), 45 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index af18d20f3079..8d2c1f84c739 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -445,7 +445,7 @@ static ssize_t host_show_lockup_detected(struct device *dev,
 	h = shost_to_hba(shost);
 	ld = lockup_detected(h);
 
-	return sprintf(buf, "ld=%d\n", ld);
+	return sysfs_emit(buf, "ld=%d\n", ld);
 }
 
 static ssize_t host_store_hp_ssd_smart_path_status(struct device *dev,
@@ -525,8 +525,8 @@ static ssize_t host_show_firmware_revision(struct device *dev,
 	if (!h->hba_inquiry_data)
 		return 0;
 	fwrev = &h->hba_inquiry_data[32];
-	return snprintf(buf, 20, "%c%c%c%c\n",
-		fwrev[0], fwrev[1], fwrev[2], fwrev[3]);
+	return sysfs_emit(buf, "%c%c%c%c\n",
+			  fwrev[0], fwrev[1], fwrev[2], fwrev[3]);
 }
 
 static ssize_t host_show_commands_outstanding(struct device *dev,
@@ -535,8 +535,7 @@ static ssize_t host_show_commands_outstanding(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct ctlr_info *h = shost_to_hba(shost);
 
-	return snprintf(buf, 20, "%d\n",
-			atomic_read(&h->commands_outstanding));
+	return sysfs_emit(buf, "%d\n", atomic_read(&h->commands_outstanding));
 }
 
 static ssize_t host_show_transport_mode(struct device *dev,
@@ -546,9 +545,9 @@ static ssize_t host_show_transport_mode(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 
 	h = shost_to_hba(shost);
-	return snprintf(buf, 20, "%s\n",
-		h->transMethod & CFGTBL_Trans_Performant ?
-			"performant" : "simple");
+	return sysfs_emit(buf, "%s\n",
+			  h->transMethod & CFGTBL_Trans_Performant ?
+			  "performant" : "simple");
 }
 
 static ssize_t host_show_hp_ssd_smart_path_status(struct device *dev,
@@ -558,8 +557,8 @@ static ssize_t host_show_hp_ssd_smart_path_status(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 
 	h = shost_to_hba(shost);
-	return snprintf(buf, 30, "HP SSD Smart Path %s\n",
-		(h->acciopath_status == 1) ?  "enabled" : "disabled");
+	return sysfs_emit(buf, "HP SSD Smart Path %s\n",
+			  (h->acciopath_status == 1) ?  "enabled" : "disabled");
 }
 
 /* List of controllers which cannot be hard reset on kexec with reset_devices */
@@ -642,7 +641,7 @@ static ssize_t host_show_resettable(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 
 	h = shost_to_hba(shost);
-	return snprintf(buf, 20, "%d\n", ctlr_is_resettable(h->board_id));
+	return sysfs_emit(buf, "%d\n", ctlr_is_resettable(h->board_id));
 }
 
 static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[])
@@ -690,7 +689,7 @@ static ssize_t raid_level_show(struct device *dev,
 	/* Is this even a logical drive? */
 	if (!is_logical_device(hdev)) {
 		spin_unlock_irqrestore(&h->lock, flags);
-		l = snprintf(buf, PAGE_SIZE, "N/A\n");
+		l = sysfs_emit(buf, "N/A\n");
 		return l;
 	}
 
@@ -698,7 +697,7 @@ static ssize_t raid_level_show(struct device *dev,
 	spin_unlock_irqrestore(&h->lock, flags);
 	if (rlevel > RAID_UNKNOWN)
 		rlevel = RAID_UNKNOWN;
-	l = snprintf(buf, PAGE_SIZE, "RAID %s\n", raid_label[rlevel]);
+	l = sysfs_emit(buf, "RAID %s\n", raid_label[rlevel]);
 	return l;
 }
 
@@ -721,7 +720,7 @@ static ssize_t lunid_show(struct device *dev,
 	}
 	memcpy(lunid, hdev->scsi3addr, sizeof(lunid));
 	spin_unlock_irqrestore(&h->lock, flags);
-	return snprintf(buf, 20, "0x%8phN\n", lunid);
+	return sysfs_emit(buf, "0x%8phN\n", lunid);
 }
 
 static ssize_t unique_id_show(struct device *dev,
@@ -743,13 +742,12 @@ static ssize_t unique_id_show(struct device *dev,
 	}
 	memcpy(sn, hdev->device_id, sizeof(sn));
 	spin_unlock_irqrestore(&h->lock, flags);
-	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 ssize_t sas_address_show(struct device *dev,
@@ -772,7 +770,7 @@ static ssize_t sas_address_show(struct device *dev,
 	sas_address = hdev->sas_address;
 	spin_unlock_irqrestore(&h->lock, flags);
 
-	return snprintf(buf, PAGE_SIZE, "0x%016llx\n", sas_address);
+	return sysfs_emit(buf, "0x%016llx\n", sas_address);
 }
 
 static ssize_t host_show_hp_ssd_smart_path_enabled(struct device *dev,
@@ -796,10 +794,10 @@ static ssize_t host_show_hp_ssd_smart_path_enabled(struct device *dev,
 	spin_unlock_irqrestore(&h->lock, flags);
 
 	if (hdev->devtype == TYPE_DISK || hdev->devtype == TYPE_ZBC)
-		return snprintf(buf, 20, "%d\n", offload_enabled);
+		return sysfs_emit(buf, "%d\n", offload_enabled);
 	else
-		return snprintf(buf, 40, "%s\n",
-				"Not applicable for a controller");
+		return sysfs_emit(buf, "%s\n",
+				  "Not applicable for a controller");
 }
 
 #define MAX_PATHS 8
@@ -837,17 +835,15 @@ static ssize_t path_info_show(struct device *dev,
 		else
 			continue;
 
-		output_len += scnprintf(buf + output_len,
-				PAGE_SIZE - output_len,
+		output_len += sysfs_emit_at(buf, output_len,
 				"[%d:%d:%d:%d] %20.20s ",
 				h->scsi_host->host_no,
 				hdev->bus, hdev->target, hdev->lun,
 				scsi_device_type(hdev->devtype));
 
 		if (hdev->devtype == TYPE_RAID || is_logical_device(hdev)) {
-			output_len += scnprintf(buf + output_len,
-						PAGE_SIZE - output_len,
-						"%s\n", active);
+			output_len += sysfs_emit_at(buf, output_len,
+						    "%s\n", active);
 			continue;
 		}
 
@@ -858,30 +854,27 @@ static ssize_t path_info_show(struct device *dev,
 			phys_connector[0] = '0';
 		if (phys_connector[1] < '0')
 			phys_connector[1] = '0';
-		output_len += scnprintf(buf + output_len,
-				PAGE_SIZE - output_len,
+		output_len += sysfs_emit_at(buf, output_len,
 				"PORT: %.2s ",
 				phys_connector);
 		if ((hdev->devtype == TYPE_DISK || hdev->devtype == TYPE_ZBC) &&
 			hdev->expose_device) {
 			if (box == 0 || box == 0xFF) {
-				output_len += scnprintf(buf + output_len,
-					PAGE_SIZE - output_len,
-					"BAY: %hhu %s\n",
-					bay, active);
+				output_len += sysfs_emit_at(buf, output_len,
+							    "BAY: %hhu %s\n",
+							     bay, active);
 			} else {
-				output_len += scnprintf(buf + output_len,
-					PAGE_SIZE - output_len,
+				output_len += sysfs_emit_at(buf, output_len,
 					"BOX: %hhu BAY: %hhu %s\n",
 					box, bay, active);
 			}
 		} else if (box != 0 && box != 0xFF) {
-			output_len += scnprintf(buf + output_len,
-				PAGE_SIZE - output_len, "BOX: %hhu %s\n",
-				box, active);
+			output_len += sysfs_emit_at(buf, output_len,
+						    "BOX: %hhu %s\n",
+						    box, active);
 		} else
-			output_len += scnprintf(buf + output_len,
-				PAGE_SIZE - output_len, "%s\n", active);
+			output_len += sysfs_emit_at(buf, output_len,
+						    "%s\n", active);
 	}
 
 	spin_unlock_irqrestore(&h->devlock, flags);
@@ -895,7 +888,7 @@ static ssize_t host_show_ctlr_num(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 
 	h = shost_to_hba(shost);
-	return snprintf(buf, 20, "%d\n", h->ctlr);
+	return sysfs_emit(buf, "%d\n", h->ctlr);
 }
 
 static ssize_t host_show_legacy_board(struct device *dev,
@@ -905,7 +898,7 @@ static ssize_t host_show_legacy_board(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 
 	h = shost_to_hba(shost);
-	return snprintf(buf, 20, "%d\n", h->legacy_board ? 1 : 0);
+	return sysfs_emit(buf, "%d\n", h->legacy_board ? 1 : 0);
 }
 
 static DEVICE_ATTR_RO(raid_level);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 14/25] scsi: hptiop: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (11 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 13/25] scsi: hpsa: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 15/25] scsi: ipr: " Li Zhijian
                   ` (11 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, HighPoint Linux Team, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi

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: HighPoint Linux Team <linux@highpoint-tech.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/hptiop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index f5334ccbf2ca..65426df93270 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -1111,7 +1111,7 @@ static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
 static ssize_t hptiop_show_version(struct device *dev,
 				   struct device_attribute *attr, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
+	return sysfs_emit(buf, "%s\n", driver_ver);
 }
 
 static ssize_t hptiop_show_fw_version(struct device *dev,
@@ -1120,7 +1120,7 @@ static ssize_t hptiop_show_fw_version(struct device *dev,
 	struct Scsi_Host *host = class_to_shost(dev);
 	struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
 
-	return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
+	return sysfs_emit(buf, "%d.%d.%d.%d\n",
 				hba->firmware_version >> 24,
 				(hba->firmware_version >> 16) & 0xff,
 				(hba->firmware_version >> 8) & 0xff,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 15/25] scsi: ipr: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (12 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 14/25] scsi: hptiop: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 16/25] scsi: myrb,myrs: " Li Zhijian
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Brian King, James E.J. Bottomley, Martin K. Petersen,
	linux-scsi

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: Brian King <brking@us.ibm.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/ipr.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 3819f7c42788..ad3003a67109 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -3412,10 +3412,10 @@ static ssize_t ipr_show_fw_version(struct device *dev,
 	int len;
 
 	spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
-	len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
-		       ucode_vpd->major_release, ucode_vpd->card_type,
-		       ucode_vpd->minor_release[0],
-		       ucode_vpd->minor_release[1]);
+	len = sysfs_emit(buf, "%02X%02X%02X%02X\n",
+			 ucode_vpd->major_release, ucode_vpd->card_type,
+			 ucode_vpd->minor_release[0],
+			 ucode_vpd->minor_release[1]);
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 	return len;
 }
@@ -3446,7 +3446,7 @@ static ssize_t ipr_show_log_level(struct device *dev,
 	int len;
 
 	spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
-	len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
+	len = sysfs_emit(buf, "%d\n", ioa_cfg->log_level);
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 	return len;
 }
@@ -3565,9 +3565,9 @@ static ssize_t ipr_show_adapter_state(struct device *dev,
 
 	spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
 	if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
-		len = snprintf(buf, PAGE_SIZE, "offline\n");
+		len = sysfs_emit(buf, "offline\n");
 	else
-		len = snprintf(buf, PAGE_SIZE, "online\n");
+		len = sysfs_emit(buf, "online\n");
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 	return len;
 }
@@ -3684,7 +3684,7 @@ static ssize_t ipr_show_iopoll_weight(struct device *dev,
 	int len;
 
 	spin_lock_irqsave(shost->host_lock, lock_flags);
-	len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->iopoll_weight);
+	len = sysfs_emit(buf, "%d\n", ioa_cfg->iopoll_weight);
 	spin_unlock_irqrestore(shost->host_lock, lock_flags);
 
 	return len;
@@ -4073,7 +4073,7 @@ static ssize_t ipr_show_fw_type(struct device *dev,
 	int len;
 
 	spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
-	len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
+	len = sysfs_emit(buf, "%d\n", ioa_cfg->sis64);
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 	return len;
 }
@@ -4432,7 +4432,7 @@ static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribu
 	spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
 	res = (struct ipr_resource_entry *)sdev->hostdata;
 	if (res)
-		len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
+		len = sysfs_emit(buf, "%08X\n", res->res_handle);
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 	return len;
 }
@@ -4467,12 +4467,12 @@ static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribut
 	spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
 	res = (struct ipr_resource_entry *)sdev->hostdata;
 	if (res && ioa_cfg->sis64)
-		len = snprintf(buf, PAGE_SIZE, "%s\n",
-			       __ipr_format_res_path(res->res_path, buffer,
-						     sizeof(buffer)));
+		len = sysfs_emit(buf, "%s\n",
+				 __ipr_format_res_path(res->res_path, buffer,
+						       sizeof(buffer)));
 	else if (res)
-		len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
-			       res->bus, res->target, res->lun);
+		len = sysfs_emit(buf, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
+				 res->bus, res->target, res->lun);
 
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 	return len;
@@ -4506,9 +4506,9 @@ static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *a
 	spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
 	res = (struct ipr_resource_entry *)sdev->hostdata;
 	if (res && ioa_cfg->sis64)
-		len = snprintf(buf, PAGE_SIZE, "0x%llx\n", be64_to_cpu(res->dev_id));
+		len = sysfs_emit(buf, "0x%llx\n", be64_to_cpu(res->dev_id));
 	else if (res)
-		len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
+		len = sysfs_emit(buf, "0x%llx\n", res->lun_wwn);
 
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 	return len;
@@ -4543,7 +4543,7 @@ static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribut
 	res = (struct ipr_resource_entry *)sdev->hostdata;
 
 	if (res)
-		len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
+		len = sysfs_emit(buf, "%x\n", res->type);
 
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 	return len;
@@ -4578,7 +4578,7 @@ static ssize_t ipr_show_raw_mode(struct device *dev,
 	spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
 	res = (struct ipr_resource_entry *)sdev->hostdata;
 	if (res)
-		len = snprintf(buf, PAGE_SIZE, "%d\n", res->raw_mode);
+		len = sysfs_emit(buf, "%d\n", res->raw_mode);
 	else
 		len = -ENXIO;
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 16/25] scsi: myrb,myrs: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (13 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 15/25] scsi: ipr: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 17/25] scsi: ncr53c8xx: " Li Zhijian
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Hannes Reinecke, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi

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: Hannes Reinecke <hare@kernel.org>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/myrb.c | 38 ++++++++++----------
 drivers/scsi/myrs.c | 88 ++++++++++++++++++++++-----------------------
 2 files changed, 63 insertions(+), 63 deletions(-)

diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c
index ca2e932dd9b7..06a5e6fb9f99 100644
--- a/drivers/scsi/myrb.c
+++ b/drivers/scsi/myrb.c
@@ -1767,7 +1767,7 @@ static ssize_t raid_state_show(struct device *dev,
 	int ret;
 
 	if (!sdev->hostdata)
-		return snprintf(buf, 16, "Unknown\n");
+		return sysfs_emit(buf, "Unknown\n");
 
 	if (sdev->channel == myrb_logical_channel(sdev->host)) {
 		struct myrb_ldev_info *ldev_info = sdev->hostdata;
@@ -1775,10 +1775,10 @@ static ssize_t raid_state_show(struct device *dev,
 
 		name = myrb_devstate_name(ldev_info->state);
 		if (name)
-			ret = snprintf(buf, 32, "%s\n", name);
+			ret = sysfs_emit(buf, "%s\n", name);
 		else
-			ret = snprintf(buf, 32, "Invalid (%02X)\n",
-				       ldev_info->state);
+			ret = sysfs_emit(buf, "Invalid (%02X)\n",
+					 ldev_info->state);
 	} else {
 		struct myrb_pdev_state *pdev_info = sdev->hostdata;
 		unsigned short status;
@@ -1796,10 +1796,10 @@ static ssize_t raid_state_show(struct device *dev,
 		else
 			name = myrb_devstate_name(pdev_info->state);
 		if (name)
-			ret = snprintf(buf, 32, "%s\n", name);
+			ret = sysfs_emit(buf, "%s\n", name);
 		else
-			ret = snprintf(buf, 32, "Invalid (%02X)\n",
-				       pdev_info->state);
+			ret = sysfs_emit(buf, "Invalid (%02X)\n",
+					 pdev_info->state);
 	}
 	return ret;
 }
@@ -1886,11 +1886,11 @@ static ssize_t raid_level_show(struct device *dev,
 
 		name = myrb_raidlevel_name(ldev_info->raid_level);
 		if (!name)
-			return snprintf(buf, 32, "Invalid (%02X)\n",
-					ldev_info->state);
-		return snprintf(buf, 32, "%s\n", name);
+			return sysfs_emit(buf, "Invalid (%02X)\n",
+					  ldev_info->state);
+		return sysfs_emit(buf, "%s\n", name);
 	}
-	return snprintf(buf, 32, "Physical Drive\n");
+	return sysfs_emit(buf, "Physical Drive\n");
 }
 static DEVICE_ATTR_RO(raid_level);
 
@@ -1903,17 +1903,17 @@ static ssize_t rebuild_show(struct device *dev,
 	unsigned char status;
 
 	if (sdev->channel < myrb_logical_channel(sdev->host))
-		return snprintf(buf, 32, "physical device - not rebuilding\n");
+		return sysfs_emit(buf, "physical device - not rebuilding\n");
 
 	status = myrb_get_rbld_progress(cb, &rbld_buf);
 
 	if (rbld_buf.ldev_num != sdev->id ||
 	    status != MYRB_STATUS_SUCCESS)
-		return snprintf(buf, 32, "not rebuilding\n");
+		return sysfs_emit(buf, "not rebuilding\n");
 
-	return snprintf(buf, 32, "rebuilding block %u of %u\n",
-			rbld_buf.ldev_size - rbld_buf.blocks_left,
-			rbld_buf.ldev_size);
+	return sysfs_emit(buf, "rebuilding block %u of %u\n",
+			  rbld_buf.ldev_size - rbld_buf.blocks_left,
+			  rbld_buf.ldev_size);
 }
 
 static ssize_t rebuild_store(struct device *dev,
@@ -2140,7 +2140,7 @@ static ssize_t ctlr_num_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct myrb_hba *cb = shost_priv(shost);
 
-	return snprintf(buf, 20, "%u\n", cb->ctlr_num);
+	return sysfs_emit(buf, "%u\n", cb->ctlr_num);
 }
 static DEVICE_ATTR_RO(ctlr_num);
 
@@ -2150,7 +2150,7 @@ static ssize_t firmware_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct myrb_hba *cb = shost_priv(shost);
 
-	return snprintf(buf, 16, "%s\n", cb->fw_version);
+	return sysfs_emit(buf, "%s\n", cb->fw_version);
 }
 static DEVICE_ATTR_RO(firmware);
 
@@ -2160,7 +2160,7 @@ static ssize_t model_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct myrb_hba *cb = shost_priv(shost);
 
-	return snprintf(buf, 16, "%s\n", cb->model_name);
+	return sysfs_emit(buf, "%s\n", cb->model_name);
 }
 static DEVICE_ATTR_RO(model);
 
diff --git a/drivers/scsi/myrs.c b/drivers/scsi/myrs.c
index a1eec65a9713..5dda3b669ec1 100644
--- a/drivers/scsi/myrs.c
+++ b/drivers/scsi/myrs.c
@@ -939,7 +939,7 @@ static ssize_t raid_state_show(struct device *dev,
 	int ret;
 
 	if (!sdev->hostdata)
-		return snprintf(buf, 16, "Unknown\n");
+		return sysfs_emit(buf, "Unknown\n");
 
 	if (sdev->channel >= cs->ctlr_info->physchan_present) {
 		struct myrs_ldev_info *ldev_info = sdev->hostdata;
@@ -947,10 +947,10 @@ static ssize_t raid_state_show(struct device *dev,
 
 		name = myrs_devstate_name(ldev_info->dev_state);
 		if (name)
-			ret = snprintf(buf, 32, "%s\n", name);
+			ret = sysfs_emit(buf, "%s\n", name);
 		else
-			ret = snprintf(buf, 32, "Invalid (%02X)\n",
-				       ldev_info->dev_state);
+			ret = sysfs_emit(buf, "Invalid (%02X)\n",
+					 ldev_info->dev_state);
 	} else {
 		struct myrs_pdev_info *pdev_info;
 		const char *name;
@@ -958,10 +958,10 @@ static ssize_t raid_state_show(struct device *dev,
 		pdev_info = sdev->hostdata;
 		name = myrs_devstate_name(pdev_info->dev_state);
 		if (name)
-			ret = snprintf(buf, 32, "%s\n", name);
+			ret = sysfs_emit(buf, "%s\n", name);
 		else
-			ret = snprintf(buf, 32, "Invalid (%02X)\n",
-				       pdev_info->dev_state);
+			ret = sysfs_emit(buf, "Invalid (%02X)\n",
+					 pdev_info->dev_state);
 	}
 	return ret;
 }
@@ -1058,7 +1058,7 @@ static ssize_t raid_level_show(struct device *dev,
 	const char *name = NULL;
 
 	if (!sdev->hostdata)
-		return snprintf(buf, 16, "Unknown\n");
+		return sysfs_emit(buf, "Unknown\n");
 
 	if (sdev->channel >= cs->ctlr_info->physchan_present) {
 		struct myrs_ldev_info *ldev_info;
@@ -1066,13 +1066,13 @@ static ssize_t raid_level_show(struct device *dev,
 		ldev_info = sdev->hostdata;
 		name = myrs_raid_level_name(ldev_info->raid_level);
 		if (!name)
-			return snprintf(buf, 32, "Invalid (%02X)\n",
-					ldev_info->dev_state);
+			return sysfs_emit(buf, "Invalid (%02X)\n",
+					  ldev_info->dev_state);
 
 	} else
 		name = myrs_raid_level_name(MYRS_RAID_PHYSICAL);
 
-	return snprintf(buf, 32, "%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 static DEVICE_ATTR_RO(raid_level);
 
@@ -1086,7 +1086,7 @@ static ssize_t rebuild_show(struct device *dev,
 	unsigned char status;
 
 	if (sdev->channel < cs->ctlr_info->physchan_present)
-		return snprintf(buf, 32, "physical device - not rebuilding\n");
+		return sysfs_emit(buf, "physical device - not rebuilding\n");
 
 	ldev_info = sdev->hostdata;
 	ldev_num = ldev_info->ldev_num;
@@ -1098,11 +1098,11 @@ static ssize_t rebuild_show(struct device *dev,
 		return -EIO;
 	}
 	if (ldev_info->rbld_active) {
-		return snprintf(buf, 32, "rebuilding block %zu of %zu\n",
-				(size_t)ldev_info->rbld_lba,
-				(size_t)ldev_info->cfg_devsize);
+		return sysfs_emit(buf, "rebuilding block %zu of %zu\n",
+				  (size_t)ldev_info->rbld_lba,
+				  (size_t)ldev_info->cfg_devsize);
 	} else
-		return snprintf(buf, 32, "not rebuilding\n");
+		return sysfs_emit(buf, "not rebuilding\n");
 }
 
 static ssize_t rebuild_store(struct device *dev,
@@ -1190,7 +1190,7 @@ static ssize_t consistency_check_show(struct device *dev,
 	unsigned short ldev_num;
 
 	if (sdev->channel < cs->ctlr_info->physchan_present)
-		return snprintf(buf, 32, "physical device - not checking\n");
+		return sysfs_emit(buf, "physical device - not checking\n");
 
 	ldev_info = sdev->hostdata;
 	if (!ldev_info)
@@ -1198,11 +1198,11 @@ static ssize_t consistency_check_show(struct device *dev,
 	ldev_num = ldev_info->ldev_num;
 	myrs_get_ldev_info(cs, ldev_num, ldev_info);
 	if (ldev_info->cc_active)
-		return snprintf(buf, 32, "checking block %zu of %zu\n",
-				(size_t)ldev_info->cc_lba,
-				(size_t)ldev_info->cfg_devsize);
+		return sysfs_emit(buf, "checking block %zu of %zu\n",
+				  (size_t)ldev_info->cc_lba,
+				  (size_t)ldev_info->cfg_devsize);
 	else
-		return snprintf(buf, 32, "not checking\n");
+		return sysfs_emit(buf, "not checking\n");
 }
 
 static ssize_t consistency_check_store(struct device *dev,
@@ -1303,7 +1303,7 @@ static ssize_t serial_show(struct device *dev,
 
 	memcpy(serial, cs->ctlr_info->serial_number, 16);
 	serial[16] = '\0';
-	return snprintf(buf, 16, "%s\n", serial);
+	return sysfs_emit(buf, "%s\n", serial);
 }
 static DEVICE_ATTR_RO(serial);
 
@@ -1313,7 +1313,7 @@ static ssize_t ctlr_num_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct myrs_hba *cs = shost_priv(shost);
 
-	return snprintf(buf, 20, "%d\n", cs->host->host_no);
+	return sysfs_emit(buf, "%d\n", cs->host->host_no);
 }
 static DEVICE_ATTR_RO(ctlr_num);
 
@@ -1361,22 +1361,22 @@ static ssize_t processor_show(struct device *dev,
 		}
 	}
 	if (first_processor && second_processor)
-		ret = snprintf(buf, 64, "1: %s (%s, %d cpus)\n"
-			       "2: %s (%s, %d cpus)\n",
-			       info->cpu[0].cpu_name,
-			       first_processor, info->cpu[0].cpu_count,
-			       info->cpu[1].cpu_name,
-			       second_processor, info->cpu[1].cpu_count);
+		ret = sysfs_emit(buf, "1: %s (%s, %d cpus)\n"
+				 "2: %s (%s, %d cpus)\n",
+				 info->cpu[0].cpu_name,
+				 first_processor, info->cpu[0].cpu_count,
+				 info->cpu[1].cpu_name,
+				 second_processor, info->cpu[1].cpu_count);
 	else if (first_processor && !second_processor)
-		ret = snprintf(buf, 64, "1: %s (%s, %d cpus)\n2: absent\n",
-			       info->cpu[0].cpu_name,
-			       first_processor, info->cpu[0].cpu_count);
+		ret = sysfs_emit(buf, "1: %s (%s, %d cpus)\n2: absent\n",
+				 info->cpu[0].cpu_name,
+				 first_processor, info->cpu[0].cpu_count);
 	else if (!first_processor && second_processor)
-		ret = snprintf(buf, 64, "1: absent\n2: %s (%s, %d cpus)\n",
-			       info->cpu[1].cpu_name,
-			       second_processor, info->cpu[1].cpu_count);
+		ret = sysfs_emit(buf, "1: absent\n2: %s (%s, %d cpus)\n",
+				 info->cpu[1].cpu_name,
+				 second_processor, info->cpu[1].cpu_count);
 	else
-		ret = snprintf(buf, 64, "1: absent\n2: absent\n");
+		ret = sysfs_emit(buf, "1: absent\n2: absent\n");
 
 	return ret;
 }
@@ -1388,7 +1388,7 @@ static ssize_t model_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct myrs_hba *cs = shost_priv(shost);
 
-	return snprintf(buf, 28, "%s\n", cs->model_name);
+	return sysfs_emit(buf, "%s\n", cs->model_name);
 }
 static DEVICE_ATTR_RO(model);
 
@@ -1398,7 +1398,7 @@ static ssize_t ctlr_type_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct myrs_hba *cs = shost_priv(shost);
 
-	return snprintf(buf, 4, "%d\n", cs->ctlr_info->ctlr_type);
+	return sysfs_emit(buf, "%d\n", cs->ctlr_info->ctlr_type);
 }
 static DEVICE_ATTR_RO(ctlr_type);
 
@@ -1408,7 +1408,7 @@ static ssize_t cache_size_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct myrs_hba *cs = shost_priv(shost);
 
-	return snprintf(buf, 8, "%d MB\n", cs->ctlr_info->cache_size_mb);
+	return sysfs_emit(buf, "%d MB\n", cs->ctlr_info->cache_size_mb);
 }
 static DEVICE_ATTR_RO(cache_size);
 
@@ -1418,10 +1418,10 @@ static ssize_t firmware_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct myrs_hba *cs = shost_priv(shost);
 
-	return snprintf(buf, 16, "%d.%02d-%02d\n",
-			cs->ctlr_info->fw_major_version,
-			cs->ctlr_info->fw_minor_version,
-			cs->ctlr_info->fw_turn_number);
+	return sysfs_emit(buf, "%d.%02d-%02d\n",
+			  cs->ctlr_info->fw_major_version,
+			  cs->ctlr_info->fw_minor_version,
+			  cs->ctlr_info->fw_turn_number);
 }
 static DEVICE_ATTR_RO(firmware);
 
@@ -1488,7 +1488,7 @@ static ssize_t disable_enclosure_messages_show(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct myrs_hba *cs = shost_priv(shost);
 
-	return snprintf(buf, 3, "%d\n", cs->disable_enc_msg);
+	return sysfs_emit(buf, "%d\n", cs->disable_enc_msg);
 }
 
 static ssize_t disable_enclosure_messages_store(struct device *dev,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 17/25] scsi: ncr53c8xx: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (14 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 16/25] scsi: myrb,myrs: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 18/25] scsi: pmcraid: " Li Zhijian
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/ncr53c8xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/ncr53c8xx.c b/drivers/scsi/ncr53c8xx.c
index 35869b4f9329..2bd74620caf5 100644
--- a/drivers/scsi/ncr53c8xx.c
+++ b/drivers/scsi/ncr53c8xx.c
@@ -8031,7 +8031,7 @@ static ssize_t show_ncr53c8xx_revision(struct device *dev,
 	struct Scsi_Host *host = class_to_shost(dev);
 	struct host_data *host_data = (struct host_data *)host->hostdata;
   
-	return snprintf(buf, 20, "0x%x\n", host_data->ncb->revision_id);
+	return sysfs_emit(buf, "0x%x\n", host_data->ncb->revision_id);
 }
   
 static struct device_attribute ncr53c8xx_revision_attr = {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 18/25] scsi: pmcraid: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (15 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 17/25] scsi: ncr53c8xx: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 19/25] scsi: st: " Li Zhijian
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 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


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 19/25] scsi: st: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (16 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 18/25] scsi: pmcraid: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 20/25] scsi: core: " Li Zhijian
                   ` (6 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Kai Mäkisara, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi

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: "Kai Mäkisara" <Kai.Makisara@kolumbus.fi>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/st.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 338aa8c42968..998e5bb7a6a0 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4571,7 +4571,7 @@ defined_show(struct device *dev, struct device_attribute *attr, char *buf)
 	struct st_modedef *STm = dev_get_drvdata(dev);
 	ssize_t l = 0;
 
-	l = snprintf(buf, PAGE_SIZE, "%d\n", STm->defined);
+	l = sysfs_emit(buf, "%d\n", STm->defined);
 	return l;
 }
 static DEVICE_ATTR_RO(defined);
@@ -4583,7 +4583,7 @@ default_blksize_show(struct device *dev, struct device_attribute *attr,
 	struct st_modedef *STm = dev_get_drvdata(dev);
 	ssize_t l = 0;
 
-	l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_blksize);
+	l = sysfs_emit(buf, "%d\n", STm->default_blksize);
 	return l;
 }
 static DEVICE_ATTR_RO(default_blksize);
@@ -4597,7 +4597,7 @@ default_density_show(struct device *dev, struct device_attribute *attr,
 	char *fmt;
 
 	fmt = STm->default_density >= 0 ? "0x%02x\n" : "%d\n";
-	l = snprintf(buf, PAGE_SIZE, fmt, STm->default_density);
+	l = sysfs_emit(buf, fmt, STm->default_density);
 	return l;
 }
 static DEVICE_ATTR_RO(default_density);
@@ -4609,7 +4609,7 @@ default_compression_show(struct device *dev, struct device_attribute *attr,
 	struct st_modedef *STm = dev_get_drvdata(dev);
 	ssize_t l = 0;
 
-	l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_compression - 1);
+	l = sysfs_emit(buf, "%d\n", STm->default_compression - 1);
 	return l;
 }
 static DEVICE_ATTR_RO(default_compression);
@@ -4638,7 +4638,7 @@ options_show(struct device *dev, struct device_attribute *attr, char *buf)
 	options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0;
 	options |= STp->sili ? MT_ST_SILI : 0;
 
-	l = snprintf(buf, PAGE_SIZE, "0x%08x\n", options);
+	l = sysfs_emit(buf, "0x%08x\n", options);
 	return l;
 }
 static DEVICE_ATTR_RO(options);
@@ -4656,7 +4656,7 @@ static ssize_t read_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->read_cnt));
 }
 static DEVICE_ATTR_RO(read_cnt);
@@ -4674,7 +4674,7 @@ static ssize_t read_byte_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->read_byte_cnt));
 }
 static DEVICE_ATTR_RO(read_byte_cnt);
@@ -4690,7 +4690,7 @@ static ssize_t read_ns_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->tot_read_time));
 }
 static DEVICE_ATTR_RO(read_ns);
@@ -4707,7 +4707,7 @@ static ssize_t write_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->write_cnt));
 }
 static DEVICE_ATTR_RO(write_cnt);
@@ -4724,7 +4724,7 @@ static ssize_t write_byte_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->write_byte_cnt));
 }
 static DEVICE_ATTR_RO(write_byte_cnt);
@@ -4741,7 +4741,7 @@ static ssize_t write_ns_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->tot_write_time));
 }
 static DEVICE_ATTR_RO(write_ns);
@@ -4759,7 +4759,7 @@ static ssize_t in_flight_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->in_flight));
 }
 static DEVICE_ATTR_RO(in_flight);
@@ -4779,7 +4779,7 @@ static ssize_t io_ns_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->tot_io_time));
 }
 static DEVICE_ATTR_RO(io_ns);
@@ -4798,7 +4798,7 @@ static ssize_t other_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->other_cnt));
 }
 static DEVICE_ATTR_RO(other_cnt);
@@ -4816,7 +4816,7 @@ static ssize_t resid_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->resid_cnt));
 }
 static DEVICE_ATTR_RO(resid_cnt);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 20/25] scsi: core: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (17 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 19/25] scsi: st: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 21/25] scsi: scsi_transport_fc: Convert sprintf() family to sysfs_emit() family (part 1) Li Zhijian
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/scsi_sysfs.c | 69 ++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 34 deletions(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 49dd34426d5e..2e9d93d0e770 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -163,7 +163,7 @@ show_##name (struct device *dev, struct device_attribute *attr, 	\
 	     char *buf)							\
 {									\
 	struct Scsi_Host *shost = class_to_shost(dev);			\
-	return snprintf (buf, 20, format_string, shost->field);		\
+	return sysfs_emit(buf, format_string, shost->field);		\
 }
 
 /*
@@ -228,7 +228,7 @@ show_shost_state(struct device *dev, struct device_attribute *attr, char *buf)
 	if (!name)
 		return -EINVAL;
 
-	return snprintf(buf, 20, "%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 
 /* DEVICE_ATTR(state) clashes with dev_attr_state for sdev */
@@ -241,12 +241,13 @@ show_shost_mode(unsigned int mode, char *buf)
 	ssize_t len = 0;
 
 	if (mode & MODE_INITIATOR)
-		len = sprintf(buf, "%s", "Initiator");
+		len = sysfs_emit(buf, "%s", "Initiator");
 
 	if (mode & MODE_TARGET)
-		len += sprintf(buf + len, "%s%s", len ? ", " : "", "Target");
+		len += sysfs_emit_at(buf, len, "%s%s",
+				     len ? ", " : "", "Target");
 
-	len += sprintf(buf + len, "\n");
+	len += sysfs_emit_at(buf, len, "\n");
 
 	return len;
 }
@@ -274,7 +275,7 @@ show_shost_active_mode(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 
 	if (shost->active_mode == MODE_UNKNOWN)
-		return snprintf(buf, 20, "unknown\n");
+		return sysfs_emit(buf, "unknown\n");
 	else
 		return show_shost_mode(shost->active_mode, buf);
 }
@@ -324,8 +325,8 @@ show_shost_eh_deadline(struct device *dev,
 	struct Scsi_Host *shost = class_to_shost(dev);
 
 	if (shost->eh_deadline == -1)
-		return snprintf(buf, strlen("off") + 2, "off\n");
-	return sprintf(buf, "%u\n", shost->eh_deadline / HZ);
+		return sysfs_emit(buf, "off\n");
+	return sysfs_emit(buf, "%u\n", shost->eh_deadline / HZ);
 }
 
 static ssize_t
@@ -382,14 +383,14 @@ static ssize_t
 show_host_busy(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct Scsi_Host *shost = class_to_shost(dev);
-	return snprintf(buf, 20, "%d\n", scsi_host_busy(shost));
+	return sysfs_emit(buf, "%d\n", scsi_host_busy(shost));
 }
 static DEVICE_ATTR(host_busy, S_IRUGO, show_host_busy, NULL);
 
 static ssize_t
 show_use_blk_mq(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	return sprintf(buf, "1\n");
+	return sysfs_emit(buf, "1\n");
 }
 static DEVICE_ATTR(use_blk_mq, S_IRUGO, show_use_blk_mq, NULL);
 
@@ -399,7 +400,7 @@ show_nr_hw_queues(struct device *dev, struct device_attribute *attr, char *buf)
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct blk_mq_tag_set *tag_set = &shost->tag_set;
 
-	return snprintf(buf, 20, "%d\n", tag_set->nr_hw_queues);
+	return sysfs_emit(buf, "%d\n", tag_set->nr_hw_queues);
 }
 static DEVICE_ATTR(nr_hw_queues, S_IRUGO, show_nr_hw_queues, NULL);
 
@@ -589,7 +590,7 @@ sdev_show_##field (struct device *dev, struct device_attribute *attr,	\
 {									\
 	struct scsi_device *sdev;					\
 	sdev = to_scsi_device(dev);					\
-	return snprintf (buf, 20, format_string, sdev->field);		\
+	return sysfs_emit(buf, format_string, sdev->field);		\
 }									\
 
 /*
@@ -677,7 +678,7 @@ sdev_show_device_busy(struct device *dev, struct device_attribute *attr,
 		char *buf)
 {
 	struct scsi_device *sdev = to_scsi_device(dev);
-	return snprintf(buf, 20, "%d\n", scsi_device_busy(sdev));
+	return sysfs_emit(buf, "%d\n", scsi_device_busy(sdev));
 }
 static DEVICE_ATTR(device_busy, S_IRUGO, sdev_show_device_busy, NULL);
 
@@ -686,7 +687,7 @@ sdev_show_device_blocked(struct device *dev, struct device_attribute *attr,
 		char *buf)
 {
 	struct scsi_device *sdev = to_scsi_device(dev);
-	return snprintf(buf, 20, "%d\n", atomic_read(&sdev->device_blocked));
+	return sysfs_emit(buf, "%d\n", atomic_read(&sdev->device_blocked));
 }
 static DEVICE_ATTR(device_blocked, S_IRUGO, sdev_show_device_blocked, NULL);
 
@@ -698,7 +699,7 @@ sdev_show_timeout (struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct scsi_device *sdev;
 	sdev = to_scsi_device(dev);
-	return snprintf(buf, 20, "%d\n", sdev->request_queue->rq_timeout / HZ);
+	return sysfs_emit(buf, "%d\n", sdev->request_queue->rq_timeout / HZ);
 }
 
 static ssize_t
@@ -719,7 +720,7 @@ sdev_show_eh_timeout(struct device *dev, struct device_attribute *attr, char *bu
 {
 	struct scsi_device *sdev;
 	sdev = to_scsi_device(dev);
-	return snprintf(buf, 20, "%u\n", sdev->eh_timeout / HZ);
+	return sysfs_emit(buf, "%u\n", sdev->eh_timeout / HZ);
 }
 
 static ssize_t
@@ -855,7 +856,7 @@ show_state_field(struct device *dev, struct device_attribute *attr, char *buf)
 	if (!name)
 		return -EINVAL;
 
-	return snprintf(buf, 20, "%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 
 static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_state_field, store_state_field);
@@ -870,7 +871,7 @@ show_queue_type_field(struct device *dev, struct device_attribute *attr,
 	if (sdev->simple_tags)
 		name = "simple";
 
-	return snprintf(buf, 20, "%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 
 static ssize_t
@@ -950,7 +951,7 @@ static ssize_t
 show_iostat_counterbits(struct device *dev, struct device_attribute *attr,
 			char *buf)
 {
-	return snprintf(buf, 20, "%d\n", (int)sizeof(atomic_t) * 8);
+	return sysfs_emit(buf, "%d\n", (int)sizeof(atomic_t) * 8);
 }
 
 static DEVICE_ATTR(iocounterbits, S_IRUGO, show_iostat_counterbits, NULL);
@@ -962,7 +963,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr,	\
 {									\
 	struct scsi_device *sdev = to_scsi_device(dev);			\
 	unsigned long long count = atomic_read(&sdev->field);		\
-	return snprintf(buf, 20, "0x%llx\n", count);			\
+	return sysfs_emit(buf, "0x%llx\n", count);			\
 }									\
 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
 
@@ -976,7 +977,7 @@ sdev_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct scsi_device *sdev;
 	sdev = to_scsi_device(dev);
-	return snprintf (buf, 20, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type);
+	return sysfs_emit(buf, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type);
 }
 static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL);
 
@@ -987,7 +988,7 @@ sdev_show_evt_##name(struct device *dev, struct device_attribute *attr,	\
 {									\
 	struct scsi_device *sdev = to_scsi_device(dev);			\
 	int val = test_bit(SDEV_EVT_##Cap_name, sdev->supported_events);\
-	return snprintf(buf, 20, "%d\n", val);				\
+	return sysfs_emit(buf, "%d\n", val);				\
 }
 
 #define DECLARE_EVT_STORE(name, Cap_name)				\
@@ -1089,14 +1090,14 @@ sdev_show_blacklist(struct device *dev, struct device_attribute *attr,
 			name = sdev_bflags_name[i];
 
 		if (name)
-			len += scnprintf(buf + len, PAGE_SIZE - len,
-					 "%s%s", len ? " " : "", name);
+			len += sysfs_emit_at(buf, len,
+					     "%s%s", len ? " " : "", name);
 		else
-			len += scnprintf(buf + len, PAGE_SIZE - len,
-					 "%sINVALID_BIT(%d)", len ? " " : "", i);
+			len += sysfs_emit_at(buf, len,
+					"%sINVALID_BIT(%d)", len ? " " : "", i);
 	}
 	if (len)
-		len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
+		len += sysfs_emit_at(buf, len, "\n");
 	return len;
 }
 static DEVICE_ATTR(blacklist, S_IRUGO, sdev_show_blacklist, NULL);
@@ -1109,9 +1110,9 @@ sdev_show_dh_state(struct device *dev, struct device_attribute *attr,
 	struct scsi_device *sdev = to_scsi_device(dev);
 
 	if (!sdev->handler)
-		return snprintf(buf, 20, "detached\n");
+		return sysfs_emit(buf, "detached\n");
 
-	return snprintf(buf, 20, "%s\n", sdev->handler->name);
+	return sysfs_emit(buf, "%s\n", sdev->handler->name);
 }
 
 static ssize_t
@@ -1169,7 +1170,7 @@ sdev_show_access_state(struct device *dev,
 	access_state = (sdev->access_state & SCSI_ACCESS_STATE_MASK);
 	access_state_name = scsi_access_state_name(access_state);
 
-	return sprintf(buf, "%s\n",
+	return sysfs_emit(buf, "%s\n",
 		       access_state_name ? access_state_name : "unknown");
 }
 static DEVICE_ATTR(access_state, S_IRUGO, sdev_show_access_state, NULL);
@@ -1185,9 +1186,9 @@ sdev_show_preferred_path(struct device *dev,
 		return -EINVAL;
 
 	if (sdev->access_state & SCSI_ACCESS_STATE_PREFERRED)
-		return sprintf(buf, "1\n");
+		return sysfs_emit(buf, "1\n");
 	else
-		return sprintf(buf, "0\n");
+		return sysfs_emit(buf, "0\n");
 }
 static DEVICE_ATTR(preferred_path, S_IRUGO, sdev_show_preferred_path, NULL);
 #endif
@@ -1199,8 +1200,8 @@ sdev_show_queue_ramp_up_period(struct device *dev,
 {
 	struct scsi_device *sdev;
 	sdev = to_scsi_device(dev);
-	return snprintf(buf, 20, "%u\n",
-			jiffies_to_msecs(sdev->queue_ramp_up_period));
+	return sysfs_emit(buf, "%u\n",
+			  jiffies_to_msecs(sdev->queue_ramp_up_period));
 }
 
 static ssize_t
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 21/25] scsi: scsi_transport_fc: Convert sprintf() family to sysfs_emit() family (part 1)
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (18 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 20/25] scsi: core: " Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 22/25] scsi: scsi_transport_fc: Convert sprintf() family to sysfs_emit() family (part 2) Li Zhijian
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/scsi_transport_fc.c | 34 ++++++++++++++++----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index b04075f19445..3335c31772e1 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -1120,7 +1120,7 @@ show_fc_rport_supported_classes (struct device *dev,
 {
 	struct fc_rport *rport = transport_class_to_rport(dev);
 	if (rport->supported_classes == FC_COS_UNSPECIFIED)
-		return snprintf(buf, 20, "unspecified\n");
+		return sysfs_emit(buf, "unspecified\n");
 	return get_fc_cos_names(rport->supported_classes, buf);
 }
 static FC_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
@@ -1215,21 +1215,21 @@ show_fc_rport_roles (struct device *dev, struct device_attribute *attr,
 					FC_WELLKNOWN_PORTID_MASK) {
 		switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) {
 		case FC_FPORT_PORTID:
-			return snprintf(buf, 30, "Fabric Port\n");
+			return sysfs_emit(buf, "Fabric Port\n");
 		case FC_FABCTLR_PORTID:
-			return snprintf(buf, 30, "Fabric Controller\n");
+			return sysfs_emit(buf, "Fabric Controller\n");
 		case FC_DIRSRVR_PORTID:
-			return snprintf(buf, 30, "Directory Server\n");
+			return sysfs_emit(buf, "Directory Server\n");
 		case FC_TIMESRVR_PORTID:
-			return snprintf(buf, 30, "Time Server\n");
+			return sysfs_emit(buf, "Time Server\n");
 		case FC_MGMTSRVR_PORTID:
-			return snprintf(buf, 30, "Management Server\n");
+			return sysfs_emit(buf, "Management Server\n");
 		default:
-			return snprintf(buf, 30, "Unknown Fabric Entity\n");
+			return sysfs_emit(buf, "Unknown Fabric Entity\n");
 		}
 	} else {
 		if (rport->roles == FC_PORT_ROLE_UNKNOWN)
-			return snprintf(buf, 20, "unknown\n");
+			return sysfs_emit(buf, "unknown\n");
 		return get_fc_port_roles_names(rport->roles, buf);
 	}
 }
@@ -1283,7 +1283,7 @@ show_fc_rport_port_state(struct device *dev,
 	if (!name)
 		return -EINVAL;
 
-	return snprintf(buf, 20, "%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 
 static FC_DEVICE_ATTR(rport, port_state, 0444 | 0200,
@@ -1301,8 +1301,8 @@ show_fc_rport_fast_io_fail_tmo (struct device *dev,
 	struct fc_rport *rport = transport_class_to_rport(dev);
 
 	if (rport->fast_io_fail_tmo == -1)
-		return snprintf(buf, 5, "off\n");
-	return snprintf(buf, 20, "%d\n", rport->fast_io_fail_tmo);
+		return sysfs_emit(buf, "off\n");
+	return sysfs_emit(buf, "%d\n", rport->fast_io_fail_tmo);
 }
 
 static ssize_t
@@ -1662,7 +1662,7 @@ show_fc_vport_roles (struct device *dev, struct device_attribute *attr,
 	struct fc_vport *vport = transport_class_to_vport(dev);
 
 	if (vport->roles == FC_PORT_ROLE_UNKNOWN)
-		return snprintf(buf, 20, "unknown\n");
+		return sysfs_emit(buf, "unknown\n");
 	return get_fc_port_roles_names(vport->roles, buf);
 }
 static FC_DEVICE_ATTR(vport, roles, S_IRUGO, show_fc_vport_roles, NULL);
@@ -1888,7 +1888,7 @@ show_fc_host_supported_classes (struct device *dev,
 	struct Scsi_Host *shost = transport_class_to_shost(dev);
 
 	if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED)
-		return snprintf(buf, 20, "unspecified\n");
+		return sysfs_emit(buf, "unspecified\n");
 
 	return get_fc_cos_names(fc_host_supported_classes(shost), buf);
 }
@@ -1912,7 +1912,7 @@ show_fc_host_supported_speeds (struct device *dev,
 	struct Scsi_Host *shost = transport_class_to_shost(dev);
 
 	if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN)
-		return snprintf(buf, 20, "unknown\n");
+		return sysfs_emit(buf, "unknown\n");
 
 	return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf);
 }
@@ -1964,7 +1964,7 @@ show_fc_host_speed (struct device *dev,
 		i->f->get_host_speed(shost);
 
 	if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN)
-		return snprintf(buf, 20, "unknown\n");
+		return sysfs_emit(buf, "unknown\n");
 
 	return get_fc_port_speed_names(fc_host_speed(shost), buf);
 }
@@ -1997,7 +1997,7 @@ show_fc_private_host_tgtid_bind_type(struct device *dev,
 	name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost));
 	if (!name)
 		return -EINVAL;
-	return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name);
+	return sysfs_emit(buf, "%s\n", name);
 }
 
 #define get_list_head_entry(pos, head, member) 		\
@@ -2106,7 +2106,7 @@ fc_stat_show(const struct device *dev, char *buf, unsigned long offset)
 	if (i->f->get_fc_host_stats) {
 		stats = (i->f->get_fc_host_stats)(shost);
 		if (stats)
-			ret = snprintf(buf, 20, "0x%llx\n",
+			ret = sysfs_emit(buf, "0x%llx\n",
 			      (unsigned long long)*(u64 *)(((u8 *) stats) + offset));
 	}
 	return ret;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 22/25] scsi: scsi_transport_fc: Convert sprintf() family to sysfs_emit() family (part 2)
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (19 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 21/25] scsi: scsi_transport_fc: Convert sprintf() family to sysfs_emit() family (part 1) Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 23/25] scsi: scsi_transport_sas: Convert sprintf() family to sysfs_emit() family (part 1) Li Zhijian
                   ` (3 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

This focuses on the abused in macros.

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/scsi_transport_fc.c | 152 +++++++++++++++----------------
 1 file changed, 74 insertions(+), 78 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 3335c31772e1..340cda452b44 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -114,7 +114,6 @@ static struct {
 	{ FC_PORTTYPE_NPIV,		"NPIV VPORT" },
 };
 fc_enum_name_search(port_type, fc_port_type, fc_port_type_names)
-#define FC_PORTTYPE_MAX_NAMELEN		50
 
 /* Reuse fc_port_type enum function for vport_type */
 #define get_fc_vport_type_name get_fc_port_type_name
@@ -166,7 +165,6 @@ static struct {
 };
 fc_enum_name_search(port_state, fc_port_state, fc_port_state_names)
 fc_enum_name_match(port_state, fc_port_state, fc_port_state_names)
-#define FC_PORTSTATE_MAX_NAMELEN	20
 
 
 /* Convert fc_vport_state values to ascii string name */
@@ -186,7 +184,6 @@ static struct {
 	{ FC_VPORT_FAILED,		"VPort Failed" },
 };
 fc_enum_name_search(vport_state, fc_vport_state, fc_vport_state_names)
-#define FC_VPORTSTATE_MAX_NAMELEN	24
 
 /* Reuse fc_vport_state enum function for vport_last_state */
 #define get_fc_vport_last_state_name get_fc_vport_state_name
@@ -983,7 +980,7 @@ static void __exit fc_transport_exit(void)
  * FC Remote Port Attribute Management
  */
 
-#define fc_rport_show_function(field, format_string, sz, cast)		\
+#define fc_rport_show_function(field, format_string, cast)		\
 static ssize_t								\
 show_fc_rport_##field (struct device *dev, 				\
 		       struct device_attribute *attr, char *buf)	\
@@ -996,7 +993,7 @@ show_fc_rport_##field (struct device *dev, 				\
 	      (rport->port_state == FC_PORTSTATE_DELETED) ||		\
 	      (rport->port_state == FC_PORTSTATE_NOTPRESENT)))		\
 		i->f->get_rport_##field(rport);				\
-	return snprintf(buf, sz, format_string, cast rport->field); 	\
+	return sysfs_emit(buf, format_string, cast rport->field); 	\
 }
 
 #define fc_rport_store_function(field)					\
@@ -1021,45 +1018,45 @@ store_fc_rport_##field(struct device *dev,				\
 	return count;							\
 }
 
-#define fc_rport_rd_attr(field, format_string, sz)			\
-	fc_rport_show_function(field, format_string, sz, )		\
+#define fc_rport_rd_attr(field, format_string)			\
+	fc_rport_show_function(field, format_string, )		\
 static FC_DEVICE_ATTR(rport, field, S_IRUGO,			\
 			 show_fc_rport_##field, NULL)
 
-#define fc_rport_rd_attr_cast(field, format_string, sz, cast)		\
-	fc_rport_show_function(field, format_string, sz, (cast))	\
+#define fc_rport_rd_attr_cast(field, format_string, cast)		\
+	fc_rport_show_function(field, format_string, (cast))	\
 static FC_DEVICE_ATTR(rport, field, S_IRUGO,			\
 			  show_fc_rport_##field, NULL)
 
-#define fc_rport_rw_attr(field, format_string, sz)			\
-	fc_rport_show_function(field, format_string, sz, )		\
+#define fc_rport_rw_attr(field, format_string)			\
+	fc_rport_show_function(field, format_string, )		\
 	fc_rport_store_function(field)					\
 static FC_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR,		\
 			show_fc_rport_##field,				\
 			store_fc_rport_##field)
 
 
-#define fc_private_rport_show_function(field, format_string, sz, cast)	\
+#define fc_private_rport_show_function(field, format_string, cast)	\
 static ssize_t								\
 show_fc_rport_##field (struct device *dev, 				\
 		       struct device_attribute *attr, char *buf)	\
 {									\
 	struct fc_rport *rport = transport_class_to_rport(dev);		\
-	return snprintf(buf, sz, format_string, cast rport->field); 	\
+	return sysfs_emit(buf, format_string, cast rport->field); 	\
 }
 
-#define fc_private_rport_rd_attr(field, format_string, sz)		\
-	fc_private_rport_show_function(field, format_string, sz, )	\
+#define fc_private_rport_rd_attr(field, format_string)		\
+	fc_private_rport_show_function(field, format_string, )	\
 static FC_DEVICE_ATTR(rport, field, S_IRUGO,			\
 			 show_fc_rport_##field, NULL)
 
-#define fc_private_rport_rd_attr_cast(field, format_string, sz, cast)	\
-	fc_private_rport_show_function(field, format_string, sz, (cast)) \
+#define fc_private_rport_rd_attr_cast(field, format_string, cast)	\
+	fc_private_rport_show_function(field, format_string, (cast)) \
 static FC_DEVICE_ATTR(rport, field, S_IRUGO,			\
 			  show_fc_rport_##field, NULL)
 
 
-#define fc_private_rport_rd_enum_attr(title, maxlen)			\
+#define fc_private_rport_rd_enum_attr(title)			\
 static ssize_t								\
 show_fc_rport_##title (struct device *dev,				\
 		       struct device_attribute *attr, char *buf)	\
@@ -1069,7 +1066,7 @@ show_fc_rport_##title (struct device *dev,				\
 	name = get_fc_##title##_name(rport->title);			\
 	if (!name)							\
 		return -EINVAL;						\
-	return snprintf(buf, maxlen, "%s\n", name);			\
+	return sysfs_emit(buf, "%s\n", name);			\
 }									\
 static FC_DEVICE_ATTR(rport, title, S_IRUGO,			\
 			show_fc_rport_##title, NULL)
@@ -1112,7 +1109,7 @@ static FC_DEVICE_ATTR(rport, title, S_IRUGO,			\
 
 /* Fixed Remote Port Attributes */
 
-fc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20);
+fc_private_rport_rd_attr(maxframe_size, "%u bytes\n");
 
 static ssize_t
 show_fc_rport_supported_classes (struct device *dev,
@@ -1175,7 +1172,7 @@ static int fc_rport_set_dev_loss_tmo(struct fc_rport *rport,
 	return 0;
 }
 
-fc_rport_show_function(dev_loss_tmo, "%u\n", 20, )
+fc_rport_show_function(dev_loss_tmo, "%u\n", )
 static ssize_t
 store_fc_rport_dev_loss_tmo(struct device *dev, struct device_attribute *attr,
 			    const char *buf, size_t count)
@@ -1199,9 +1196,9 @@ static FC_DEVICE_ATTR(rport, dev_loss_tmo, S_IRUGO | S_IWUSR,
 
 /* Private Remote Port Attributes */
 
-fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
-fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
-fc_private_rport_rd_attr(port_id, "0x%06x\n", 20);
+fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", unsigned long long);
+fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", unsigned long long);
+fc_private_rport_rd_attr(port_id, "0x%06x\n");
 
 static ssize_t
 show_fc_rport_roles (struct device *dev, struct device_attribute *attr,
@@ -1289,7 +1286,7 @@ show_fc_rport_port_state(struct device *dev,
 static FC_DEVICE_ATTR(rport, port_state, 0444 | 0200,
 			show_fc_rport_port_state, fc_rport_set_marginal_state);
 
-fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20);
+fc_private_rport_rd_attr(scsi_target_id, "%d\n");
 
 /*
  * fast_io_fail_tmo attribute
@@ -1346,7 +1343,7 @@ static ssize_t fc_rport_fpinstat_##name(struct device *cd,		\
 {									\
 	struct fc_rport *rport = transport_class_to_rport(cd);		\
 									\
-	return snprintf(buf, 20, "0x%llx\n", rport->fpin_stats.name);	\
+	return sysfs_emit(buf, "0x%llx\n", rport->fpin_stats.name);	\
 }									\
 static FC_DEVICE_ATTR(rport, fpin_##name, 0444, fc_rport_fpinstat_##name, NULL)
 
@@ -1411,7 +1408,7 @@ static struct attribute_group fc_rport_statistics_group = {
  *  involved in sysfs functions. The driver only gets involved if
  *  it's the "old" style that doesn't use rports.
  */
-#define fc_starget_show_function(field, format_string, sz, cast)	\
+#define fc_starget_show_function(field, format_string, cast)	\
 static ssize_t								\
 show_fc_starget_##field (struct device *dev, 				\
 			 struct device_attribute *attr, char *buf)	\
@@ -1424,17 +1421,17 @@ show_fc_starget_##field (struct device *dev, 				\
 		fc_starget_##field(starget) = rport->field;		\
 	else if (i->f->get_starget_##field)				\
 		i->f->get_starget_##field(starget);			\
-	return snprintf(buf, sz, format_string, 			\
+	return sysfs_emit(buf, format_string, 				\
 		cast fc_starget_##field(starget)); 			\
 }
 
-#define fc_starget_rd_attr(field, format_string, sz)			\
-	fc_starget_show_function(field, format_string, sz, )		\
+#define fc_starget_rd_attr(field, format_string)			\
+	fc_starget_show_function(field, format_string, )		\
 static FC_DEVICE_ATTR(starget, field, S_IRUGO,			\
 			 show_fc_starget_##field, NULL)
 
-#define fc_starget_rd_attr_cast(field, format_string, sz, cast)		\
-	fc_starget_show_function(field, format_string, sz, (cast))	\
+#define fc_starget_rd_attr_cast(field, format_string, cast)		\
+	fc_starget_show_function(field, format_string, (cast))	\
 static FC_DEVICE_ATTR(starget, field, S_IRUGO,			\
 			  show_fc_starget_##field, NULL)
 
@@ -1457,9 +1454,9 @@ static FC_DEVICE_ATTR(starget, field, S_IRUGO,			\
 		count++
 
 /* The FC Transport SCSI Target Attributes: */
-fc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
-fc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
-fc_starget_rd_attr(port_id, "0x%06x\n", 20);
+fc_starget_rd_attr_cast(node_name, "0x%llx\n", unsigned long long);
+fc_starget_rd_attr_cast(port_name, "0x%llx\n", unsigned long long);
+fc_starget_rd_attr(port_id, "0x%06x\n");
 
 
 /*
@@ -1477,7 +1474,7 @@ show_fc_vport_##field (struct device *dev, 				\
 	if ((i->f->get_vport_##field) &&				\
 	    !(vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)))	\
 		i->f->get_vport_##field(vport);				\
-	return snprintf(buf, sz, format_string, cast vport->field); 	\
+	return sysfs_emit(buf, format_string, cast vport->field); 	\
 }
 
 #define fc_vport_store_function(field)					\
@@ -1544,7 +1541,7 @@ show_fc_vport_##field (struct device *dev,				\
 		       struct device_attribute *attr, char *buf)	\
 {									\
 	struct fc_vport *vport = transport_class_to_vport(dev);		\
-	return snprintf(buf, sz, format_string, cast vport->field); 	\
+	return sysfs_emit(buf, format_string, cast vport->field); 	\
 }
 
 #define fc_private_vport_store_u32_function(field)			\
@@ -1584,7 +1581,7 @@ static FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR,		\
 			store_fc_vport_##field)
 
 
-#define fc_private_vport_rd_enum_attr(title, maxlen)			\
+#define fc_private_vport_rd_enum_attr(title)			\
 static ssize_t								\
 show_fc_vport_##title (struct device *dev,				\
 		       struct device_attribute *attr,			\
@@ -1595,7 +1592,7 @@ show_fc_vport_##title (struct device *dev,				\
 	name = get_fc_##title##_name(vport->title);			\
 	if (!name)							\
 		return -EINVAL;						\
-	return snprintf(buf, maxlen, "%s\n", name);			\
+	return sysfs_emit(buf, "%s\n", name);			\
 }									\
 static FC_DEVICE_ATTR(vport, title, S_IRUGO,			\
 			show_fc_vport_##title, NULL)
@@ -1650,8 +1647,8 @@ static FC_DEVICE_ATTR(vport, title, S_IRUGO,			\
 
 /* Private Virtual Port Attributes */
 
-fc_private_vport_rd_enum_attr(vport_state, FC_VPORTSTATE_MAX_NAMELEN);
-fc_private_vport_rd_enum_attr(vport_last_state, FC_VPORTSTATE_MAX_NAMELEN);
+fc_private_vport_rd_enum_attr(vport_state);
+fc_private_vport_rd_enum_attr(vport_last_state);
 fc_private_vport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
 fc_private_vport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
 
@@ -1667,7 +1664,7 @@ show_fc_vport_roles (struct device *dev, struct device_attribute *attr,
 }
 static FC_DEVICE_ATTR(vport, roles, S_IRUGO, show_fc_vport_roles, NULL);
 
-fc_private_vport_rd_enum_attr(vport_type, FC_PORTTYPE_MAX_NAMELEN);
+fc_private_vport_rd_enum_attr(vport_type);
 
 fc_private_vport_show_function(symbolic_name, "%s\n",
 		FC_VPORT_SYMBOLIC_NAMELEN + 1, )
@@ -1735,7 +1732,7 @@ static FC_DEVICE_ATTR(vport, vport_disable, S_IWUSR,
  * Host Attribute Management
  */
 
-#define fc_host_show_function(field, format_string, sz, cast)		\
+#define fc_host_show_function(field, format_string, cast)		\
 static ssize_t								\
 show_fc_host_##field (struct device *dev,				\
 		      struct device_attribute *attr, char *buf)		\
@@ -1744,7 +1741,7 @@ show_fc_host_##field (struct device *dev,				\
 	struct fc_internal *i = to_fc_internal(shost->transportt);	\
 	if (i->f->get_host_##field)					\
 		i->f->get_host_##field(shost);				\
-	return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
+	return sysfs_emit(buf, format_string, cast fc_host_##field(shost)); \
 }
 
 #define fc_host_store_function(field)					\
@@ -1785,13 +1782,13 @@ store_fc_host_##field(struct device *dev,				\
 	return count;							\
 }
 
-#define fc_host_rd_attr(field, format_string, sz)			\
-	fc_host_show_function(field, format_string, sz, )		\
+#define fc_host_rd_attr(field, format_string)			\
+	fc_host_show_function(field, format_string, )		\
 static FC_DEVICE_ATTR(host, field, S_IRUGO,			\
 			 show_fc_host_##field, NULL)
 
-#define fc_host_rd_attr_cast(field, format_string, sz, cast)		\
-	fc_host_show_function(field, format_string, sz, (cast))		\
+#define fc_host_rd_attr_cast(field, format_string, cast)		\
+	fc_host_show_function(field, format_string, (cast))		\
 static FC_DEVICE_ATTR(host, field, S_IRUGO,			\
 			  show_fc_host_##field, NULL)
 
@@ -1802,7 +1799,7 @@ static FC_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR,		\
 			show_fc_host_##field,				\
 			store_fc_host_##field)
 
-#define fc_host_rd_enum_attr(title, maxlen)				\
+#define fc_host_rd_enum_attr(title)				\
 static ssize_t								\
 show_fc_host_##title (struct device *dev,				\
 		      struct device_attribute *attr, char *buf)		\
@@ -1815,7 +1812,7 @@ show_fc_host_##title (struct device *dev,				\
 	name = get_fc_##title##_name(fc_host_##title(shost));		\
 	if (!name)							\
 		return -EINVAL;						\
-	return snprintf(buf, maxlen, "%s\n", name);			\
+	return sysfs_emit(buf, "%s\n", name);			\
 }									\
 static FC_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
 
@@ -1845,22 +1842,22 @@ static FC_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
 		count++
 
 
-#define fc_private_host_show_function(field, format_string, sz, cast)	\
+#define fc_private_host_show_function(field, format_string, cast)	\
 static ssize_t								\
 show_fc_host_##field (struct device *dev,				\
 		      struct device_attribute *attr, char *buf)		\
 {									\
 	struct Scsi_Host *shost = transport_class_to_shost(dev);	\
-	return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
+	return sysfs_emit(buf, format_string, cast fc_host_##field(shost)); \
 }
 
-#define fc_private_host_rd_attr(field, format_string, sz)		\
-	fc_private_host_show_function(field, format_string, sz, )	\
+#define fc_private_host_rd_attr(field, format_string)		\
+	fc_private_host_show_function(field, format_string, )	\
 static FC_DEVICE_ATTR(host, field, S_IRUGO,			\
 			 show_fc_host_##field, NULL)
 
-#define fc_private_host_rd_attr_cast(field, format_string, sz, cast)	\
-	fc_private_host_show_function(field, format_string, sz, (cast)) \
+#define fc_private_host_rd_attr_cast(field, format_string, cast)	\
+	fc_private_host_show_function(field, format_string, (cast)) \
 static FC_DEVICE_ATTR(host, field, S_IRUGO,			\
 			  show_fc_host_##field, NULL)
 
@@ -1920,20 +1917,20 @@ static FC_DEVICE_ATTR(host, supported_speeds, S_IRUGO,
 		show_fc_host_supported_speeds, NULL);
 
 
-fc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
-fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
-fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20,
+fc_private_host_rd_attr_cast(node_name, "0x%llx\n", unsigned long long);
+fc_private_host_rd_attr_cast(port_name, "0x%llx\n", unsigned long long);
+fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n",
 			     unsigned long long);
-fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20);
-fc_private_host_rd_attr(max_npiv_vports, "%u\n", 20);
-fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1));
-fc_private_host_rd_attr(manufacturer, "%s\n", FC_SERIAL_NUMBER_SIZE + 1);
-fc_private_host_rd_attr(model, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1);
-fc_private_host_rd_attr(model_description, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1);
-fc_private_host_rd_attr(hardware_version, "%s\n", FC_VERSION_STRING_SIZE + 1);
-fc_private_host_rd_attr(driver_version, "%s\n", FC_VERSION_STRING_SIZE + 1);
-fc_private_host_rd_attr(firmware_version, "%s\n", FC_VERSION_STRING_SIZE + 1);
-fc_private_host_rd_attr(optionrom_version, "%s\n", FC_VERSION_STRING_SIZE + 1);
+fc_private_host_rd_attr(maxframe_size, "%u bytes\n");
+fc_private_host_rd_attr(max_npiv_vports, "%u\n");
+fc_private_host_rd_attr(serial_number, "%s\n");
+fc_private_host_rd_attr(manufacturer, "%s\n");
+fc_private_host_rd_attr(model, "%s\n");
+fc_private_host_rd_attr(model_description, "%s\n");
+fc_private_host_rd_attr(hardware_version, "%s\n");
+fc_private_host_rd_attr(driver_version, "%s\n");
+fc_private_host_rd_attr(firmware_version, "%s\n");
+fc_private_host_rd_attr(optionrom_version, "%s\n");
 
 
 /* Dynamic Host Attributes */
@@ -1972,14 +1969,13 @@ static FC_DEVICE_ATTR(host, speed, S_IRUGO,
 		show_fc_host_speed, NULL);
 
 
-fc_host_rd_attr(port_id, "0x%06x\n", 20);
-fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN);
-fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
-fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
-fc_host_rd_attr(symbolic_name, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1);
+fc_host_rd_attr(port_id, "0x%06x\n");
+fc_host_rd_enum_attr(port_type);
+fc_host_rd_enum_attr(port_state);
+fc_host_rd_attr_cast(fabric_name, "0x%llx\n", unsigned long long);
+fc_host_rd_attr(symbolic_name, "%s\n");
 
-fc_private_host_show_function(system_hostname, "%s\n",
-		FC_SYMBOLIC_NAME_SIZE + 1, )
+fc_private_host_show_function(system_hostname, "%s\n", )
 fc_host_store_str_function(system_hostname, FC_SYMBOLIC_NAME_SIZE)
 static FC_DEVICE_ATTR(host, system_hostname, S_IRUGO | S_IWUSR,
 		show_fc_host_system_hostname, store_fc_host_system_hostname);
@@ -2079,12 +2075,12 @@ store_fc_private_host_dev_loss_tmo(struct device *dev,
 	return count;
 }
 
-fc_private_host_show_function(dev_loss_tmo, "%d\n", 20, );
+fc_private_host_show_function(dev_loss_tmo, "%d\n", );
 static FC_DEVICE_ATTR(host, dev_loss_tmo, S_IRUGO | S_IWUSR,
 		      show_fc_host_dev_loss_tmo,
 		      store_fc_private_host_dev_loss_tmo);
 
-fc_private_host_rd_attr(npiv_vports_inuse, "%u\n", 20);
+fc_private_host_rd_attr(npiv_vports_inuse, "%u\n");
 
 /*
  * Host Statistics Management
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 23/25] scsi: scsi_transport_sas: Convert sprintf() family to sysfs_emit() family (part 1)
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (20 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 22/25] scsi: scsi_transport_fc: Convert sprintf() family to sysfs_emit() family (part 2) Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 24/25] scsi: scsi_transport_sas: Convert sprintf() family to sysfs_emit() family (part 2) Li Zhijian
                   ` (2 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/scsi_transport_sas.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index d704c484a251..baf2aaf361d2 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -522,7 +522,7 @@ show_sas_device_type(struct device *dev,
 	struct sas_phy *phy = transport_class_to_phy(dev);
 
 	if (!phy->identify.device_type)
-		return snprintf(buf, 20, "none\n");
+		return sysfs_emit(buf, "none\n");
 	return get_sas_device_type_names(phy->identify.device_type, buf);
 }
 static DEVICE_ATTR(device_type, S_IRUGO, show_sas_device_type, NULL);
@@ -569,7 +569,7 @@ show_sas_phy_enable(struct device *dev, struct device_attribute *attr,
 {
 	struct sas_phy *phy = transport_class_to_phy(dev);
 
-	return snprintf(buf, 20, "%d\n", phy->enabled);
+	return sysfs_emit(buf, "%d\n", phy->enabled);
 }
 
 static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, show_sas_phy_enable,
@@ -1177,7 +1177,7 @@ show_sas_rphy_device_type(struct device *dev,
 	struct sas_rphy *rphy = transport_class_to_rphy(dev);
 
 	if (!rphy->identify.device_type)
-		return snprintf(buf, 20, "none\n");
+		return sysfs_emit(buf, "none\n");
 	return get_sas_device_type_names(
 			rphy->identify.device_type, buf);
 }
@@ -1199,7 +1199,7 @@ show_sas_rphy_enclosure_identifier(struct device *dev,
 	error = i->f->get_enclosure_identifier(rphy, &identifier);
 	if (error)
 		return error;
-	return sprintf(buf, "0x%llx\n", (unsigned long long)identifier);
+	return sysfs_emit(buf, "0x%llx\n", (unsigned long long)identifier);
 }
 
 static SAS_DEVICE_ATTR(rphy, enclosure_identifier, S_IRUGO,
@@ -1218,7 +1218,7 @@ show_sas_rphy_bay_identifier(struct device *dev,
 	val = i->f->get_bay_identifier(rphy);
 	if (val < 0)
 		return val;
-	return sprintf(buf, "%d\n", val);
+	return sysfs_emit(buf, "%d\n", val);
 }
 
 static SAS_DEVICE_ATTR(rphy, bay_identifier, S_IRUGO,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 24/25] scsi: scsi_transport_sas: Convert sprintf() family to sysfs_emit() family (part 2)
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (21 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 23/25] scsi: scsi_transport_sas: Convert sprintf() family to sysfs_emit() family (part 1) Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-03-19  6:31 ` [PATCH v2 25/25] scsi: ibmvscsi: Convert sprintf() family to sysfs_emit() family Li Zhijian
  2024-04-12  2:05 ` (subset) [PATCH v2 01/25] scsi: aacraid: " Martin K. Petersen
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, James E.J. Bottomley, Martin K. Petersen, linux-scsi

This focuses on the abused cases in macros.

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" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/scsi_transport_sas.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index baf2aaf361d2..21d3b13c543a 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -427,7 +427,7 @@ show_sas_phy_##name(struct device *dev, 				\
 {									\
 	struct sas_phy *phy = transport_class_to_phy(dev);		\
 									\
-	return snprintf(buf, 20, format_string, cast phy->field);	\
+	return sysfs_emit(buf, format_string, cast phy->field);		\
 }
 
 #define sas_phy_simple_attr(field, name, format_string, type)		\
@@ -442,7 +442,7 @@ show_sas_phy_##name(struct device *dev, 				\
 	struct sas_phy *phy = transport_class_to_phy(dev);		\
 									\
 	if (!phy->field)						\
-		return snprintf(buf, 20, "none\n");			\
+		return sysfs_emit(buf, "none\n");			\
 	return get_sas_protocol_names(phy->field, buf);		\
 }
 
@@ -507,7 +507,7 @@ show_sas_phy_##field(struct device *dev, 				\
 	error = i->f->get_linkerrors ? i->f->get_linkerrors(phy) : 0;	\
 	if (error)							\
 		return error;						\
-	return snprintf(buf, 20, "%u\n", phy->field);			\
+	return sysfs_emit(buf, "%u\n", phy->field);			\
 }
 
 #define sas_phy_linkerror_attr(field)					\
@@ -798,7 +798,7 @@ show_sas_port_##name(struct device *dev, 				\
 {									\
 	struct sas_port *port = transport_class_to_sas_port(dev);	\
 									\
-	return snprintf(buf, 20, format_string, cast port->field);	\
+	return sysfs_emit(buf, format_string, cast port->field);	\
 }
 
 #define sas_port_simple_attr(field, name, format_string, type)		\
@@ -1145,7 +1145,7 @@ show_sas_rphy_##name(struct device *dev, 				\
 {									\
 	struct sas_rphy *rphy = transport_class_to_rphy(dev);		\
 									\
-	return snprintf(buf, 20, format_string, cast rphy->field);	\
+	return sysfs_emit(buf, format_string, cast rphy->field);	\
 }
 
 #define sas_rphy_simple_attr(field, name, format_string, type)		\
@@ -1161,7 +1161,7 @@ show_sas_rphy_##name(struct device *dev, 				\
 	struct sas_rphy *rphy = transport_class_to_rphy(dev);		\
 									\
 	if (!rphy->field)					\
-		return snprintf(buf, 20, "none\n");			\
+		return sysfs_emit(buf, "none\n");			\
 	return get_sas_protocol_names(rphy->field, buf);	\
 }
 
@@ -1280,7 +1280,7 @@ show_sas_end_dev_##name(struct device *dev, 				\
 	struct sas_rphy *rphy = transport_class_to_rphy(dev);		\
 	struct sas_end_device *rdev = rphy_to_end_device(rphy);		\
 									\
-	return snprintf(buf, 20, format_string, cast rdev->field);	\
+	return sysfs_emit(buf, format_string, cast rdev->field);	\
 }
 
 #define sas_end_dev_simple_attr(field, name, format_string, type)	\
@@ -1309,7 +1309,7 @@ show_sas_expander_##name(struct device *dev, 				\
 	struct sas_rphy *rphy = transport_class_to_rphy(dev);		\
 	struct sas_expander_device *edev = rphy_to_expander_device(rphy); \
 									\
-	return snprintf(buf, 20, format_string, cast edev->field);	\
+	return sysfs_emit(buf, format_string, cast edev->field);	\
 }
 
 #define sas_expander_simple_attr(field, name, format_string, type)	\
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2 25/25] scsi: ibmvscsi: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (22 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 24/25] scsi: scsi_transport_sas: Convert sprintf() family to sysfs_emit() family (part 2) Li Zhijian
@ 2024-03-19  6:31 ` Li Zhijian
  2024-04-12  2:05 ` (subset) [PATCH v2 01/25] scsi: aacraid: " Martin K. Petersen
  24 siblings, 0 replies; 27+ messages in thread
From: Li Zhijian @ 2024-03-19  6:31 UTC (permalink / raw
  To: linux-kernel
  Cc: Li Zhijian, Tyrel Datwyler, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy, Aneesh Kumar K.V, Naveen N. Rao,
	James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	linuxppc-dev

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: Tyrel Datwyler <tyreld@linux.ibm.com>
CC: Michael Ellerman <mpe@ellerman.id.au>
CC: Nicholas Piggin <npiggin@gmail.com>
CC: Christophe Leroy <christophe.leroy@csgroup.eu>
CC: "Aneesh Kumar K.V" <aneesh.kumar@kernel.org>
CC: "Naveen N. Rao" <naveen.n.rao@linux.ibm.com>
CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: linux-scsi@vger.kernel.org
CC: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
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/20240116041129.3937800-1-lizhijian@fujitsu.com/
---
 drivers/scsi/ibmvscsi/ibmvscsi.c | 38 +++++++++-----------------------
 1 file changed, 10 insertions(+), 28 deletions(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 71f3e9563520..d6f205d30dcd 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -1904,11 +1904,8 @@ static ssize_t show_host_vhost_loc(struct device *dev,
 {
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct ibmvscsi_host_data *hostdata = shost_priv(shost);
-	int len;
 
-	len = snprintf(buf, sizeof(hostdata->caps.loc), "%s\n",
-		       hostdata->caps.loc);
-	return len;
+	return sysfs_emit(buf, "%s\n", hostdata->caps.loc);
 }
 
 static struct device_attribute ibmvscsi_host_vhost_loc = {
@@ -1924,11 +1921,8 @@ static ssize_t show_host_vhost_name(struct device *dev,
 {
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct ibmvscsi_host_data *hostdata = shost_priv(shost);
-	int len;
 
-	len = snprintf(buf, sizeof(hostdata->caps.name), "%s\n",
-		       hostdata->caps.name);
-	return len;
+	return sysfs_emit(buf, "%s\n", hostdata->caps.name);
 }
 
 static struct device_attribute ibmvscsi_host_vhost_name = {
@@ -1944,11 +1938,8 @@ static ssize_t show_host_srp_version(struct device *dev,
 {
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct ibmvscsi_host_data *hostdata = shost_priv(shost);
-	int len;
 
-	len = snprintf(buf, PAGE_SIZE, "%s\n",
-		       hostdata->madapter_info.srp_version);
-	return len;
+	return sysfs_emit(buf, "%s\n", hostdata->madapter_info.srp_version);
 }
 
 static struct device_attribute ibmvscsi_host_srp_version = {
@@ -1965,11 +1956,8 @@ static ssize_t show_host_partition_name(struct device *dev,
 {
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct ibmvscsi_host_data *hostdata = shost_priv(shost);
-	int len;
 
-	len = snprintf(buf, PAGE_SIZE, "%s\n",
-		       hostdata->madapter_info.partition_name);
-	return len;
+	return sysfs_emit(buf, "%s\n", hostdata->madapter_info.partition_name);
 }
 
 static struct device_attribute ibmvscsi_host_partition_name = {
@@ -1986,11 +1974,9 @@ static ssize_t show_host_partition_number(struct device *dev,
 {
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct ibmvscsi_host_data *hostdata = shost_priv(shost);
-	int len;
 
-	len = snprintf(buf, PAGE_SIZE, "%d\n",
-		       be32_to_cpu(hostdata->madapter_info.partition_number));
-	return len;
+	return sysfs_emit(buf, "%d\n",
+			 be32_to_cpu(hostdata->madapter_info.partition_number));
 }
 
 static struct device_attribute ibmvscsi_host_partition_number = {
@@ -2006,11 +1992,9 @@ static ssize_t show_host_mad_version(struct device *dev,
 {
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct ibmvscsi_host_data *hostdata = shost_priv(shost);
-	int len;
 
-	len = snprintf(buf, PAGE_SIZE, "%d\n",
-		       be32_to_cpu(hostdata->madapter_info.mad_version));
-	return len;
+	return sysfs_emit(buf, "%d\n",
+			 be32_to_cpu(hostdata->madapter_info.mad_version));
 }
 
 static struct device_attribute ibmvscsi_host_mad_version = {
@@ -2026,11 +2010,9 @@ static ssize_t show_host_os_type(struct device *dev,
 {
 	struct Scsi_Host *shost = class_to_shost(dev);
 	struct ibmvscsi_host_data *hostdata = shost_priv(shost);
-	int len;
 
-	len = snprintf(buf, PAGE_SIZE, "%d\n",
-		       be32_to_cpu(hostdata->madapter_info.os_type));
-	return len;
+	return sysfs_emit(buf, "%d\n",
+			 be32_to_cpu(hostdata->madapter_info.os_type));
 }
 
 static struct device_attribute ibmvscsi_host_os_type = {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* RE: [PATCH v2 12/25] scsi: snic: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 ` [PATCH v2 12/25] scsi: snic: " Li Zhijian
@ 2024-03-19 23:39   ` Karan Tilak Kumar (kartilak)
  0 siblings, 0 replies; 27+ messages in thread
From: Karan Tilak Kumar (kartilak) @ 2024-03-19 23:39 UTC (permalink / raw
  To: Li Zhijian, linux-kernel@vger.kernel.org
  Cc: Sesidhar Baddela (sebaddel), James E.J. Bottomley,
	Martin K. Petersen, linux-scsi@vger.kernel.org

On Monday, March 18, 2024 11:31 PM, Li Zhijian <lizhijian@fujitsu.com> 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.
>
> 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: Karan Tilak Kumar <kartilak@cisco.com>
> CC: Sesidhar Baddela <sebaddel@cisco.com>
> CC: "James E.J. Bottomley" <jejb@linux.ibm.com>
> CC: "Martin K. Petersen" <martin.petersen@oracle.com>
> CC: linux-scsi@vger.kernel.org
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> 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/20240116041129.3937800-1-lizhijian@fujitsu.com/
> ---
> drivers/scsi/snic/snic_attrs.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/scsi/snic/snic_attrs.c b/drivers/scsi/snic/snic_attrs.c index 3ddbdbc3ded1..48bf82d042b4 100644
> --- a/drivers/scsi/snic/snic_attrs.c
> +++ b/drivers/scsi/snic/snic_attrs.c
> @@ -13,7 +13,7 @@ snic_show_sym_name(struct device *dev,  {
> struct snic *snic = shost_priv(class_to_shost(dev));
>
> -     return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
> +     return sysfs_emit(buf, "%s\n", snic->name);
> }
>
> static ssize_t
> @@ -23,8 +23,7 @@ snic_show_state(struct device *dev,  {
> struct snic *snic = shost_priv(class_to_shost(dev));
>
> -     return snprintf(buf, PAGE_SIZE, "%s\n",
> -                     snic_state_str[snic_get_state(snic)]);
> +     return sysfs_emit(buf, "%s\n", snic_state_str[snic_get_state(snic)]);
> }
>
> static ssize_t
> @@ -32,7 +31,7 @@ snic_show_drv_version(struct device *dev,
> struct device_attribute *attr,
> char *buf)
> {
> -     return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
> +     return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION);
> }
>
> static ssize_t
> @@ -45,8 +44,8 @@ snic_show_link_state(struct device *dev,
> if (snic->config.xpt_type == SNIC_DAS)
> snic->link_status = svnic_dev_link_status(snic->vdev);
>
> -     return snprintf(buf, PAGE_SIZE, "%s\n",
> -                     (snic->link_status) ? "Link Up" : "Link Down");
> +     return sysfs_emit(buf, "%s\n",
> +                       (snic->link_status) ? "Link Up" : "Link Down");
> }
>
> static DEVICE_ATTR(snic_sym_name, S_IRUGO, snic_show_sym_name, NULL);
> --
> 2.29.2
>
>

Reviewed-by: Karan Tilak Kumar <kartilak@cisco.com>

Regards,
Karan

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: (subset) [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family
  2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
                   ` (23 preceding siblings ...)
  2024-03-19  6:31 ` [PATCH v2 25/25] scsi: ibmvscsi: Convert sprintf() family to sysfs_emit() family Li Zhijian
@ 2024-04-12  2:05 ` Martin K. Petersen
  24 siblings, 0 replies; 27+ messages in thread
From: Martin K. Petersen @ 2024-04-12  2:05 UTC (permalink / raw
  To: linux-kernel, Li Zhijian
  Cc: Martin K . Petersen, Adaptec OEM Raid Solutions,
	James E.J. Bottomley, linux-scsi

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2024-04-12  2:05 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-19  6:31 [PATCH v2 01/25] scsi: aacraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
2024-03-19  6:31 ` [PATCH v2 02/25] scsi: aic94xx: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 03/25] scsi: arcmsr: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 04/25] scsi: be2iscsi: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 05/25] scsi: fcoe: Convert sprintf() family to sysfs_emit() family (part 1) Li Zhijian
2024-03-19  6:31 ` [PATCH v2 06/25] scsi: fcoe: Convert sprintf() family to sysfs_emit() family (part 2) Li Zhijian
2024-03-19  6:31 ` [PATCH v2 07/25] scsi: megaraid: Convert sprintf() family to sysfs_emit() family Li Zhijian
2024-03-19  6:31 ` [PATCH v2 08/25] scsi: mpt3sas: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 09/25] scsi: pcmcia: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 10/25] scsi: qla4xxx: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 11/25] scsi: smartpqi: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 12/25] scsi: snic: " Li Zhijian
2024-03-19 23:39   ` Karan Tilak Kumar (kartilak)
2024-03-19  6:31 ` [PATCH v2 13/25] scsi: hpsa: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 14/25] scsi: hptiop: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 15/25] scsi: ipr: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 16/25] scsi: myrb,myrs: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 17/25] scsi: ncr53c8xx: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 18/25] scsi: pmcraid: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 19/25] scsi: st: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 20/25] scsi: core: " Li Zhijian
2024-03-19  6:31 ` [PATCH v2 21/25] scsi: scsi_transport_fc: Convert sprintf() family to sysfs_emit() family (part 1) Li Zhijian
2024-03-19  6:31 ` [PATCH v2 22/25] scsi: scsi_transport_fc: Convert sprintf() family to sysfs_emit() family (part 2) Li Zhijian
2024-03-19  6:31 ` [PATCH v2 23/25] scsi: scsi_transport_sas: Convert sprintf() family to sysfs_emit() family (part 1) Li Zhijian
2024-03-19  6:31 ` [PATCH v2 24/25] scsi: scsi_transport_sas: Convert sprintf() family to sysfs_emit() family (part 2) Li Zhijian
2024-03-19  6:31 ` [PATCH v2 25/25] scsi: ibmvscsi: Convert sprintf() family to sysfs_emit() family Li Zhijian
2024-04-12  2:05 ` (subset) [PATCH v2 01/25] scsi: aacraid: " Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).