Commit 7aaf9752 authored by Gavin Li's avatar Gavin Li Committed by Saeed Mahameed
Browse files

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: 662404b2 ("net/mlx5e: Block entering switchdev mode with ns inconsistency")
Signed-off-by: default avatarGavin Li <gavinl@nvidia.com>
Reviewed-by: default avatarGavi Teitz <gavi@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 3d7a3f26
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -3653,14 +3653,18 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode)

static bool esw_offloads_devlink_ns_eq_netdev_ns(struct devlink *devlink)
{
	struct mlx5_core_dev *dev = devlink_priv(devlink);
	struct net *devl_net, *netdev_net;
	struct mlx5_eswitch *esw;
	bool ret = false;

	esw = mlx5_devlink_eswitch_nocheck_get(devlink);
	netdev_net = dev_net(esw->dev->mlx5e_res.uplink_netdev);
	mutex_lock(&dev->mlx5e_res.uplink_netdev_lock);
	if (dev->mlx5e_res.uplink_netdev) {
		netdev_net = dev_net(dev->mlx5e_res.uplink_netdev);
		devl_net = devlink_net(devlink);

	return net_eq(devl_net, netdev_net);
		ret = net_eq(devl_net, netdev_net);
	}
	mutex_unlock(&dev->mlx5e_res.uplink_netdev_lock);
	return ret;
}

int mlx5_eswitch_block_mode(struct mlx5_core_dev *dev)