Skip to content

Commit 7aaf975

Browse files
GavinLi-NVSaeed Mahameed
authored andcommitted
net/mlx5e: Check netdev pointer before checking its net ns
Previously, when comparing the net namespaces, the case where the netdev doesn't exist wasn't taken into account, and therefore can cause a crash. In such a case, the comparing function should return false, as there is no netdev->net to compare the devlink->net to. Furthermore, this will result in an attempt to enter switchdev mode without a netdev to fail, and which is the desired result as there is no meaning in switchdev mode without a net device. Fixes: 662404b ("net/mlx5e: Block entering switchdev mode with ns inconsistency") Signed-off-by: Gavin Li <[email protected]> Reviewed-by: Gavi Teitz <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 3d7a3f2 commit 7aaf975

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,14 +3653,18 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode)
36533653

36543654
static bool esw_offloads_devlink_ns_eq_netdev_ns(struct devlink *devlink)
36553655
{
3656+
struct mlx5_core_dev *dev = devlink_priv(devlink);
36563657
struct net *devl_net, *netdev_net;
3657-
struct mlx5_eswitch *esw;
3658-
3659-
esw = mlx5_devlink_eswitch_nocheck_get(devlink);
3660-
netdev_net = dev_net(esw->dev->mlx5e_res.uplink_netdev);
3661-
devl_net = devlink_net(devlink);
3658+
bool ret = false;
36623659

3663-
return net_eq(devl_net, netdev_net);
3660+
mutex_lock(&dev->mlx5e_res.uplink_netdev_lock);
3661+
if (dev->mlx5e_res.uplink_netdev) {
3662+
netdev_net = dev_net(dev->mlx5e_res.uplink_netdev);
3663+
devl_net = devlink_net(devlink);
3664+
ret = net_eq(devl_net, netdev_net);
3665+
}
3666+
mutex_unlock(&dev->mlx5e_res.uplink_netdev_lock);
3667+
return ret;
36643668
}
36653669

36663670
int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev)

0 commit comments

Comments
 (0)