diff mbox series

[net-next] mlxsw: spectrum_router: avoid uninitialized variable access

Message ID 20180706124455.3151925-1-arnd@arndb.de
State Accepted
Commit be9c64b19b8131459dd7107dc0ae209eeeaa9ce8
Headers show
Series [net-next] mlxsw: spectrum_router: avoid uninitialized variable access | expand

Commit Message

Arnd Bergmann July 6, 2018, 12:44 p.m. UTC
When CONFIG_BRIDGE_VLAN_FILTERING is disabled, gcc correctly points out
that the 'vid' variable is uninitialized whenever br_vlan_get_pvid
returns an error:

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c: In function 'mlxsw_sp_rif_vlan_fid_get':
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:6881:6: error: 'vid' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This changes the condition check to always return -EINVAL here,
which I guess is what the author intended here.

Fixes: e6f1960ae6c7 ("mlxsw: spectrum_router: Allocate FID according to PVID")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

-- 
2.9.0

Comments

Ido Schimmel July 6, 2018, 1:16 p.m. UTC | #1
On Fri, Jul 06, 2018 at 02:44:45PM +0200, Arnd Bergmann wrote:
> When CONFIG_BRIDGE_VLAN_FILTERING is disabled, gcc correctly points out

> that the 'vid' variable is uninitialized whenever br_vlan_get_pvid

> returns an error:

> 

> drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c: In function 'mlxsw_sp_rif_vlan_fid_get':

> drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:6881:6: error: 'vid' may be used uninitialized in this function [-Werror=maybe-uninitialized]

> 

> This changes the condition check to always return -EINVAL here,

> which I guess is what the author intended here.

> 

> Fixes: e6f1960ae6c7 ("mlxsw: spectrum_router: Allocate FID according to PVID")

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>


Reviewed-by: Ido Schimmel <idosch@mellanox.com>


Thanks!
David Miller July 7, 2018, 11:07 a.m. UTC | #2
From: Arnd Bergmann <arnd@arndb.de>

Date: Fri,  6 Jul 2018 14:44:45 +0200

> When CONFIG_BRIDGE_VLAN_FILTERING is disabled, gcc correctly points out

> that the 'vid' variable is uninitialized whenever br_vlan_get_pvid

> returns an error:

> 

> drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c: In function 'mlxsw_sp_rif_vlan_fid_get':

> drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:6881:6: error: 'vid' may be used uninitialized in this function [-Werror=maybe-uninitialized]

> 

> This changes the condition check to always return -EINVAL here,

> which I guess is what the author intended here.

> 

> Fixes: e6f1960ae6c7 ("mlxsw: spectrum_router: Allocate FID according to PVID")

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>


Applied.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 071428227b91..60c352ddd6fd 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -6878,11 +6878,9 @@  mlxsw_sp_rif_vlan_fid_get(struct mlxsw_sp_rif *rif,
 		vid = vlan_dev_vlan_id(rif->dev);
 	} else {
 		err = br_vlan_get_pvid(rif->dev, &vid);
-		if (!vid)
-			err = -EINVAL;
-		if (err) {
+		if (err < 0 || !vid) {
 			NL_SET_ERR_MSG_MOD(extack, "Couldn't determine bridge PVID");
-			return ERR_PTR(err);
+			return ERR_PTR(-EINVAL);
 		}
 	}