[PATCH 5.1 31/98] net/mlx5e: Avoid detaching non-existing netdev under switchdev mode

From: Greg Kroah-Hartman
Date: Thu Jun 20 2019 - 14:14:26 EST

From: Alaa Hleihel <alaa@xxxxxxxxxxxx>

After introducing dedicated uplink representor, the netdev instance
set over the esw manager vport (PF) became no longer in use, so it was
removed in the cited commit once we're on switchdev mode.
However, the mlx5e_detach function was not updated accordingly, and it
still tries to detach a non-existing netdev, causing a kernel crash.

This patch fixes this issue.

Fixes: aec002f6f82c ("net/mlx5e: Uninstantiate esw manager vport netdev on switchdev mode")
Signed-off-by: Alaa Hleihel <alaa@xxxxxxxxxxxx>
Reviewed-by: Roi Dayan <roid@xxxxxxxxxxxx>
Signed-off-by: Saeed Mahameed <saeedm@xxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 5 +++++
1 file changed, 5 insertions(+)

--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -5165,6 +5165,11 @@ static void mlx5e_detach(struct mlx5_cor
struct mlx5e_priv *priv = vpriv;
struct net_device *netdev = priv->netdev;

+ if (MLX5_ESWITCH_MANAGER(mdev) && vpriv == mdev)
+ return;
if (!netif_device_present(netdev))