From: Deepak R Varma <drv@mailo.com>
To: "James E.J. Bottomley" <jejb@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Saurabh Singh Sengar <ssengar@microsoft.com>,
Praveen Kumar <kumarpraveen@linux.microsoft.com>,
Deepak R Varma <drv@mailo.com>
Subject: [PATCH] scsi: scsi_transport_fc: Use sysfs_emit in show function callsbacks
Date: Sat, 24 Dec 2022 01:33:12 +0530 [thread overview]
Message-ID: <Y6YJgNv0GbdcPq2w@qemulion> (raw)
According to Documentation/filesystems/sysfs.rst, the show() callback
function of kobject attributes should strictly use sysfs_emit() instead
of sprintf() family functions. Also, merge split lines wherever possible
due to shortened length of lines.
Issue identified using the coccinelle device_attr_show.cocci script.
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
drivers/scsi/scsi_transport_fc.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 0965f8a7134f..ace0df098774 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -1117,7 +1117,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,
@@ -1212,21 +1212,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);
}
}
@@ -1280,7 +1280,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,
@@ -1298,8 +1298,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
@@ -1659,7 +1659,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);
@@ -1885,7 +1885,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);
}
@@ -1909,7 +1909,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);
}
@@ -1961,7 +1961,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);
}
@@ -1994,7 +1994,7 @@ show_fc_private_host_tgtid_bind_type(struct device *dev,
name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost));
if (!name)
return -EINVAL;
- return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name);
+ return sysfs_emit(buf, "%s\n", name);
}
#define get_list_head_entry(pos, head, member) \
--
2.34.1
reply other threads:[~2022-12-23 20:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y6YJgNv0GbdcPq2w@qemulion \
--to=drv@mailo.com \
--cc=jejb@linux.ibm.com \
--cc=kumarpraveen@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=ssengar@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox