lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240319063132.1588443-15-lizhijian@fujitsu.com>
Date: Tue, 19 Mar 2024 14:31:22 +0800
From: Li Zhijian <lizhijian@...itsu.com>
To: linux-kernel@...r.kernel.org
Cc: Li Zhijian <lizhijian@...itsu.com>,
	Brian King <brking@...ibm.com>,
	"James E.J. Bottomley" <jejb@...ux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@...cle.com>,
	linux-scsi@...r.kernel.org
Subject: [PATCH v2 15/25] scsi: ipr: Convert sprintf() family to sysfs_emit() family

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

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

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

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

No functional change intended

CC: Brian King <brking@...ibm.com>
CC: "James E.J. Bottomley" <jejb@...ux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@...cle.com>
CC: linux-scsi@...r.kernel.org
Signed-off-by: Li Zhijian <lizhijian@...itsu.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ