net/mlx5e: Check netdev pointer before checking its net ns
authorGavin Li <gavinl@nvidia.com>
Thu, 31 Aug 2023 02:47:09 +0000 (05:47 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Dec 2023 16:01:45 +0000 (17:01 +0100)
commitef3b2d5f21526a47067ac0ab885fd1c096fcec82
treecfbe54a9c4540ec6ae2c6aeab565436cab380d87
parenta4839771d7b9d74b98b8209967ffdbfb28ae9104
net/mlx5e: Check netdev pointer before checking its net ns

[ Upstream commit 7aaf975238c47b710fcc4eca0da1e7902a53abe2 ]

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: 662404b24a4c ("net/mlx5e: Block entering switchdev mode with ns inconsistency")
Signed-off-by: Gavin Li <gavinl@nvidia.com>
Reviewed-by: Gavi Teitz <gavi@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c