linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning
@ 2016-09-30 16:17 Arnd Bergmann
  2016-09-30 16:17 ` [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage Arnd Bergmann
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Arnd Bergmann @ 2016-09-30 16:17 UTC (permalink / raw)
  To: Saeed Mahameed, Matan Barak, Leon Romanovsky
  Cc: Arnd Bergmann, David S. Miller, Or Gerlitz, Amir Vadai,
	Maor Gottlieb, netdev, linux-rdma, linux-kernel

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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index a350b7171e3d..ce8c54d18906 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -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)
-- 
2.9.0

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

* [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage
  2016-09-30 16:17 [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning Arnd Bergmann
@ 2016-09-30 16:17 ` Arnd Bergmann
  2016-09-30 17:57   ` Ido Schimmel
  2016-10-03  5:56   ` David Miller
  2016-10-01 15:08 ` [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning Or Gerlitz
  2016-10-03  5:56 ` David Miller
  2 siblings, 2 replies; 7+ messages in thread
From: Arnd Bergmann @ 2016-09-30 16:17 UTC (permalink / raw)
  To: Jiri Pirko, Ido Schimmel
  Cc: Arnd Bergmann, David S. Miller, Yotam Gigi, Nogah Frankel,
	netdev, linux-kernel

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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 48d50efec5e2..78fc557d6dd7 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -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;
-- 
2.9.0

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

* Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage
  2016-09-30 16:17 ` [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage Arnd Bergmann
@ 2016-09-30 17:57   ` Ido Schimmel
  2016-10-01  3:36     ` Arnd Bergmann
  2016-10-03  5:56   ` David Miller
  1 sibling, 1 reply; 7+ messages in thread
From: Ido Schimmel @ 2016-09-30 17:57 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Jiri Pirko, Ido Schimmel, David S. Miller, Yotam Gigi,
	Nogah Frankel, netdev, linux-kernel

On Fri, Sep 30, 2016 at 06:17:10PM +0200, Arnd Bergmann wrote:
> 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")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

For net-next:
Acked-by: Ido Schimmel <idosch@mellanox.com>

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!

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

* Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage
  2016-09-30 17:57   ` Ido Schimmel
@ 2016-10-01  3:36     ` Arnd Bergmann
  0 siblings, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2016-10-01  3:36 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: Jiri Pirko, Ido Schimmel, David S. Miller, Yotam Gigi,
	Nogah Frankel, netdev, linux-kernel

On Friday 30 September 2016, Ido Schimmel wrote:
> 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

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

* Re: [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning
  2016-09-30 16:17 [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning Arnd Bergmann
  2016-09-30 16:17 ` [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage Arnd Bergmann
@ 2016-10-01 15:08 ` Or Gerlitz
  2016-10-03  5:56 ` David Miller
  2 siblings, 0 replies; 7+ messages in thread
From: Or Gerlitz @ 2016-10-01 15:08 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Saeed Mahameed, Matan Barak, Leon Romanovsky, David S. Miller,
	Or Gerlitz, Amir Vadai, Maor Gottlieb, Linux Netdev List,
	linux-rdma, Linux Kernel

On Fri, Sep 30, 2016 at 7:17 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> 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")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

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

Acked-by: Or Gerlitz <ogerlitz@mellanox.com>

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

* Re: [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning
  2016-09-30 16:17 [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning Arnd Bergmann
  2016-09-30 16:17 ` [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage Arnd Bergmann
  2016-10-01 15:08 ` [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning Or Gerlitz
@ 2016-10-03  5:56 ` David Miller
  2 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2016-10-03  5:56 UTC (permalink / raw)
  To: arnd
  Cc: saeedm, matanb, leonro, ogerlitz, amirva, maorg, netdev,
	linux-rdma, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 30 Sep 2016 18:17:09 +0200

> 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")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied.

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

* Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage
  2016-09-30 16:17 ` [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage Arnd Bergmann
  2016-09-30 17:57   ` Ido Schimmel
@ 2016-10-03  5:56   ` David Miller
  1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2016-10-03  5:56 UTC (permalink / raw)
  To: arnd; +Cc: jiri, idosch, yotamg, nogahf, netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 30 Sep 2016 18:17:10 +0200

> 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")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied.

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

end of thread, other threads:[~2016-10-03  5:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-30 16:17 [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning Arnd Bergmann
2016-09-30 16:17 ` [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage Arnd Bergmann
2016-09-30 17:57   ` Ido Schimmel
2016-10-01  3:36     ` Arnd Bergmann
2016-10-03  5:56   ` David Miller
2016-10-01 15:08 ` [PATCH 1/2] net/mlx5e: shut up maybe-uninitialized warning Or Gerlitz
2016-10-03  5:56 ` David Miller

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