net/mlx5: Add vport return value checks
Subsystems (4)
PATCH 1/1 net/mlx5: Add vport return value checks
add missing vport return value checks for recent code, as in [1].
Ref:
[1] https://lkml.org/lkml/2020/11/1/315
--- .../mellanox/mlx5/core/eswitch_offloads.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +20 -0
@@ -1230,6 +1230,8 @@ static int esw_add_fdb_peer_miss_rules(struct mlx5_eswitch *esw,if (mlx5_core_is_ecpf_esw_manager (esw->dev)) { vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_PF ); +if (IS_ERR (vport)) +return PTR_ERR (vport);esw_set_peer_miss_rule_source_port (esw, peer_dev->priv.eswitch, spec,MLX5_VPORT_PF );
@@ -1244,6 +1246,8 @@ static int esw_add_fdb_peer_miss_rules(struct mlx5_eswitch *esw,if (mlx5_ecpf_vport_exists (esw->dev)) { vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_ECPF ); +if (IS_ERR (vport)) +return PTR_ERR (vport);MLX5_SET (fte_match_set_misc, misc, source_port,MLX5_VPORT_ECPF ); flow =mlx5_add_flow_rules (esw->fdb_table.offloads.slow_fdb, spec, &flow_act, &dest,1 );
@@ -1281,11 +1285,15 @@ static int esw_add_fdb_peer_miss_rules(struct mlx5_eswitch *esw, }if (mlx5_ecpf_vport_exists (esw->dev)) { vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_ECPF ); +if (IS_ERR (vport)) +return PTR_ERR (vport);mlx5_del_flow_rules (flows[vport->index]); } add_ecpf_flow_err:if (mlx5_core_is_ecpf_esw_manager (esw->dev)) { vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_PF ); +if (IS_ERR (vport)) +return PTR_ERR (vport);mlx5_del_flow_rules (flows[vport->index]); } add_pf_flow_err:
@@ -1309,11 +1317,15 @@ static void esw_del_fdb_peer_miss_rules(struct mlx5_eswitch *esw)if (mlx5_ecpf_vport_exists (esw->dev)) { vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_ECPF ); +if (IS_ERR (vport)) +return ;mlx5_del_flow_rules (flows[vport->index]); }if (mlx5_core_is_ecpf_esw_manager (esw->dev)) { vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_PF ); +if (IS_ERR (vport)) +return ;mlx5_del_flow_rules (flows[vport->index]); }kvfree (flows);
@@ -2385,6 +2397,9 @@ static int esw_set_uplink_slave_ingress_root(struct mlx5_core_dev *master,if (master) { esw = master->priv.eswitch; vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_UPLINK ); +if (IS_ERR (vport)) +return PTR_ERR (vport); +MLX5_SET (set_flow_table_root_in, in, table_of_other_vport,1 );MLX5_SET (set_flow_table_root_in, in, table_vport_number,MLX5_VPORT_UPLINK );
@@ -2405,6 +2420,9 @@ static int esw_set_uplink_slave_ingress_root(struct mlx5_core_dev *master, }else { esw = slave->priv.eswitch; vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_UPLINK ); +if (IS_ERR (vport)) +return PTR_ERR (vport); + ns =mlx5_get_flow_vport_acl_namespace (slave,MLX5_FLOW_NAMESPACE_ESW_INGRESS , vport->index);
@@ -2590,6 +2608,8 @@ static void esw_unset_master_egress_rule(struct mlx5_core_dev *dev) vport =mlx5_eswitch_get_vport (dev->priv.eswitch, dev->priv.eswitch->manager_vport); +if (IS_ERR (vport)) +return ;esw_acl_egress_ofld_cleanup (vport); }
Signature · 1 line
2.25.1
Quoted 5 lines · Zizhuang Deng
add missing vport return value checks for recent code, as in [1].
Where did this patch come from ? real bug ? or just aligning the code to
be according the link below ? because all the use-cases below are supposed to be guaranteed to have a valid vport object for uplink/pf/and ecpf vportrs, i am not against the
patch, I am just trying to understand if there is a hidden bug somewhere ..
Quoted 9 lines
Signed-off-by Zizhuang Deng <[email protected]>---
.../mellanox/mlx5/core/eswitch_offloads.c| 20 +++++++++++++++++++1 file changed, 20 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +0
-0
[...]
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c static void esw_del_fdb_peer_miss_rules(struct mlx5_eswitch *esw) · line 1321
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +2
-0@@ -1309,11 +1317,15 @@ static void esw_del_fdb_peer_miss_rules(struct mlx5_eswitch *esw)if (mlx5_ecpf_vport_exists (esw->dev)) { vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_ECPF ); +if (IS_ERR (vport)) +return ;
memleak, we need to hit kvfree(flows) below, instead of returning you should make the del_flow conditional and continue to next steps in the esw_del_fdb_peer_miss_rules routine, e.g:
if (vport)
mlx5_del_flow_rules(flows[vport->index]);
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c static void esw_del_fdb_peer_miss_rules(struct mlx5_eswitch *esw) · line 1328
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +2
-0mlx5_del_flow_rules (flows[vport->index]); }if (mlx5_core_is_ecpf_esw_manager (esw->dev)) { vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_PF ); +if (IS_ERR (vport)) +return ;
ditto
Quoted 35 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +8
-0mlx5_del_flow_rules (flows[vport->index]); }kvfree (flows);@@ -2385,6 +2397,9 @@ static int esw_set_uplink_slave_ingress_root(struct mlx5_core_dev *master,if (master) { esw = master->priv.eswitch; vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_UPLINK ); +if (IS_ERR (vport)) +return PTR_ERR (vport); +MLX5_SET (set_flow_table_root_in, in, table_of_other_vport,1 );MLX5_SET (set_flow_table_root_in, in, table_vport_number,MLX5_VPORT_UPLINK );@@ -2405,6 +2420,9 @@ static int esw_set_uplink_slave_ingress_root(struct mlx5_core_dev *master, }else { esw = slave->priv.eswitch; vport =mlx5_eswitch_get_vport (esw,MLX5_VPORT_UPLINK ); +if (IS_ERR (vport)) +return PTR_ERR (vport); + ns =mlx5_get_flow_vport_acl_namespace (slave,MLX5_FLOW_NAMESPACE_ESW_INGRESS , vport->index);@@ -2590,6 +2608,8 @@ static void esw_unset_master_egress_rule(struct mlx5_core_dev *dev) vport =mlx5_eswitch_get_vport (dev->priv.eswitch, dev->priv.eswitch->manager_vport); +if (IS_ERR (vport)) +return ;esw_acl_egress_ofld_cleanup (vport); }Signature · 1 line
2.25.1