* [PATCH] virtio-blk: fixup coccinelle warnings
@ 2021-10-21 6:51 cgel.zte
2021-10-21 7:08 ` Joe Perches
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: cgel.zte @ 2021-10-21 6:51 UTC (permalink / raw)
To: mst
Cc: jasowang, pbonzini, stefanha, axboe, virtualization, linux-block,
linux-kernel, Ye Guojin, Zeal Robot
From: Ye Guojin <ye.guojin@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 or sprintf makes more sense.
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Ye Guojin <ye.guojin@zte.com.cn>
---
drivers/block/virtio_blk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 303caf2d17d0..8a71b2f9f4b7 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -624,7 +624,7 @@ cache_type_show(struct device *dev, struct device_attribute *attr, char *buf)
u8 writeback = virtblk_get_cache_mode(vblk->vdev);
BUG_ON(writeback >= ARRAY_SIZE(virtblk_cache_types));
- return snprintf(buf, 40, "%s\n", virtblk_cache_types[writeback]);
+ return sysfs_emit(buf, "%s\n", virtblk_cache_types[writeback]);
}
static DEVICE_ATTR_RW(cache_type);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio-blk: fixup coccinelle warnings
2021-10-21 6:51 [PATCH] virtio-blk: fixup coccinelle warnings cgel.zte
@ 2021-10-21 7:08 ` Joe Perches
2021-10-21 9:15 ` Stefan Hajnoczi
2021-10-21 9:13 ` Stefan Hajnoczi
2021-10-21 14:35 ` Stefano Garzarella
2 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2021-10-21 7:08 UTC (permalink / raw)
To: cgel.zte, mst, Denis Efremov, Julia Lawall, Gilles Muller,
Nicolas Palix, Michal Marek, cocci
Cc: jasowang, pbonzini, stefanha, axboe, virtualization, linux-block,
linux-kernel, Ye Guojin, Zeal Robot
On Thu, 2021-10-21 at 06:51 +0000, cgel.zte@gmail.com wrote:
> From: Ye Guojin <ye.guojin@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 or sprintf makes more sense.
[]
> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
[]
> @@ -624,7 +624,7 @@ cache_type_show(struct device *dev, struct device_attribute *attr, char *buf)
> - return snprintf(buf, 40, "%s\n", virtblk_cache_types[writeback]);
> + return sysfs_emit(buf, "%s\n", virtblk_cache_types[writeback]);
Perhaps scripts/coccinelle/api/device_attr_show.cocci should be updated
to be more like the script used in commit 1c7fd72687d6
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio-blk: fixup coccinelle warnings
2021-10-21 6:51 [PATCH] virtio-blk: fixup coccinelle warnings cgel.zte
2021-10-21 7:08 ` Joe Perches
@ 2021-10-21 9:13 ` Stefan Hajnoczi
2021-10-21 14:35 ` Stefano Garzarella
2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2021-10-21 9:13 UTC (permalink / raw)
To: cgel.zte
Cc: mst, jasowang, pbonzini, axboe, virtualization, linux-block,
linux-kernel, Ye Guojin, Zeal Robot
[-- Attachment #1: Type: text/plain, Size: 555 bytes --]
On Thu, Oct 21, 2021 at 06:51:11AM +0000, cgel.zte@gmail.com wrote:
> From: Ye Guojin <ye.guojin@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 or sprintf makes more sense.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Ye Guojin <ye.guojin@zte.com.cn>
> ---
> drivers/block/virtio_blk.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio-blk: fixup coccinelle warnings
2021-10-21 7:08 ` Joe Perches
@ 2021-10-21 9:15 ` Stefan Hajnoczi
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2021-10-21 9:15 UTC (permalink / raw)
To: Joe Perches
Cc: cgel.zte, mst, Denis Efremov, Julia Lawall, Gilles Muller,
Nicolas Palix, Michal Marek, cocci, jasowang, pbonzini, axboe,
virtualization, linux-block, linux-kernel, Ye Guojin, Zeal Robot
[-- Attachment #1: Type: text/plain, Size: 1111 bytes --]
On Thu, Oct 21, 2021 at 12:08:23AM -0700, Joe Perches wrote:
> On Thu, 2021-10-21 at 06:51 +0000, cgel.zte@gmail.com wrote:
> > From: Ye Guojin <ye.guojin@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 or sprintf makes more sense.
> []
> > diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> []
> > @@ -624,7 +624,7 @@ cache_type_show(struct device *dev, struct device_attribute *attr, char *buf)
> > - return snprintf(buf, 40, "%s\n", virtblk_cache_types[writeback]);
> > + return sysfs_emit(buf, "%s\n", virtblk_cache_types[writeback]);
>
> Perhaps scripts/coccinelle/api/device_attr_show.cocci should be updated
> to be more like the script used in commit 1c7fd72687d6
This won't catch the case covered by the patch because it's
"snprintf(buf, 40" instead of "snprintf(buf, PAGE_SIZE", although
any size that's not PAGE_SIZE needs to be reviewed carefully in case the
intent of the statement is to truncate the output.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio-blk: fixup coccinelle warnings
2021-10-21 6:51 [PATCH] virtio-blk: fixup coccinelle warnings cgel.zte
2021-10-21 7:08 ` Joe Perches
2021-10-21 9:13 ` Stefan Hajnoczi
@ 2021-10-21 14:35 ` Stefano Garzarella
2 siblings, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2021-10-21 14:35 UTC (permalink / raw)
To: cgel.zte
Cc: mst, jasowang, pbonzini, stefanha, axboe, virtualization,
linux-block, linux-kernel, Ye Guojin, Zeal Robot
On Thu, Oct 21, 2021 at 06:51:11AM +0000, cgel.zte@gmail.com wrote:
>From: Ye Guojin <ye.guojin@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 or sprintf makes more sense.
>
>Reported-by: Zeal Robot <zealci@zte.com.cn>
>Signed-off-by: Ye Guojin <ye.guojin@zte.com.cn>
>---
> drivers/block/virtio_blk.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-10-21 14:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 6:51 [PATCH] virtio-blk: fixup coccinelle warnings cgel.zte
2021-10-21 7:08 ` Joe Perches
2021-10-21 9:15 ` Stefan Hajnoczi
2021-10-21 9:13 ` Stefan Hajnoczi
2021-10-21 14:35 ` Stefano Garzarella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).