Commit 6311f308 authored by Gavi Teitz's avatar Gavi Teitz Committed by Saeed Mahameed

net/mlx5: MPFS, Cleanup add MAC flow

Unify and isolate the error handling flow in mlx5_mpfs_add_mac(),
removing code duplication.
Signed-off-by: default avatarGavi Teitz <gavi@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 4f5d1bea
...@@ -134,8 +134,8 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac) ...@@ -134,8 +134,8 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac)
{ {
struct mlx5_mpfs *mpfs = dev->priv.mpfs; struct mlx5_mpfs *mpfs = dev->priv.mpfs;
struct l2table_node *l2addr; struct l2table_node *l2addr;
int err = 0;
u32 index; u32 index;
int err;
if (!MLX5_ESWITCH_MANAGER(dev)) if (!MLX5_ESWITCH_MANAGER(dev))
return 0; return 0;
...@@ -145,29 +145,33 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac) ...@@ -145,29 +145,33 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac)
l2addr = l2addr_hash_find(mpfs->hash, mac, struct l2table_node); l2addr = l2addr_hash_find(mpfs->hash, mac, struct l2table_node);
if (l2addr) { if (l2addr) {
err = -EEXIST; err = -EEXIST;
goto abort; goto out;
} }
err = alloc_l2table_index(mpfs, &index); err = alloc_l2table_index(mpfs, &index);
if (err) if (err)
goto abort; goto out;
l2addr = l2addr_hash_add(mpfs->hash, mac, struct l2table_node, GFP_KERNEL); l2addr = l2addr_hash_add(mpfs->hash, mac, struct l2table_node, GFP_KERNEL);
if (!l2addr) { if (!l2addr) {
free_l2table_index(mpfs, index);
err = -ENOMEM; err = -ENOMEM;
goto abort; goto hash_add_err;
} }
l2addr->index = index;
err = set_l2table_entry_cmd(dev, index, mac); err = set_l2table_entry_cmd(dev, index, mac);
if (err) { if (err)
l2addr_hash_del(l2addr); goto set_table_entry_err;
free_l2table_index(mpfs, index);
} l2addr->index = index;
mlx5_core_dbg(dev, "MPFS mac added %pM, index (%d)\n", mac, index); mlx5_core_dbg(dev, "MPFS mac added %pM, index (%d)\n", mac, index);
abort: goto out;
set_table_entry_err:
l2addr_hash_del(l2addr);
hash_add_err:
free_l2table_index(mpfs, index);
out:
mutex_unlock(&mpfs->lock); mutex_unlock(&mpfs->lock);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment