@@ -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 = {
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(-)