[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20211105082153.77120-1-yao.jing2@zte.com.cn>
Date: Fri, 5 Nov 2021 08:21:53 +0000
From: cgel.zte@...il.com
To: jejb@...ux.ibm.com
Cc: martin.petersen@...cle.com, linux-scsi@...r.kernel.org,
linux-kernel@...r.kernel.org, Jing Yao <yao.jing2@....com.cn>,
Zeal Robot <zealci@....com.cn>
Subject: [PATCH] scsi: scsi_transport_fc: Replace snprintf in show functions with sysfs_emit
From: Jing Yao <yao.jing2@....com.cn>
coccicheck complains about the use of snprintf() in sysfs show
functions:
WARNING use scnprintf or sprintf
Use sysfs_emit instead of scnprintf, snprintf or sprintf makes more
sense.
Reported-by: Zeal Robot <zealci@....com.cn>
Signed-off-by: Jing Yao <yao.jing2@....com.cn>
---
drivers/scsi/scsi_transport_fc.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 60e406bcf42a..42a1fe6f4bd6 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -1122,7 +1122,7 @@ show_fc_rport_supported_classes (struct device *dev,
{
struct fc_rport *rport = transport_class_to_rport(dev);
if (rport->supported_classes == FC_COS_UNSPECIFIED)
- return snprintf(buf, 20, "unspecified\n");
+ return sysfs_emit(buf, "unspecified\n");
return get_fc_cos_names(rport->supported_classes, buf);
}
static FC_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
@@ -1217,21 +1217,21 @@ show_fc_rport_roles (struct device *dev, struct device_attribute *attr,
FC_WELLKNOWN_PORTID_MASK) {
switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) {
case FC_FPORT_PORTID:
- return snprintf(buf, 30, "Fabric Port\n");
+ return sysfs_emit(buf, "Fabric Port\n");
case FC_FABCTLR_PORTID:
- return snprintf(buf, 30, "Fabric Controller\n");
+ return sysfs_emit(buf, "Fabric Controller\n");
case FC_DIRSRVR_PORTID:
- return snprintf(buf, 30, "Directory Server\n");
+ return sysfs_emit(buf, "Directory Server\n");
case FC_TIMESRVR_PORTID:
- return snprintf(buf, 30, "Time Server\n");
+ return sysfs_emit(buf, "Time Server\n");
case FC_MGMTSRVR_PORTID:
- return snprintf(buf, 30, "Management Server\n");
+ return sysfs_emit(buf, "Management Server\n");
default:
- return snprintf(buf, 30, "Unknown Fabric Entity\n");
+ return sysfs_emit(buf, "Unknown Fabric Entity\n");
}
} else {
if (rport->roles == FC_PORT_ROLE_UNKNOWN)
- return snprintf(buf, 20, "unknown\n");
+ return sysfs_emit(buf, "unknown\n");
return get_fc_port_roles_names(rport->roles, buf);
}
}
@@ -1285,7 +1285,7 @@ show_fc_rport_port_state(struct device *dev,
if (!name)
return -EINVAL;
- return snprintf(buf, 20, "%s\n", name);
+ return sysfs_emit(buf, "%s\n", name);
}
static FC_DEVICE_ATTR(rport, port_state, 0444 | 0200,
@@ -1303,8 +1303,8 @@ show_fc_rport_fast_io_fail_tmo (struct device *dev,
struct fc_rport *rport = transport_class_to_rport(dev);
if (rport->fast_io_fail_tmo == -1)
- return snprintf(buf, 5, "off\n");
- return snprintf(buf, 20, "%d\n", rport->fast_io_fail_tmo);
+ return sysfs_emit(buf, "off\n");
+ return sysfs_emit(buf, "%d\n", rport->fast_io_fail_tmo);
}
static ssize_t
@@ -1664,7 +1664,7 @@ show_fc_vport_roles (struct device *dev, struct device_attribute *attr,
struct fc_vport *vport = transport_class_to_vport(dev);
if (vport->roles == FC_PORT_ROLE_UNKNOWN)
- return snprintf(buf, 20, "unknown\n");
+ return sysfs_emit(buf, "unknown\n");
return get_fc_port_roles_names(vport->roles, buf);
}
static FC_DEVICE_ATTR(vport, roles, S_IRUGO, show_fc_vport_roles, NULL);
@@ -1890,7 +1890,7 @@ show_fc_host_supported_classes (struct device *dev,
struct Scsi_Host *shost = transport_class_to_shost(dev);
if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED)
- return snprintf(buf, 20, "unspecified\n");
+ return sysfs_emit(buf, "unspecified\n");
return get_fc_cos_names(fc_host_supported_classes(shost), buf);
}
@@ -1914,7 +1914,7 @@ show_fc_host_supported_speeds (struct device *dev,
struct Scsi_Host *shost = transport_class_to_shost(dev);
if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN)
- return snprintf(buf, 20, "unknown\n");
+ return sysfs_emit(buf, "unknown\n");
return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf);
}
@@ -1966,7 +1966,7 @@ show_fc_host_speed (struct device *dev,
i->f->get_host_speed(shost);
if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN)
- return snprintf(buf, 20, "unknown\n");
+ return sysfs_emit(buf, "unknown\n");
return get_fc_port_speed_names(fc_host_speed(shost), buf);
}
--
2.25.1
Powered by blists - more mailing lists