Skip to content

Commit ab58070

Browse files
arndbdavem330
authored andcommitted
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: b45f64d ("mlxsw: spectrum_router: Use FIB notifications instead of switchdev calls") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d0debb7 commit ab58070

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ mlxsw_sp_router_fib4_entry_init(struct mlxsw_sp *mlxsw_sp,
16401640
struct mlxsw_sp_fib_entry *fib_entry)
16411641
{
16421642
struct fib_info *fi = fen_info->fi;
1643-
struct mlxsw_sp_rif *r;
1643+
struct mlxsw_sp_rif *r = NULL;
16441644
int nhsel;
16451645
int err;
16461646

@@ -1664,11 +1664,15 @@ mlxsw_sp_router_fib4_entry_init(struct mlxsw_sp *mlxsw_sp,
16641664
* to us. Set trap and pass the packets for
16651665
* this prefix to kernel.
16661666
*/
1667-
fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_TRAP;
1668-
return 0;
1667+
break;
16691668
}
16701669
}
16711670

1671+
if (!r) {
1672+
fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_TRAP;
1673+
return 0;
1674+
}
1675+
16721676
if (fi->fib_scope != RT_SCOPE_UNIVERSE) {
16731677
fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_LOCAL;
16741678
fib_entry->rif = r->rif;

0 commit comments

Comments
 (0)