From: Eli Cohen <e...@mellanox.com>

Net devices might be removed. For example, a vxlan device could be
deleted and its ifnidex would become invalid. Use dev_get_by_index()
instead of __dev_get_by_index() to hold reference on the device while
accessing it and release after done.

Fixes: 3c37745ec614 ("net/mlx5e: Properly deal with encap flows add/del under 
neigh update")
Signed-off-by: Eli Cohen <e...@mellanox.com>
Reviewed-by: Vlad Buslov <vla...@mellanox.com>
Signed-off-by: Saeed Mahameed <sae...@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c 
b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 75f169aef1cf..e88f98ab062f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -1327,10 +1327,14 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,
                        continue;
 
                mirred_ifindex = parse_attr->mirred_ifindex[out_index];
-               out_dev = __dev_get_by_index(dev_net(priv->netdev),
-                                            mirred_ifindex);
+               out_dev = dev_get_by_index(dev_net(priv->netdev),
+                                          mirred_ifindex);
+               if (!out_dev)
+                       return -ENODEV;
+
                err = mlx5e_attach_encap(priv, flow, out_dev, out_index,
                                         extack, &encap_dev, &encap_valid);
+               dev_put(out_dev);
                if (err)
                        return err;
 
-- 
2.26.2

Reply via email to