Commit b04720ae authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller
Browse files

mlxsw: spectrum_router: Consolidate identical functions



After the last patch mlxsw_sp_fib{4,6}_node_entry_link() and
mlxsw_sp_fib{4,6}_node_entry_unlink() are identical and can therefore be
consolidated into the same common function.

Perform the consolidation.

Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0705297e
Loading
Loading
Loading
Loading
+22 −49
Original line number Diff line number Diff line
@@ -4813,31 +4813,31 @@ static void mlxsw_sp_fib_node_entry_del(struct mlxsw_sp *mlxsw_sp,
	mlxsw_sp_fib_entry_del(mlxsw_sp, fib_entry);
}

static int mlxsw_sp_fib4_node_entry_link(struct mlxsw_sp *mlxsw_sp,
					 struct mlxsw_sp_fib4_entry *fib4_entry)
static int mlxsw_sp_fib_node_entry_link(struct mlxsw_sp *mlxsw_sp,
					struct mlxsw_sp_fib_entry *fib_entry)
{
	struct mlxsw_sp_fib_node *fib_node = fib4_entry->common.fib_node;
	struct mlxsw_sp_fib_node *fib_node = fib_entry->fib_node;
	int err;

	list_add(&fib4_entry->common.list, &fib_node->entry_list);
	list_add(&fib_entry->list, &fib_node->entry_list);

	err = mlxsw_sp_fib_node_entry_add(mlxsw_sp, &fib4_entry->common);
	err = mlxsw_sp_fib_node_entry_add(mlxsw_sp, fib_entry);
	if (err)
		goto err_fib_node_entry_add;

	return 0;

err_fib_node_entry_add:
	list_del(&fib4_entry->common.list);
	list_del(&fib_entry->list);
	return err;
}

static void
mlxsw_sp_fib4_node_entry_unlink(struct mlxsw_sp *mlxsw_sp,
				struct mlxsw_sp_fib4_entry *fib4_entry)
mlxsw_sp_fib_node_entry_unlink(struct mlxsw_sp *mlxsw_sp,
			       struct mlxsw_sp_fib_entry *fib_entry)
{
	mlxsw_sp_fib_node_entry_del(mlxsw_sp, &fib4_entry->common);
	list_del(&fib4_entry->common.list);
	mlxsw_sp_fib_node_entry_del(mlxsw_sp, fib_entry);
	list_del(&fib_entry->list);
}

static void mlxsw_sp_fib4_entry_replace(struct mlxsw_sp *mlxsw_sp,
@@ -4852,7 +4852,7 @@ static void mlxsw_sp_fib4_entry_replace(struct mlxsw_sp *mlxsw_sp,
	/* We inserted the new entry before replaced one */
	replaced = list_next_entry(fib4_entry, common.list);

	mlxsw_sp_fib4_node_entry_unlink(mlxsw_sp, replaced);
	mlxsw_sp_fib_node_entry_unlink(mlxsw_sp, &replaced->common);
	mlxsw_sp_fib4_entry_destroy(mlxsw_sp, replaced);
	mlxsw_sp_fib_node_put(mlxsw_sp, fib_node);
}
@@ -4884,17 +4884,17 @@ mlxsw_sp_router_fib4_replace(struct mlxsw_sp *mlxsw_sp,
		goto err_fib4_entry_create;
	}

	err = mlxsw_sp_fib4_node_entry_link(mlxsw_sp, fib4_entry);
	err = mlxsw_sp_fib_node_entry_link(mlxsw_sp, &fib4_entry->common);
	if (err) {
		dev_warn(mlxsw_sp->bus_info->dev, "Failed to link FIB entry to node\n");
		goto err_fib4_node_entry_link;
		goto err_fib_node_entry_link;
	}

	mlxsw_sp_fib4_entry_replace(mlxsw_sp, fib4_entry);

	return 0;

err_fib4_node_entry_link:
err_fib_node_entry_link:
	mlxsw_sp_fib4_entry_destroy(mlxsw_sp, fib4_entry);
err_fib4_entry_create:
	mlxsw_sp_fib_node_put(mlxsw_sp, fib_node);
@@ -4915,7 +4915,7 @@ static void mlxsw_sp_router_fib4_del(struct mlxsw_sp *mlxsw_sp,
		return;
	fib_node = fib4_entry->common.fib_node;

	mlxsw_sp_fib4_node_entry_unlink(mlxsw_sp, fib4_entry);
	mlxsw_sp_fib_node_entry_unlink(mlxsw_sp, &fib4_entry->common);
	mlxsw_sp_fib4_entry_destroy(mlxsw_sp, fib4_entry);
	mlxsw_sp_fib_node_put(mlxsw_sp, fib_node);
}
@@ -5374,33 +5374,6 @@ static void mlxsw_sp_fib6_entry_destroy(struct mlxsw_sp *mlxsw_sp,
	kfree(fib6_entry);
}

static int mlxsw_sp_fib6_node_entry_link(struct mlxsw_sp *mlxsw_sp,
					 struct mlxsw_sp_fib6_entry *fib6_entry)
{
	struct mlxsw_sp_fib_node *fib_node = fib6_entry->common.fib_node;
	int err;

	list_add(&fib6_entry->common.list, &fib_node->entry_list);

	err = mlxsw_sp_fib_node_entry_add(mlxsw_sp, &fib6_entry->common);
	if (err)
		goto err_fib_node_entry_add;

	return 0;

err_fib_node_entry_add:
	list_del(&fib6_entry->common.list);
	return err;
}

static void
mlxsw_sp_fib6_node_entry_unlink(struct mlxsw_sp *mlxsw_sp,
				struct mlxsw_sp_fib6_entry *fib6_entry)
{
	mlxsw_sp_fib_node_entry_del(mlxsw_sp, &fib6_entry->common);
	list_del(&fib6_entry->common.list);
}

static struct mlxsw_sp_fib6_entry *
mlxsw_sp_fib6_entry_lookup(struct mlxsw_sp *mlxsw_sp,
			   const struct fib6_info *rt)
@@ -5445,7 +5418,7 @@ static void mlxsw_sp_fib6_entry_replace(struct mlxsw_sp *mlxsw_sp,
	/* We inserted the new entry before replaced one */
	replaced = list_next_entry(fib6_entry, common.list);

	mlxsw_sp_fib6_node_entry_unlink(mlxsw_sp, replaced);
	mlxsw_sp_fib_node_entry_unlink(mlxsw_sp, &replaced->common);
	mlxsw_sp_fib6_entry_destroy(mlxsw_sp, replaced);
	mlxsw_sp_fib_node_put(mlxsw_sp, fib_node);
}
@@ -5483,15 +5456,15 @@ static int mlxsw_sp_router_fib6_replace(struct mlxsw_sp *mlxsw_sp,
		goto err_fib6_entry_create;
	}

	err = mlxsw_sp_fib6_node_entry_link(mlxsw_sp, fib6_entry);
	err = mlxsw_sp_fib_node_entry_link(mlxsw_sp, &fib6_entry->common);
	if (err)
		goto err_fib6_node_entry_link;
		goto err_fib_node_entry_link;

	mlxsw_sp_fib6_entry_replace(mlxsw_sp, fib6_entry);

	return 0;

err_fib6_node_entry_link:
err_fib_node_entry_link:
	mlxsw_sp_fib6_entry_destroy(mlxsw_sp, fib6_entry);
err_fib6_entry_create:
	mlxsw_sp_fib_node_put(mlxsw_sp, fib_node);
@@ -5577,7 +5550,7 @@ static void mlxsw_sp_router_fib6_del(struct mlxsw_sp *mlxsw_sp,

	fib_node = fib6_entry->common.fib_node;

	mlxsw_sp_fib6_node_entry_unlink(mlxsw_sp, fib6_entry);
	mlxsw_sp_fib_node_entry_unlink(mlxsw_sp, &fib6_entry->common);
	mlxsw_sp_fib6_entry_destroy(mlxsw_sp, fib6_entry);
	mlxsw_sp_fib_node_put(mlxsw_sp, fib_node);
}
@@ -5737,7 +5710,7 @@ static void mlxsw_sp_fib4_node_flush(struct mlxsw_sp *mlxsw_sp,
				 common.list) {
		bool do_break = &tmp->common.list == &fib_node->entry_list;

		mlxsw_sp_fib4_node_entry_unlink(mlxsw_sp, fib4_entry);
		mlxsw_sp_fib_node_entry_unlink(mlxsw_sp, &fib4_entry->common);
		mlxsw_sp_fib4_entry_destroy(mlxsw_sp, fib4_entry);
		mlxsw_sp_fib_node_put(mlxsw_sp, fib_node);
		/* Break when entry list is empty and node was freed.
@@ -5758,7 +5731,7 @@ static void mlxsw_sp_fib6_node_flush(struct mlxsw_sp *mlxsw_sp,
				 common.list) {
		bool do_break = &tmp->common.list == &fib_node->entry_list;

		mlxsw_sp_fib6_node_entry_unlink(mlxsw_sp, fib6_entry);
		mlxsw_sp_fib_node_entry_unlink(mlxsw_sp, &fib6_entry->common);
		mlxsw_sp_fib6_entry_destroy(mlxsw_sp, fib6_entry);
		mlxsw_sp_fib_node_put(mlxsw_sp, fib_node);
		if (do_break)