[v3] net/mlx5: fix compilation issue with gcc pragma

Message ID 1570019815-16177-1-git-send-email-viacheslavo@mellanox.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v3] net/mlx5: fix compilation issue with gcc pragma |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-compilation success Compile Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Slava Ovsiienko Oct. 2, 2019, 12:36 p.m. UTC
  The GCC compiler might generate warning or error if
format parameter of fscanf is not literal. This was
suppressed with GCC specific pragms. Some compilers
(i.e Intel icc) do not recognize GCC diagnostic
pragma, so the code was refactored with stringification,
pragmas are not needed anymore.

Fixes: a46a42b5cd03 ("net/mlx5: add VF LAG mode bonding device recognition")

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 v3: replace with RTE_STR stringifier

 v2: http://patches.dpdk.org/patch/60415/
     code rewritten with stringification

 v1: http://patches.dpdk.org/patch/60310/
     initial version with pragmas and compiler type check

 drivers/net/mlx5/mlx5.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
  

Comments

Ferruh Yigit Oct. 2, 2019, 4:19 p.m. UTC | #1
On 10/2/2019 1:36 PM, Viacheslav Ovsiienko wrote:
> The GCC compiler might generate warning or error if
> format parameter of fscanf is not literal. This was
> suppressed with GCC specific pragms. Some compilers
> (i.e Intel icc) do not recognize GCC diagnostic
> pragma, so the code was refactored with stringification,
> pragmas are not needed anymore.
> 
> Fixes: a46a42b5cd03 ("net/mlx5: add VF LAG mode bonding device recognition")
> 
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>

Squashed into relevant commit in next-net, thanks.
  

Patch

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 951b9f5..13d112e 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -2295,12 +2295,9 @@  struct mlx5_dev_spawn_data {
 	}
 	if (!file)
 		return -1;
-	MKSTR(format, "%c%us", '%', (unsigned int)(sizeof(ifname) - 1));
-
 	/* Use safe format to check maximal buffer length. */
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-	while (fscanf(file, format, ifname) == 1) {
-#pragma GCC diagnostic error "-Wformat-nonliteral"
+	assert(atol(RTE_STR(IF_NAMESIZE)) == IF_NAMESIZE);
+	while (fscanf(file, "%" RTE_STR(IF_NAMESIZE) "s", ifname) == 1) {
 		char tmp_str[IF_NAMESIZE + 32];
 		struct rte_pci_addr pci_addr;
 		struct mlx5_switch_info	info;