linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools: hv: Fix a complier warning in the fcopy uio daemon
@ 2024-09-10  0:44 Dexuan Cui
  2024-09-13  7:30 ` Saurabh Singh Sengar
  2024-12-07  7:45 ` Wei Liu
  0 siblings, 2 replies; 6+ messages in thread
From: Dexuan Cui @ 2024-09-10  0:44 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Long Li,
	Greg Kroah-Hartman, Saurabh Sengar,
	open list:Hyper-V/Azure CORE AND DRIVERS, open list
  Cc: stable

hv_fcopy_uio_daemon.c:436:53: warning: '%s' directive output may be truncated
writing up to 14 bytes into a region of size 10 [-Wformat-truncation=]
  436 |  snprintf(uio_dev_path, sizeof(uio_dev_path), "/dev/%s", uio_name);

Also added 'static' for the array 'desc[]'.

Fixes: 82b0945ce2c2 ("tools: hv: Add new fcopy application based on uio driver")
Cc: stable@vger.kernel.org # 6.10+
Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 tools/hv/hv_fcopy_uio_daemon.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/tools/hv/hv_fcopy_uio_daemon.c b/tools/hv/hv_fcopy_uio_daemon.c
index 3ce316cc9f97..f7741af08a79 100644
--- a/tools/hv/hv_fcopy_uio_daemon.c
+++ b/tools/hv/hv_fcopy_uio_daemon.c
@@ -35,8 +35,6 @@
 #define WIN8_SRV_MINOR		1
 #define WIN8_SRV_VERSION	(WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)
 
-#define MAX_FOLDER_NAME		15
-#define MAX_PATH_LEN		15
 #define FCOPY_UIO		"/sys/bus/vmbus/devices/eb765408-105f-49b6-b4aa-c123b64d17d4/uio"
 
 #define FCOPY_VER_COUNT		1
@@ -51,7 +49,7 @@ static const int fw_versions[] = {
 
 #define HV_RING_SIZE		0x4000 /* 16KB ring buffer size */
 
-unsigned char desc[HV_RING_SIZE];
+static unsigned char desc[HV_RING_SIZE];
 
 static int target_fd;
 static char target_fname[PATH_MAX];
@@ -402,8 +400,8 @@ int main(int argc, char *argv[])
 	struct vmbus_br txbr, rxbr;
 	void *ring;
 	uint32_t len = HV_RING_SIZE;
-	char uio_name[MAX_FOLDER_NAME] = {0};
-	char uio_dev_path[MAX_PATH_LEN] = {0};
+	char uio_name[NAME_MAX] = {0};
+	char uio_dev_path[PATH_MAX] = {0};
 
 	static struct option long_options[] = {
 		{"help",	no_argument,	   0,  'h' },
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] tools: hv: Fix a complier warning in the fcopy uio daemon
  2024-09-10  0:44 [PATCH] tools: hv: Fix a complier warning in the fcopy uio daemon Dexuan Cui
@ 2024-09-13  7:30 ` Saurabh Singh Sengar
  2024-09-21  1:23   ` Dexuan Cui
  2024-12-07  7:45 ` Wei Liu
  1 sibling, 1 reply; 6+ messages in thread
From: Saurabh Singh Sengar @ 2024-09-13  7:30 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Long Li,
	Greg Kroah-Hartman, open list:Hyper-V/Azure CORE AND DRIVERS,
	open list, stable

On Tue, Sep 10, 2024 at 12:44:32AM +0000, Dexuan Cui wrote:
> hv_fcopy_uio_daemon.c:436:53: warning: '%s' directive output may be truncated
> writing up to 14 bytes into a region of size 10 [-Wformat-truncation=]
>   436 |  snprintf(uio_dev_path, sizeof(uio_dev_path), "/dev/%s", uio_name);

Makefile today doesn't have -Wformat-truncation flag enabled, I tried to add
-Wformat-truncation=2 but I don't see any error in this file.

Do you mind sharing more details how you get this error ?

- Saurabh


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH] tools: hv: Fix a complier warning in the fcopy uio daemon
  2024-09-13  7:30 ` Saurabh Singh Sengar
@ 2024-09-21  1:23   ` Dexuan Cui
  2024-09-24 18:22     ` Saurabh Singh Sengar
  0 siblings, 1 reply; 6+ messages in thread
From: Dexuan Cui @ 2024-09-21  1:23 UTC (permalink / raw)
  To: Saurabh Singh Sengar
  Cc: KY Srinivasan, Haiyang Zhang, Wei Liu, Long Li,
	Greg Kroah-Hartman, open list:Hyper-V/Azure CORE AND DRIVERS,
	open list, stable@vger.kernel.org

> From: Saurabh Singh Sengar <ssengar@linux.microsoft.com>
> Sent: Friday, September 13, 2024 12:31 AM
> To: Dexuan Cui <decui@microsoft.com>
> Cc: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>; Wei Liu <wei.liu@kernel.org>; Long Li
> <longli@microsoft.com>; Greg Kroah-Hartman
> <gregkh@linuxfoundation.org>; open list:Hyper-V/Azure CORE AND DRIVERS
> <linux-hyperv@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>;
> stable@vger.kernel.org
> Subject: Re: [PATCH] tools: hv: Fix a complier warning in the fcopy uio
> daemon
> 
> On Tue, Sep 10, 2024 at 12:44:32AM +0000, Dexuan Cui wrote:
> > hv_fcopy_uio_daemon.c:436:53: warning: '%s' directive output may be
> truncated
> > writing up to 14 bytes into a region of size 10 [-Wformat-truncation=]
> >   436 |  snprintf(uio_dev_path, sizeof(uio_dev_path), "/dev/%s",
> uio_name);
> 
> Makefile today doesn't have -Wformat-truncation flag enabled, I tried to add
> -Wformat-truncation=2 but I don't see any error in this file.
> 
> Do you mind sharing more details how you get this error ?
> 
> - Saurabh

This repros in a Ubuntu 20.04 VM:

root@decui-u2004-2024-0920:~/linux/tools/hv# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
...

root@decui-u2004-2024-0920:~/linux/tools/hv# gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@decui-u2004-2024-0920:~/linux/tools/hv# make clean; make
...
make -f /root/linux/tools/build/Makefile.build dir=. obj=hv_fcopy_uio_daemon
make[1]: Entering directory '/root/linux/tools/hv'
  CC      hv_fcopy_uio_daemon.o
hv_fcopy_uio_daemon.c: In function 'main':
hv_fcopy_uio_daemon.c:443:53: warning: '%s' directive output may be truncated writing up to 14 bytes into a region of size 10 [-Wformat-truncation=]
  443 |  snprintf(uio_dev_path, sizeof(uio_dev_path), "/dev/%s", uio_name);
      |                                                     ^~   ~~~~~~~~
In file included from /usr/include/stdio.h:867,
                 from hv_fcopy_uio_daemon.c:20:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk' output between 6 and 20 bytes into a destination of size 15
   67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CC      vmbus_bufring.o
  LD      hv_fcopy_uio_daemon-in.o
make[1]: Leaving directory '/root/linux/tools/hv'
  LINK    hv_fcopy_uio_daemon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tools: hv: Fix a complier warning in the fcopy uio daemon
  2024-09-21  1:23   ` Dexuan Cui
@ 2024-09-24 18:22     ` Saurabh Singh Sengar
  2024-09-26  4:01       ` Saurabh Singh Sengar
  0 siblings, 1 reply; 6+ messages in thread
From: Saurabh Singh Sengar @ 2024-09-24 18:22 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: KY Srinivasan, Haiyang Zhang, Wei Liu, Long Li,
	Greg Kroah-Hartman, open list:Hyper-V/Azure CORE AND DRIVERS,
	open list, stable@vger.kernel.org

On Sat, Sep 21, 2024 at 01:23:09AM +0000, Dexuan Cui wrote:
> > From: Saurabh Singh Sengar <ssengar@linux.microsoft.com>
> > Sent: Friday, September 13, 2024 12:31 AM
> > To: Dexuan Cui <decui@microsoft.com>
> > Cc: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang
> > <haiyangz@microsoft.com>; Wei Liu <wei.liu@kernel.org>; Long Li
> > <longli@microsoft.com>; Greg Kroah-Hartman
> > <gregkh@linuxfoundation.org>; open list:Hyper-V/Azure CORE AND DRIVERS
> > <linux-hyperv@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>;
> > stable@vger.kernel.org
> > Subject: Re: [PATCH] tools: hv: Fix a complier warning in the fcopy uio
> > daemon
> > 
> > On Tue, Sep 10, 2024 at 12:44:32AM +0000, Dexuan Cui wrote:
> > > hv_fcopy_uio_daemon.c:436:53: warning: '%s' directive output may be
> > truncated
> > > writing up to 14 bytes into a region of size 10 [-Wformat-truncation=]
> > >   436 |  snprintf(uio_dev_path, sizeof(uio_dev_path), "/dev/%s",
> > uio_name);
> > 
> > Makefile today doesn't have -Wformat-truncation flag enabled, I tried to add
> > -Wformat-truncation=2 but I don't see any error in this file.
> > 
> > Do you mind sharing more details how you get this error ?
> > 
> > - Saurabh
> 
> This repros in a Ubuntu 20.04 VM:
> 
> root@decui-u2004-2024-0920:~/linux/tools/hv# cat /etc/os-release
> NAME="Ubuntu"
> VERSION="20.04.6 LTS (Focal Fossa)"
> ...
> 
> root@decui-u2004-2024-0920:~/linux/tools/hv# gcc --version
> gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
> Copyright (C) 2019 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> root@decui-u2004-2024-0920:~/linux/tools/hv# make clean; make
> ...
> make -f /root/linux/tools/build/Makefile.build dir=. obj=hv_fcopy_uio_daemon
> make[1]: Entering directory '/root/linux/tools/hv'
>   CC      hv_fcopy_uio_daemon.o
> hv_fcopy_uio_daemon.c: In function 'main':
> hv_fcopy_uio_daemon.c:443:53: warning: '%s' directive output may be truncated writing up to 14 bytes into a region of size 10 [-Wformat-truncation=]
>   443 |  snprintf(uio_dev_path, sizeof(uio_dev_path), "/dev/%s", uio_name);
>       |                                                     ^~   ~~~~~~~~
> In file included from /usr/include/stdio.h:867,
>                  from hv_fcopy_uio_daemon.c:20:
> /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk' output between 6 and 20 bytes into a destination of size 15
>    67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    68 |        __bos (__s), __fmt, __va_arg_pack ());
>       |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   CC      vmbus_bufring.o
>   LD      hv_fcopy_uio_daemon-in.o
> make[1]: Leaving directory '/root/linux/tools/hv'
>   LINK    hv_fcopy_uio_daemon

Thanks for the details. Looks this is the behaviour of old gcc versions.
How about fixing it like this :

--- a/tools/hv/hv_fcopy_uio_daemon.c
+++ b/tools/hv/hv_fcopy_uio_daemon.c
@@ -35,7 +35,7 @@
 #define WIN8_SRV_MINOR         1
 #define WIN8_SRV_VERSION       (WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)

-#define MAX_FOLDER_NAME                15
+#define MAX_FOLDER_NAME                10
 #define MAX_PATH_LEN           15


- Saurabh


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tools: hv: Fix a complier warning in the fcopy uio daemon
  2024-09-24 18:22     ` Saurabh Singh Sengar
@ 2024-09-26  4:01       ` Saurabh Singh Sengar
  0 siblings, 0 replies; 6+ messages in thread
From: Saurabh Singh Sengar @ 2024-09-26  4:01 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: KY Srinivasan, Haiyang Zhang, Wei Liu, Long Li,
	Greg Kroah-Hartman, open list:Hyper-V/Azure CORE AND DRIVERS,
	open list, stable@vger.kernel.org

On Tue, Sep 24, 2024 at 11:22:50AM -0700, Saurabh Singh Sengar wrote:
> On Sat, Sep 21, 2024 at 01:23:09AM +0000, Dexuan Cui wrote:
> > > From: Saurabh Singh Sengar <ssengar@linux.microsoft.com>
> > > Sent: Friday, September 13, 2024 12:31 AM
> > > To: Dexuan Cui <decui@microsoft.com>
> > > Cc: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang
> > > <haiyangz@microsoft.com>; Wei Liu <wei.liu@kernel.org>; Long Li
> > > <longli@microsoft.com>; Greg Kroah-Hartman
> > > <gregkh@linuxfoundation.org>; open list:Hyper-V/Azure CORE AND DRIVERS
> > > <linux-hyperv@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>;
> > > stable@vger.kernel.org
> > > Subject: Re: [PATCH] tools: hv: Fix a complier warning in the fcopy uio
> > > daemon
> > > 
> > > On Tue, Sep 10, 2024 at 12:44:32AM +0000, Dexuan Cui wrote:
> > > > hv_fcopy_uio_daemon.c:436:53: warning: '%s' directive output may be
> > > truncated
> > > > writing up to 14 bytes into a region of size 10 [-Wformat-truncation=]
> > > >   436 |  snprintf(uio_dev_path, sizeof(uio_dev_path), "/dev/%s",
> > > uio_name);
> > > 
> > > Makefile today doesn't have -Wformat-truncation flag enabled, I tried to add
> > > -Wformat-truncation=2 but I don't see any error in this file.
> > > 
> > > Do you mind sharing more details how you get this error ?
> > > 
> > > - Saurabh
> > 
> > This repros in a Ubuntu 20.04 VM:
> > 
> > root@decui-u2004-2024-0920:~/linux/tools/hv# cat /etc/os-release
> > NAME="Ubuntu"
> > VERSION="20.04.6 LTS (Focal Fossa)"
> > ...
> > 
> > root@decui-u2004-2024-0920:~/linux/tools/hv# gcc --version
> > gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
> > Copyright (C) 2019 Free Software Foundation, Inc.
> > This is free software; see the source for copying conditions.  There is NO
> > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> > 
> > root@decui-u2004-2024-0920:~/linux/tools/hv# make clean; make
> > ...
> > make -f /root/linux/tools/build/Makefile.build dir=. obj=hv_fcopy_uio_daemon
> > make[1]: Entering directory '/root/linux/tools/hv'
> >   CC      hv_fcopy_uio_daemon.o
> > hv_fcopy_uio_daemon.c: In function 'main':
> > hv_fcopy_uio_daemon.c:443:53: warning: '%s' directive output may be truncated writing up to 14 bytes into a region of size 10 [-Wformat-truncation=]
> >   443 |  snprintf(uio_dev_path, sizeof(uio_dev_path), "/dev/%s", uio_name);
> >       |                                                     ^~   ~~~~~~~~
> > In file included from /usr/include/stdio.h:867,
> >                  from hv_fcopy_uio_daemon.c:20:
> > /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk' output between 6 and 20 bytes into a destination of size 15
> >    67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
> >       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >    68 |        __bos (__s), __fmt, __va_arg_pack ());
> >       |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >   CC      vmbus_bufring.o
> >   LD      hv_fcopy_uio_daemon-in.o
> > make[1]: Leaving directory '/root/linux/tools/hv'
> >   LINK    hv_fcopy_uio_daemon
> 
> Thanks for the details. Looks this is the behaviour of old gcc versions.
> How about fixing it like this :
> 
> --- a/tools/hv/hv_fcopy_uio_daemon.c
> +++ b/tools/hv/hv_fcopy_uio_daemon.c
> @@ -35,7 +35,7 @@
>  #define WIN8_SRV_MINOR         1
>  #define WIN8_SRV_VERSION       (WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)
> 
> -#define MAX_FOLDER_NAME                15
> +#define MAX_FOLDER_NAME                10
>  #define MAX_PATH_LEN           15
> 
> 

Had a offline discussion with Dexuan.
The above suggested approach saves few bytes of userspace memory,
using standard macros for path and folder length would be
preferable for better code readability


Please add,
Reviewed-by: Saurabh Sengar <ssengar@linux.microsoft.com>

- Saurabh



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tools: hv: Fix a complier warning in the fcopy uio daemon
  2024-09-10  0:44 [PATCH] tools: hv: Fix a complier warning in the fcopy uio daemon Dexuan Cui
  2024-09-13  7:30 ` Saurabh Singh Sengar
@ 2024-12-07  7:45 ` Wei Liu
  1 sibling, 0 replies; 6+ messages in thread
From: Wei Liu @ 2024-12-07  7:45 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Long Li,
	Greg Kroah-Hartman, Saurabh Sengar,
	open list:Hyper-V/Azure CORE AND DRIVERS, open list, stable

On Tue, Sep 10, 2024 at 12:44:32AM +0000, Dexuan Cui wrote:
> hv_fcopy_uio_daemon.c:436:53: warning: '%s' directive output may be truncated
> writing up to 14 bytes into a region of size 10 [-Wformat-truncation=]
>   436 |  snprintf(uio_dev_path, sizeof(uio_dev_path), "/dev/%s", uio_name);
> 
> Also added 'static' for the array 'desc[]'.
> 
> Fixes: 82b0945ce2c2 ("tools: hv: Add new fcopy application based on uio driver")
> Cc: stable@vger.kernel.org # 6.10+
> Signed-off-by: Dexuan Cui <decui@microsoft.com>

Applied to hyperv-fixes. Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-12-07  7:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-10  0:44 [PATCH] tools: hv: Fix a complier warning in the fcopy uio daemon Dexuan Cui
2024-09-13  7:30 ` Saurabh Singh Sengar
2024-09-21  1:23   ` Dexuan Cui
2024-09-24 18:22     ` Saurabh Singh Sengar
2024-09-26  4:01       ` Saurabh Singh Sengar
2024-12-07  7:45 ` Wei Liu

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).