net/cnxk: fix dangling pointer in meter for gcc12

Message ID 20220117140226.3019392-1-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Jerin Jacob
Headers
Series net/cnxk: fix dangling pointer in meter for gcc12 |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Ferruh Yigit Jan. 17, 2022, 2:02 p.m. UTC
  Observed with: gcc (GCC) 12.0.0 20220116 (experimental)

In file included from ../drivers/net/cnxk/cnxk_ethdev.h:16,
                 from ../drivers/net/cnxk/cnxk_ethdev_mtr.c:5:
In function ‘rte_mtr_error_set’,
    inlined from ‘cnxk_nix_mtr_policy_validate’ at ../drivers/net/cnxk/cnxk_ethdev_mtr.c:311:14:
../lib/ethdev/rte_mtr_driver.h:188:24: error: storing the address of local variable ‘message’ in ‘*error.message’ [-Werror=dangling-pointer=]
  188 |                 *error = (struct rte_mtr_error){
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
  189 |                         .type = type,
      |                         ~~~~~~~~~~~~~
  190 |                         .cause = cause,
      |                         ~~~~~~~~~~~~~~~
  191 |                         .message = message,
      |                         ~~~~~~~~~~~~~~~~~~~
  192 |                 };
      |                 ~
../drivers/net/cnxk/cnxk_ethdev_mtr.c: In function ‘cnxk_nix_mtr_policy_validate’:
../drivers/net/cnxk/cnxk_ethdev_mtr.c:288:14: note: ‘message’ declared here
  288 |         char message[1024];
      |              ^~~~~~~
../drivers/net/cnxk/cnxk_ethdev_mtr.c:288:14: note: ‘error’ declared here

It is a valid compiler warning, make local variable a global one.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

---

Fix is done in a quickest way, mainly to report the issue,
please feel free to suggest another solution for the build error.
---
 drivers/net/cnxk/cnxk_ethdev_mtr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/drivers/net/cnxk/cnxk_ethdev_mtr.c b/drivers/net/cnxk/cnxk_ethdev_mtr.c
index 39d856382656..b6c6a6621935 100644
--- a/drivers/net/cnxk/cnxk_ethdev_mtr.c
+++ b/drivers/net/cnxk/cnxk_ethdev_mtr.c
@@ -285,7 +285,7 @@  cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,
 	static const char *const action_color[] = {"Green", "Yellow", "Red"};
 	bool supported[RTE_COLORS] = {false, false, false};
 	const struct rte_flow_action *action;
-	char message[1024];
+	static char message[1024];
 	uint32_t i;
 
 	RTE_SET_USED(dev);