Skip to contentSkip to conversation

net/mlx5e: shut up maybe-uninitialized warning

PATCH Applied Arnd Bergmann 4 participants 7 messages Sep 30, 2016 – Oct 3, 2016

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net/mlx5e: shut up maybe-uninitialized warning

Build-testing this driver with -Wmaybe-uninitialized gives a new false-positive warning that I can't really explain:

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c: In function 'mlx5e_configure_flower':
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:509:3: error: 'old_attr' may be used uninitialized in this function [-Werror=maybe-uninitialized]

It's obvious from the code that 'old_attr' is initialized whenever 'old' is non-NULL here. The warning appears with all versions I tested from gcc-4.7 through gcc-6.1, and I could not come up with a way to rewrite the function in a more readable way that avoids the warning, so I'm adding another initialization to shut it up.

Fixes 8b32580df1cb ("net/mlx5e: Add TC vlan action for SRIOV offloads")
---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +1 -1
index a350b7171e3d..ce8c54d18906 100644
@@ -451,7 +451,7 @@ int mlx5e_configure_flower(struct mlx5e_priv *priv, __be16 protocol,
 	struct mlx5e_tc_flow *flow;
 	struct mlx5_flow_spec *spec;
 	struct mlx5_flow_rule *old = NULL;
-	struct mlx5_esw_flow_attr *old_attr;
+	struct mlx5_esw_flow_attr *old_attr = NULL;
 	struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
 
 	if (esw && esw->mode == SRIOV_OFFLOADS)
Signature · 6 lines
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH 2/2 mlxsw: spectrum_router: avoid potential uninitialized data usage

If fi->fib_nhs is zero, the router interface pointer is uninitialized, as shown by this warning:

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c: In function 'mlxsw_sp_router_fib_event':
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:1674:21: error: 'r' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:1643:23: note: 'r' was declared here

This changes the loop so we handle the case the same way as finding no router interface pointer attached to one of the nexthops to ensure we always trap here instead of using uninitialized data.

Fixes b45f64d16d45 ("mlxsw: spectrum_router: Use FIB notifications instead of switchdev calls")
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +7 -3
index 48d50efec5e2..78fc557d6dd7 100644
@@ -1640,7 +1640,7 @@ mlxsw_sp_router_fib4_entry_init(struct mlxsw_sp *mlxsw_sp,
 				struct mlxsw_sp_fib_entry *fib_entry)
 {
 	struct fib_info *fi = fen_info->fi;
-	struct mlxsw_sp_rif *r;
+	struct mlxsw_sp_rif *r = NULL;
 	int nhsel;
 	int err;
 
@@ -1664,11 +1664,15 @@ mlxsw_sp_router_fib4_entry_init(struct mlxsw_sp *mlxsw_sp,
 			 * to us. Set trap and pass the packets for
 			 * this prefix to kernel.
 			 */
-			fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_TRAP;
-			return 0;
+			break;
 		}
 	}
 
+	if (!r) {
+		fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_TRAP;
+		return 0;
+	}
+
 	if (fi->fib_scope != RT_SCOPE_UNIVERSE) {
 		fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_LOCAL;
 		fib_entry->rif = r->rif;
Signature · 1 line
2.9.0
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage

Quoted 7 lines · Arnd Bergmann

If fi->fib_nhs is zero, the router interface pointer is uninitialized, as shown by this warning:

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c: In function 'mlxsw_sp_router_fib_event':
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:1674:21: error: 'r' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:1643:23: note: 'r' was declared here

Quoted 6 lines

This changes the loop so we handle the case the same way as finding no router interface pointer attached to one of the nexthops to ensure we always trap here instead of using uninitialized data.

Fixes b45f64d16d45 ("mlxsw: spectrum_router: Use FIB notifications instead of switchdev calls")

For net-next:

BTW, which flags did you pass to generate this error? I can only reproduce this with EXTRA_CFLAGS="-Wmaybe-uninitialized -Werror", but for some reason EXTRA_CFLAGS="-Wall -Werror" is silent. Any idea why? I would like to add this to my git hooks and avoid these errors in the future :)

Thanks!

#3 lore raw

Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage

Quoted 5 lines · Ido Schimmel

BTW, which flags did you pass to generate this error? I can only reproduce this with EXTRA_CFLAGS="-Wmaybe-uninitialized -Werror", but for some reason EXTRA_CFLAGS="-Wall -Werror" is silent. Any idea why? I would like to add this to my git hooks and avoid these errors in the future :)

Linus disabled the warning for v4.8. I've just talked to him today about this warning in particular, and hope that we can find a way to enable it by default again in the future, as a lot of possible bugs get introduced, but certain compiler versions also produce a lot of false positives.

Arnd

Acked-by on v1 1/2
#5 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann

Build-testing this driver with -Wmaybe-uninitialized gives a new false-positive warning that I can't really explain:

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c: In function 'mlx5e_configure_flower':
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:509:3: error: 'old_attr' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Quoted 8 lines

It's obvious from the code that 'old_attr' is initialized whenever 'old' is non-NULL here. The warning appears with all versions I tested from gcc-4.7 through gcc-6.1, and I could not come up with a way to rewrite the function in a more readable way that avoids the warning, so I'm adding another initialization to shut it up.

Fixes 8b32580df1cb ("net/mlx5e: Add TC vlan action for SRIOV offloads")

Yeah, this is clearly false positive and I was sure that newish GCCs don't show that, but you are the master here.. so FWIW

maintainer
#6 lore raw
In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>
Date: Fri, 30 Sep 2016 18:17:09 +0200

Quoted 6 lines

Build-testing this driver with -Wmaybe-uninitialized gives a new false-positive warning that I can't really explain:

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c: In function 'mlx5e_configure_flower':
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:509:3: error: 'old_attr' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Quoted 8 lines

It's obvious from the code that 'old_attr' is initialized whenever 'old' is non-NULL here. The warning appears with all versions I tested from gcc-4.7 through gcc-6.1, and I could not come up with a way to rewrite the function in a more readable way that avoids the warning, so I'm adding another initialization to shut it up.

Fixes 8b32580df1cb ("net/mlx5e: Add TC vlan action for SRIOV offloads")

Applied.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer Applied
#4 lore raw

Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>
Date: Fri, 30 Sep 2016 18:17:10 +0200

Quoted 7 lines

If fi->fib_nhs is zero, the router interface pointer is uninitialized, as shown by this warning:

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c: In function 'mlxsw_sp_router_fib_event':
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:1674:21: error: 'r' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:1643:23: note: 'r' was declared here

Quoted 6 lines

This changes the loop so we handle the case the same way as finding no router interface pointer attached to one of the nexthops to ensure we always trap here instead of using uninitialized data.

Fixes b45f64d16d45 ("mlxsw: spectrum_router: Use FIB notifications instead of switchdev calls")

Applied.