DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/mlx: fix variadic macro
@ 2019-12-11  6:49 Ali Alnubani
  2019-12-12 22:24 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: Ali Alnubani @ 2019-12-11  6:49 UTC (permalink / raw)
  To: dev; +Cc: Adrien Mazarguil, stable, Matan Azrad

This rewrites the MKSTR macro appending an empty string to its arguments
to resolve build failures similar to:

  drivers/net/mlx4/mlx4.c:461:14: fatal error: format string is not a
  string literal [-Wformat-nonliteral]
          MKSTR(path, "%s/device/uevent", device->ibdev_path);

  drivers/net/mlx4/mlx4_utils.h:82:30: note: expanded from macro 'MKSTR'
          char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \

  drivers/net/mlx5/mlx5_stats.c:144:15: fatal error: format string is not a
  string literal [-Wformat-nonliteral]
  	MKSTR(path, "%s/ports/%d/hw_counters/%s",

  drivers/net/mlx5/mlx5_utils.h:149:30: note: expanded from macro 'MKSTR'
  	char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \

The errors reproduce with clang version 9.0.0, and the release notes
don't mention what could have caused them.

Fixes: 7fae69eeff13 ("mlx4: new poll mode driver")
Fixes: 771fa900b73a ("mlx5: introduce new driver for Mellanox ConnectX-4 adapters")
Cc: adrien.mazarguil@6wind.com
Cc: stable@dpdk.org

Signed-off-by: Ali Alnubani <alialnu@mellanox.com>
Signed-off-by: Matan Azrad <matan@mellanox.com>
---
 drivers/net/mlx4/mlx4_utils.h | 5 +++--
 drivers/net/mlx5/mlx5_utils.h | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/mlx4/mlx4_utils.h b/drivers/net/mlx4/mlx4_utils.h
index 74b9d2ecd..5718b9c74 100644
--- a/drivers/net/mlx4/mlx4_utils.h
+++ b/drivers/net/mlx4/mlx4_utils.h
@@ -79,9 +79,10 @@ pmd_drv_log_basename(const char *s)
 
 /** Allocate a buffer on the stack and fill it with a printf format string. */
 #define MKSTR(name, ...) \
-	char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \
+	int mkstr_size_##name = snprintf(NULL, 0, "" __VA_ARGS__); \
+	char name[mkstr_size_##name + 1]; \
 	\
-	snprintf(name, sizeof(name), __VA_ARGS__)
+	snprintf(name, sizeof(name), "" __VA_ARGS__)
 
 /** Generate a string out of the provided arguments. */
 #define MLX4_STR(...) # __VA_ARGS__
diff --git a/drivers/net/mlx5/mlx5_utils.h b/drivers/net/mlx5/mlx5_utils.h
index b4ed8c6da..ebf79b80a 100644
--- a/drivers/net/mlx5/mlx5_utils.h
+++ b/drivers/net/mlx5/mlx5_utils.h
@@ -146,9 +146,10 @@ extern int mlx5_logtype;
 
 /* Allocate a buffer on the stack and fill it with a printf format string. */
 #define MKSTR(name, ...) \
-	char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \
+	int mkstr_size_##name = snprintf(NULL, 0, "" __VA_ARGS__); \
+	char name[mkstr_size_##name + 1]; \
 	\
-	snprintf(name, sizeof(name), __VA_ARGS__)
+	snprintf(name, sizeof(name), "" __VA_ARGS__)
 
 /**
  * Return logarithm of the nearest power of two above input value.
-- 
2.24.0


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

* Re: [dpdk-dev] [PATCH] net/mlx: fix variadic macro
  2019-12-11  6:49 [dpdk-dev] [PATCH] net/mlx: fix variadic macro Ali Alnubani
@ 2019-12-12 22:24 ` Thomas Monjalon
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Monjalon @ 2019-12-12 22:24 UTC (permalink / raw)
  To: Ali Alnubani; +Cc: dev, Adrien Mazarguil, stable, Matan Azrad

11/12/2019 07:49, Ali Alnubani:
> This rewrites the MKSTR macro appending an empty string to its arguments
> to resolve build failures similar to:
> 
>   drivers/net/mlx4/mlx4.c:461:14: fatal error: format string is not a
>   string literal [-Wformat-nonliteral]
>           MKSTR(path, "%s/device/uevent", device->ibdev_path);
> 
>   drivers/net/mlx4/mlx4_utils.h:82:30: note: expanded from macro 'MKSTR'
>           char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \
> 
>   drivers/net/mlx5/mlx5_stats.c:144:15: fatal error: format string is not a
>   string literal [-Wformat-nonliteral]
>   	MKSTR(path, "%s/ports/%d/hw_counters/%s",
> 
>   drivers/net/mlx5/mlx5_utils.h:149:30: note: expanded from macro 'MKSTR'
>   	char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \
> 
> The errors reproduce with clang version 9.0.0, and the release notes
> don't mention what could have caused them.
> 
> Fixes: 7fae69eeff13 ("mlx4: new poll mode driver")
> Fixes: 771fa900b73a ("mlx5: introduce new driver for Mellanox ConnectX-4 adapters")
> Cc: adrien.mazarguil@6wind.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ali Alnubani <alialnu@mellanox.com>
> Signed-off-by: Matan Azrad <matan@mellanox.com>

Applied quickly in main tree as it is fixing compilation with a recent clang 9.



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

end of thread, other threads:[~2019-12-12 22:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11  6:49 [dpdk-dev] [PATCH] net/mlx: fix variadic macro Ali Alnubani
2019-12-12 22:24 ` Thomas Monjalon

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