[PATCH v2 25/25] scsi: ibmvscsi: Convert sprintf() family to sysfs_emit() family
From: Li Zhijian <hidden>
Date: 2024-03-19 06:32:41
Also in:
linux-scsi, lkml
Subsystem:
ibm power virtual scsi device drivers, linux for powerpc (32-bit and 64-bit), scsi subsystem, the rest · Maintainers:
Tyrel Datwyler, Madhavan Srinivasan, "James E.J. Bottomley", "Martin K. Petersen", Linus Torvalds
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 <redacted> CC: "Aneesh Kumar K.V" <aneesh.kumar@kernel.org> CC: "Naveen N. Rao" <redacted> CC: "James E.J. Bottomley" <redacted> CC: "Martin K. Petersen" <redacted> CC: linux-scsi@vger.kernel.org CC: linuxppc-dev@lists.ozlabs.org Signed-off-by: Li Zhijian <redacted> --- 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/ (local) --- 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