* [PATCH] scsi: snic: Replace snprintf in show functions with sysfs_emit
@ 2021-11-05 8:14 cgel.zte
2021-11-07 16:13 ` Joe Perches
0 siblings, 1 reply; 2+ messages in thread
From: cgel.zte @ 2021-11-05 8:14 UTC (permalink / raw)
To: kartilak
Cc: sebaddel, jejb, martin.petersen, linux-scsi, linux-kernel,
Jing Yao, Zeal Robot
From: Jing Yao <yao.jing2@zte.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@zte.com.cn>
Signed-off-by: Jing Yao <yao.jing2@zte.com.cn>
---
drivers/scsi/snic/snic_attrs.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/snic/snic_attrs.c b/drivers/scsi/snic/snic_attrs.c
index dc03ce1ec909..cb501be3e9ec 100644
--- a/drivers/scsi/snic/snic_attrs.c
+++ b/drivers/scsi/snic/snic_attrs.c
@@ -27,7 +27,7 @@ snic_show_sym_name(struct device *dev,
{
struct snic *snic = shost_priv(class_to_shost(dev));
- return snprintf(buf, PAGE_SIZE, "%s\n", snic->name);
+ return sysfs_emit(buf, "%s\n", snic->name);
}
static ssize_t
@@ -37,7 +37,7 @@ snic_show_state(struct device *dev,
{
struct snic *snic = shost_priv(class_to_shost(dev));
- return snprintf(buf, PAGE_SIZE, "%s\n",
+ return sysfs_emit(buf, "%s\n",
snic_state_str[snic_get_state(snic)]);
}
@@ -46,7 +46,7 @@ snic_show_drv_version(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%s\n", SNIC_DRV_VERSION);
+ return sysfs_emit(buf, "%s\n", SNIC_DRV_VERSION);
}
static ssize_t
@@ -59,7 +59,7 @@ snic_show_link_state(struct device *dev,
if (snic->config.xpt_type == SNIC_DAS)
snic->link_status = svnic_dev_link_status(snic->vdev);
- return snprintf(buf, PAGE_SIZE, "%s\n",
+ return sysfs_emit(buf, "%s\n",
(snic->link_status) ? "Link Up" : "Link Down");
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] scsi: snic: Replace snprintf in show functions with sysfs_emit
2021-11-05 8:14 [PATCH] scsi: snic: Replace snprintf in show functions with sysfs_emit cgel.zte
@ 2021-11-07 16:13 ` Joe Perches
0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2021-11-07 16:13 UTC (permalink / raw)
To: cgel.zte, kartilak
Cc: sebaddel, jejb, martin.petersen, linux-scsi, linux-kernel,
Jing Yao, Zeal Robot
On Fri, 2021-11-05 at 08:14 +0000, cgel.zte@gmail.com wrote:
> From: Jing Yao <yao.jing2@zte.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.
[]
> diff --git a/drivers/scsi/snic/snic_attrs.c b/drivers/scsi/snic/snic_attrs.c
[]
> @@ -37,7 +37,7 @@ snic_show_state(struct device *dev,
> {
> struct snic *snic = shost_priv(class_to_shost(dev));
>
> - return snprintf(buf, PAGE_SIZE, "%s\n",
> + return sysfs_emit(buf, "%s\n",
> snic_state_str[snic_get_state(snic)]);
> }
when you do these, please consider the ability to rewrap to 80 columns.
return sysfs_emit(buf, "%s\n", snic_state_str[snic_get_state(snic)]);
> @@ -59,7 +59,7 @@ snic_show_link_state(struct device *dev,
> if (snic->config.xpt_type == SNIC_DAS)
> snic->link_status = svnic_dev_link_status(snic->vdev);
>
> - return snprintf(buf, PAGE_SIZE, "%s\n",
> + return sysfs_emit(buf, "%s\n",
> (snic->link_status) ? "Link Up" : "Link Down");
And maintain parenthesis alignment
return sysfs_emit(buf, "%s\n",
snic->link_status ? "Link Up" : "Link Down");
or maybe
return sysfs_emit(buf, "Link %s\n", snic->link_status ? "Up" : "Down");
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-07 16:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 8:14 [PATCH] scsi: snic: Replace snprintf in show functions with sysfs_emit cgel.zte
2021-11-07 16:13 ` Joe Perches
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.