DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/mana: avoid the use of variable length array
@ 2025-03-05  0:37 longli
  2025-03-05  9:00 ` Morten Brørup
  2025-03-06  2:17 ` Andre Muezerie
  0 siblings, 2 replies; 3+ messages in thread
From: longli @ 2025-03-05  0:37 UTC (permalink / raw)
  To: Stephen Hemminger, Wei Hu; +Cc: dev, Long Li

From: Long Li <longli@microsoft.com>

The pathname can be defined as name[MAX_PATH]. This makes the driver
compilable using MSVC.

Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/net/mana/mana.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/mana/mana.c b/drivers/net/mana/mana.c
index c37c4e3444..d12dff6ce1 100644
--- a/drivers/net/mana/mana.c
+++ b/drivers/net/mana/mana.c
@@ -36,11 +36,8 @@ static rte_spinlock_t mana_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
 
 /* Allocate a buffer on the stack and fill it with a printf format string. */
 #define MANA_MKSTR(name, ...) \
-	int mkstr_size_##name = snprintf(NULL, 0, "" __VA_ARGS__); \
-	char name[mkstr_size_##name + 1]; \
-	\
-	memset(name, 0, mkstr_size_##name + 1); \
-	snprintf(name, sizeof(name), "" __VA_ARGS__)
+	char name[PATH_MAX]; \
+	snprintf(name, PATH_MAX, "" __VA_ARGS__)
 
 int mana_logtype_driver;
 int mana_logtype_init;
-- 
2.34.1


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

* RE: [PATCH] net/mana: avoid the use of variable length array
  2025-03-05  0:37 [PATCH] net/mana: avoid the use of variable length array longli
@ 2025-03-05  9:00 ` Morten Brørup
  2025-03-06  2:17 ` Andre Muezerie
  1 sibling, 0 replies; 3+ messages in thread
From: Morten Brørup @ 2025-03-05  9:00 UTC (permalink / raw)
  To: longli, Stephen Hemminger, Wei Hu; +Cc: dev, Long Li

> From: longli@linuxonhyperv.com [mailto:longli@linuxonhyperv.com]
> Sent: Wednesday, 5 March 2025 01.38
> 
> From: Long Li <longli@microsoft.com>
> 
> The pathname can be defined as name[MAX_PATH]. This makes the driver
> compilable using MSVC.

The name is PATH_MAX, not MAX_PATH. It's correct in the code.

> 
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  drivers/net/mana/mana.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/mana/mana.c b/drivers/net/mana/mana.c
> index c37c4e3444..d12dff6ce1 100644
> --- a/drivers/net/mana/mana.c
> +++ b/drivers/net/mana/mana.c
> @@ -36,11 +36,8 @@ static rte_spinlock_t mana_shared_data_lock =
> RTE_SPINLOCK_INITIALIZER;
> 
>  /* Allocate a buffer on the stack and fill it with a printf format
> string. */
>  #define MANA_MKSTR(name, ...) \

The macro is no longer generic, but tied to a path name, so the macro's name and description should be updated accordingly. E.g.:

/* Allocate a path name buffer on the stack and fill it with a printf format string. */
#define MANA_MKPATHSTR(name, ...) \

Don't forget search-replace for uses of the macro. (It's being used 6 times in this file.)

> -	int mkstr_size_##name = snprintf(NULL, 0, "" __VA_ARGS__); \
> -	char name[mkstr_size_##name + 1]; \
> -	\
> -	memset(name, 0, mkstr_size_##name + 1); \
> -	snprintf(name, sizeof(name), "" __VA_ARGS__)
> +	char name[PATH_MAX]; \
> +	snprintf(name, PATH_MAX, "" __VA_ARGS__)
> 
>  int mana_logtype_driver;
>  int mana_logtype_init;
> --
> 2.34.1

With suggested changes,
Acked-by: Morten Brørup <mb@smartsharesystems.com>


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

* Re: [PATCH] net/mana: avoid the use of variable length array
  2025-03-05  0:37 [PATCH] net/mana: avoid the use of variable length array longli
  2025-03-05  9:00 ` Morten Brørup
@ 2025-03-06  2:17 ` Andre Muezerie
  1 sibling, 0 replies; 3+ messages in thread
From: Andre Muezerie @ 2025-03-06  2:17 UTC (permalink / raw)
  To: longli; +Cc: Stephen Hemminger, Wei Hu, dev, Long Li

On Tue, Mar 04, 2025 at 04:37:32PM -0800, longli@linuxonhyperv.com wrote:
> From: Long Li <longli@microsoft.com>
> 
> The pathname can be defined as name[MAX_PATH]. This makes the driver
> compilable using MSVC.
> 
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  drivers/net/mana/mana.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/mana/mana.c b/drivers/net/mana/mana.c
> index c37c4e3444..d12dff6ce1 100644
> --- a/drivers/net/mana/mana.c
> +++ b/drivers/net/mana/mana.c
> @@ -36,11 +36,8 @@ static rte_spinlock_t mana_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
>  
>  /* Allocate a buffer on the stack and fill it with a printf format string. */
>  #define MANA_MKSTR(name, ...) \
> -	int mkstr_size_##name = snprintf(NULL, 0, "" __VA_ARGS__); \
> -	char name[mkstr_size_##name + 1]; \
> -	\
> -	memset(name, 0, mkstr_size_##name + 1); \
> -	snprintf(name, sizeof(name), "" __VA_ARGS__)
> +	char name[PATH_MAX]; \
> +	snprintf(name, PATH_MAX, "" __VA_ARGS__)
>  
>  int mana_logtype_driver;
>  int mana_logtype_init;
> -- 
> 2.34.1

Did you try to remove the line below from mana/meson.build?
That line prevents the compiler from complain about VLAs. If
the driver is VLA-free after this fix it would be great
if the compiler was allowed to complain about VLAs (default
in DPDK project).

If the code still compiles without this line then it should be
safe to remove it:

cflags += no_wvla_cflag
--
Andre Muezerie

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

end of thread, other threads:[~2025-03-06  2:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-05  0:37 [PATCH] net/mana: avoid the use of variable length array longli
2025-03-05  9:00 ` Morten Brørup
2025-03-06  2:17 ` Andre Muezerie

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