diff mbox series

[1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings

Message ID 20231226114507.2447118-1-yanjun.zhu@intel.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [1/1] virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1113 this patch: 1113
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 1140 this patch: 1140
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1140
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Zhu Yanjun Dec. 26, 2023, 11:45 a.m. UTC
From: Zhu Yanjun <yanjun.zhu@linux.dev>

Fix a warning when building virtio_net driver.

Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
---
 drivers/net/virtio_net.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Zhu Yanjun Dec. 26, 2023, 11:53 a.m. UTC | #1
The warnings are as below:

"

drivers/net/virtio_net.c: In function ‘init_vqs’:
drivers/net/virtio_net.c:4551:48: warning: ‘%d’ directive writing 
between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
  4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
       |                                                ^~
In function ‘virtnet_find_vqs’,
     inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
drivers/net/virtio_net.c:4551:41: note: directive argument in the range 
[-2147483643, 65534]
  4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
       |                                         ^~~~~~~~~~
drivers/net/virtio_net.c:4551:17: note: ‘sprintf’ output between 8 and 
18 bytes into a destination of size 16
  4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/virtio_net.c: In function ‘init_vqs’:
drivers/net/virtio_net.c:4552:49: warning: ‘%d’ directive writing 
between 1 and 11 bytes into a region of size 9 [-Wformat-overflow=]
  4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
       |                                                 ^~
In function ‘virtnet_find_vqs’,
     inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
drivers/net/virtio_net.c:4552:41: note: directive argument in the range 
[-2147483643, 65534]
  4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
       |                                         ^~~~~~~~~~~
drivers/net/virtio_net.c:4552:17: note: ‘sprintf’ output between 9 and 
19 bytes into a destination of size 16
  4552 |                 sprintf(vi->sq[i].name, "output.%d", i);

"

Please review.

Best Regards,

Zhu Yanjun

在 2023/12/26 19:45, Zhu Yanjun 写道:
> From: Zhu Yanjun <yanjun.zhu@linux.dev>
>
> Fix a warning when building virtio_net driver.
>
> Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
> ---
>   drivers/net/virtio_net.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 49625638ad43..cf57eddf768a 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -4508,10 +4508,11 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
>   {
>   	vq_callback_t **callbacks;
>   	struct virtqueue **vqs;
> -	int ret = -ENOMEM;
> -	int i, total_vqs;
>   	const char **names;
> +	int ret = -ENOMEM;
> +	int total_vqs;
>   	bool *ctx;
> +	u16 i;
>   
>   	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
>   	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
Xuan Zhuo Dec. 26, 2023, 12:43 p.m. UTC | #2
On Tue, 26 Dec 2023 19:53:58 +0800, Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
> The warnings are as below:
>
> "
>
> drivers/net/virtio_net.c: In function ‘init_vqs’:
> drivers/net/virtio_net.c:4551:48: warning: ‘%d’ directive writing
> between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
>   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
>        |                                                ^~
> In function ‘virtnet_find_vqs’,
>      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> drivers/net/virtio_net.c:4551:41: note: directive argument in the range
> [-2147483643, 65534]
>   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
>        |                                         ^~~~~~~~~~
> drivers/net/virtio_net.c:4551:17: note: ‘sprintf’ output between 8 and
> 18 bytes into a destination of size 16
>   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
>        |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/net/virtio_net.c: In function ‘init_vqs’:
> drivers/net/virtio_net.c:4552:49: warning: ‘%d’ directive writing
> between 1 and 11 bytes into a region of size 9 [-Wformat-overflow=]
>   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
>        |                                                 ^~
> In function ‘virtnet_find_vqs’,
>      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> drivers/net/virtio_net.c:4552:41: note: directive argument in the range
> [-2147483643, 65534]
>   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
>        |                                         ^~~~~~~~~~~
> drivers/net/virtio_net.c:4552:17: note: ‘sprintf’ output between 9 and
> 19 bytes into a destination of size 16
>   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
>
> "
>
> Please review.

Please put this to the git msg.

Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>

Thanks.



>
> Best Regards,
>
> Zhu Yanjun
>
> 在 2023/12/26 19:45, Zhu Yanjun 写道:
> > From: Zhu Yanjun <yanjun.zhu@linux.dev>
> >
> > Fix a warning when building virtio_net driver.
> >
> > Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
> > ---
> >   drivers/net/virtio_net.c | 5 +++--
> >   1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 49625638ad43..cf57eddf768a 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -4508,10 +4508,11 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >   {
> >   	vq_callback_t **callbacks;
> >   	struct virtqueue **vqs;
> > -	int ret = -ENOMEM;
> > -	int i, total_vqs;
> >   	const char **names;
> > +	int ret = -ENOMEM;
> > +	int total_vqs;
> >   	bool *ctx;
> > +	u16 i;
> >
> >   	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
> >   	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
Stephen Hemminger Dec. 26, 2023, 6:01 p.m. UTC | #3
On Tue, 26 Dec 2023 19:53:58 +0800
Zhu Yanjun <yanjun.zhu@linux.dev> wrote:

> The warnings are as below:
> 
> "
> 
> drivers/net/virtio_net.c: In function ‘init_vqs’:
> drivers/net/virtio_net.c:4551:48: warning: ‘%d’ directive writing 
> between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
>   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
>        |                                                ^~
> In function ‘virtnet_find_vqs’,
>      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> drivers/net/virtio_net.c:4551:41: note: directive argument in the range 
> [-2147483643, 65534]
>   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
>        |                                         ^~~~~~~~~~
> drivers/net/virtio_net.c:4551:17: note: ‘sprintf’ output between 8 and 
> 18 bytes into a destination of size 16
>   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
>        |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/net/virtio_net.c: In function ‘init_vqs’:
> drivers/net/virtio_net.c:4552:49: warning: ‘%d’ directive writing 
> between 1 and 11 bytes into a region of size 9 [-Wformat-overflow=]
>   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
>        |                                                 ^~
> In function ‘virtnet_find_vqs’,
>      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> drivers/net/virtio_net.c:4552:41: note: directive argument in the range 
> [-2147483643, 65534]
>   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
>        |                                         ^~~~~~~~~~~
> drivers/net/virtio_net.c:4552:17: note: ‘sprintf’ output between 9 and 
> 19 bytes into a destination of size 16
>   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
> 
> "
> 
> Please review.
> 
> Best Regards,
> 
> Zhu Yanjun
> 
> 在 2023/12/26 19:45, Zhu Yanjun 写道:
> > From: Zhu Yanjun <yanjun.zhu@linux.dev>
> >
> > Fix a warning when building virtio_net driver.
> >
> > Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
> > ---
> >   drivers/net/virtio_net.c | 5 +++--
> >   1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 49625638ad43..cf57eddf768a 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -4508,10 +4508,11 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> >   {
> >   	vq_callback_t **callbacks;
> >   	struct virtqueue **vqs;
> > -	int ret = -ENOMEM;
> > -	int i, total_vqs;
> >   	const char **names;
> > +	int ret = -ENOMEM;
> > +	int total_vqs;
> >   	bool *ctx;
> > +	u16 i;
> >   
> >   	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
> >   	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by  
> 

If you change the variable type to u16, then the format string should no
longer use %d. Instead should be %u
Michael S. Tsirkin Dec. 26, 2023, 6:11 p.m. UTC | #4
On Tue, Dec 26, 2023 at 10:01:13AM -0800, Stephen Hemminger wrote:
> On Tue, 26 Dec 2023 19:53:58 +0800
> Zhu Yanjun <yanjun.zhu@linux.dev> wrote:
> 
> > The warnings are as below:
> > 
> > "
> > 
> > drivers/net/virtio_net.c: In function ‘init_vqs’:
> > drivers/net/virtio_net.c:4551:48: warning: ‘%d’ directive writing 
> > between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
> >   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
> >        |                                                ^~
> > In function ‘virtnet_find_vqs’,
> >      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> > drivers/net/virtio_net.c:4551:41: note: directive argument in the range 
> > [-2147483643, 65534]
> >   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
> >        |                                         ^~~~~~~~~~
> > drivers/net/virtio_net.c:4551:17: note: ‘sprintf’ output between 8 and 
> > 18 bytes into a destination of size 16
> >   4551 |                 sprintf(vi->rq[i].name, "input.%d", i);
> >        |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > drivers/net/virtio_net.c: In function ‘init_vqs’:
> > drivers/net/virtio_net.c:4552:49: warning: ‘%d’ directive writing 
> > between 1 and 11 bytes into a region of size 9 [-Wformat-overflow=]
> >   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
> >        |                                                 ^~
> > In function ‘virtnet_find_vqs’,
> >      inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:
> > drivers/net/virtio_net.c:4552:41: note: directive argument in the range 
> > [-2147483643, 65534]
> >   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
> >        |                                         ^~~~~~~~~~~
> > drivers/net/virtio_net.c:4552:17: note: ‘sprintf’ output between 9 and 
> > 19 bytes into a destination of size 16
> >   4552 |                 sprintf(vi->sq[i].name, "output.%d", i);
> > 
> > "
> > 
> > Please review.
> > 
> > Best Regards,
> > 
> > Zhu Yanjun
> > 
> > 在 2023/12/26 19:45, Zhu Yanjun 写道:
> > > From: Zhu Yanjun <yanjun.zhu@linux.dev>
> > >
> > > Fix a warning when building virtio_net driver.
> > >
> > > Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
> > > ---
> > >   drivers/net/virtio_net.c | 5 +++--
> > >   1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > > index 49625638ad43..cf57eddf768a 100644
> > > --- a/drivers/net/virtio_net.c
> > > +++ b/drivers/net/virtio_net.c
> > > @@ -4508,10 +4508,11 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
> > >   {
> > >   	vq_callback_t **callbacks;
> > >   	struct virtqueue **vqs;
> > > -	int ret = -ENOMEM;
> > > -	int i, total_vqs;
> > >   	const char **names;
> > > +	int ret = -ENOMEM;
> > > +	int total_vqs;
> > >   	bool *ctx;
> > > +	u16 i;
> > >   
> > >   	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
> > >   	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by  
> > 
> 
> If you change the variable type to u16, then the format string should no
> longer use %d. Instead should be %u

I would just use unsigned FWIW. But it doesn't matter the range is
limited here. It's just that the compiler can't figure it out.
diff mbox series

Patch

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 49625638ad43..cf57eddf768a 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -4508,10 +4508,11 @@  static int virtnet_find_vqs(struct virtnet_info *vi)
 {
 	vq_callback_t **callbacks;
 	struct virtqueue **vqs;
-	int ret = -ENOMEM;
-	int i, total_vqs;
 	const char **names;
+	int ret = -ENOMEM;
+	int total_vqs;
 	bool *ctx;
+	u16 i;
 
 	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
 	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by