[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240319063132.1588443-25-lizhijian@fujitsu.com>
Date: Tue, 19 Mar 2024 14:31:32 +0800
From: Li Zhijian <lizhijian@...itsu.com>
To: linux-kernel@...r.kernel.org
Cc: Li Zhijian <lizhijian@...itsu.com>,
Tyrel Datwyler <tyreld@...ux.ibm.com>,
Michael Ellerman <mpe@...erman.id.au>,
Nicholas Piggin <npiggin@...il.com>,
Christophe Leroy <christophe.leroy@...roup.eu>,
"Aneesh Kumar K.V" <aneesh.kumar@...nel.org>,
"Naveen N. Rao" <naveen.n.rao@...ux.ibm.com>,
"James E.J. Bottomley" <jejb@...ux.ibm.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
linux-scsi@...r.kernel.org,
linuxppc-dev@...ts.ozlabs.org
Subject: [PATCH v2 25/25] scsi: ibmvscsi: 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: Tyrel Datwyler <tyreld@...ux.ibm.com>
CC: Michael Ellerman <mpe@...erman.id.au>
CC: Nicholas Piggin <npiggin@...il.com>
CC: Christophe Leroy <christophe.leroy@...roup.eu>
CC: "Aneesh Kumar K.V" <aneesh.kumar@...nel.org>
CC: "Naveen N. Rao" <naveen.n.rao@...ux.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
CC: linuxppc-dev@...ts.ozlabs.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/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
Powered by blists - more mailing lists