net/mlx5: fix GCC uninitialized variable warning

Message ID 20211228091704.3359132-1-dkozlyuk@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: fix GCC uninitialized variable warning |

Checks

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

Commit Message

Dmitry Kozlyuk Dec. 28, 2021, 9:17 a.m. UTC
  When building with -Db_sanitize=thread, GCC gives a warning:

drivers/net/mlx5/mlx5_flow_meter.c: In function ‘mlx5_flow_meter_create’:
drivers/net/mlx5/mlx5_flow_meter.c:1170:33: warning: ‘legacy_fm’ may be
    used uninitialized in this function [-Wmaybe-uninitialized]

This is a false-positive: legacy_fm is initialized and used
if and only if priv->sh->meter_aso_en is false.
Work around this by initializing legacy_fm to NULL.
Add an assertion before legacy_fm use in case the logic changes.

Fixes: 444320186393 ("net/mlx5: support meter creation with policy")
Cc: lizh@nvidia.com
Cc: stable@dpdk.org

Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_meter.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Raslan Darawsheh Jan. 9, 2022, 11:58 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
> Sent: Tuesday, December 28, 2021 11:17 AM
> To: dev@dpdk.org
> Cc: Li Zhang <lizh@nvidia.com>; stable@dpdk.org; Stephen Hemminger
> <stephen@networkplumber.org>; Matan Azrad <matan@nvidia.com>; Slava
> Ovsiienko <viacheslavo@nvidia.com>
> Subject: [PATCH] net/mlx5: fix GCC uninitialized variable warning
> 
> When building with -Db_sanitize=thread, GCC gives a warning:
> 
> drivers/net/mlx5/mlx5_flow_meter.c: In function
> ‘mlx5_flow_meter_create’:
> drivers/net/mlx5/mlx5_flow_meter.c:1170:33: warning: ‘legacy_fm’ may be
>     used uninitialized in this function [-Wmaybe-uninitialized]
> 
> This is a false-positive: legacy_fm is initialized and used if and only if priv->sh-
> >meter_aso_en is false.
> Work around this by initializing legacy_fm to NULL.
> Add an assertion before legacy_fm use in case the logic changes.
> 
> Fixes: 444320186393 ("net/mlx5: support meter creation with policy")
> Cc: lizh@nvidia.com
> Cc: stable@dpdk.org
> 
> Reported-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
> Acked-by: Matan Azrad <matan@nvidia.com>

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh
  

Patch

diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index f4a7b697e6..fd4f286deb 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -1167,7 +1167,8 @@  mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id,
 	struct mlx5_legacy_flow_meters *fms = &priv->flow_meters;
 	struct mlx5_flow_meter_profile *fmp;
 	struct mlx5_flow_meter_info *fm;
-	struct mlx5_legacy_flow_meter *legacy_fm;
+	/* GCC fails to infer legacy_fm is set when !priv->sh->meter_aso_en. */
+	struct mlx5_legacy_flow_meter *legacy_fm = NULL;
 	struct mlx5_flow_meter_policy *mtr_policy = NULL;
 	struct mlx5_indexed_pool_config flow_ipool_cfg = {
 		.size = 0,
@@ -1273,8 +1274,10 @@  mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id,
 	if (mlx5_flow_create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap))
 		goto error;
 	/* Add to the flow meter list. */
-	if (!priv->sh->meter_aso_en)
+	if (!priv->sh->meter_aso_en) {
+		MLX5_ASSERT(legacy_fm != NULL);
 		TAILQ_INSERT_TAIL(fms, legacy_fm, next);
+	}
 	/* Add to the flow meter list. */
 	fm->active_state = 1; /* Config meter starts as active. */
 	fm->is_enable = 1;