[PATCH v2 25/25] scsi: ibmvscsi: Convert sprintf() family to sysfs_emit() family

From: Li Zhijian
Date: Tue Mar 19 2024 - 02:39:35 EST


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@xxxxxxxxxxxxx>
CC: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
CC: Nicholas Piggin <npiggin@xxxxxxxxx>
CC: Christophe Leroy <christophe.leroy@xxxxxxxxxx>
CC: "Aneesh Kumar K.V" <aneesh.kumar@xxxxxxxxxx>
CC: "Naveen N. Rao" <naveen.n.rao@xxxxxxxxxxxxx>
CC: "James E.J. Bottomley" <jejb@xxxxxxxxxxxxx>
CC: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>
CC: linux-scsi@xxxxxxxxxxxxxxx
CC: linuxppc-dev@xxxxxxxxxxxxxxxx
Signed-off-by: Li Zhijian <lizhijian@xxxxxxxxxxx>
---
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@xxxxxxxxxxx/
---
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