Skip to content

Commit

Permalink
isisd: move flex_algo_delete into flex_algo_destroy
Browse files Browse the repository at this point in the history
Move flex_algo_delete() content into isis_instance_flex_algo_destroy()
because it is called only once.

Rename _flex_algo_delete to flex_algo_free()

Cosmetic change.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
  • Loading branch information
louis-6wind committed Jul 26, 2024
1 parent 67e2718 commit 9c0e668
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
8 changes: 7 additions & 1 deletion isisd/isis_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,8 @@ int isis_instance_flex_algo_create(struct nb_cb_create_args *args)

int isis_instance_flex_algo_destroy(struct nb_cb_destroy_args *args)
{
struct listnode *node, *nnode;
struct flex_algo *fa;
struct isis_area *area;
uint32_t algorithm;

Expand All @@ -2883,7 +2885,11 @@ int isis_instance_flex_algo_destroy(struct nb_cb_destroy_args *args)

switch (args->event) {
case NB_EV_APPLY:
flex_algo_delete(area->flex_algos, algorithm);
for (ALL_LIST_ELEMENTS(area->flex_algos->flex_algos, node,
nnode, fa)) {
if (fa->algorithm == algorithm)
flex_algo_free(area->flex_algos, fa);
}
lsp_regenerate_schedule(area, area->is_type, 0);
break;
case NB_EV_VALIDATE:
Expand Down
21 changes: 2 additions & 19 deletions lib/flex_algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO_DATABASE, "Flex-Algo database");
DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO, "Flex-Algo algorithm information");

static void _flex_algo_delete(struct flex_algos *flex_algos,
struct flex_algo *fa);

struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator,
flex_algo_releaser_t releaser)
{
Expand All @@ -42,7 +39,7 @@ void flex_algos_free(struct flex_algos *flex_algos)
struct flex_algo *fa;

for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa))
_flex_algo_delete(flex_algos, fa);
flex_algo_free(flex_algos, fa);
list_delete(&flex_algos->flex_algos);
XFREE(MTYPE_FLEX_ALGO_DATABASE, flex_algos);
}
Expand All @@ -63,8 +60,7 @@ struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos,
return fa;
}

static void _flex_algo_delete(struct flex_algos *flex_algos,
struct flex_algo *fa)
void flex_algo_free(struct flex_algos *flex_algos, struct flex_algo *fa)
{
if (flex_algos->releaser)
flex_algos->releaser(fa->data);
Expand All @@ -75,19 +71,6 @@ static void _flex_algo_delete(struct flex_algos *flex_algos,
XFREE(MTYPE_FLEX_ALGO, fa);
}


void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm)
{
struct listnode *node, *nnode;
struct flex_algo *fa;

for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa)) {
if (fa->algorithm != algorithm)
continue;
_flex_algo_delete(flex_algos, fa);
}
}

/**
* @brief Look up the local flex-algo object by its algorithm number.
* @param algorithm flex-algo algorithm number
Expand Down
2 changes: 1 addition & 1 deletion lib/flex_algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator,
void flex_algos_free(struct flex_algos *flex_algos);
struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos,
uint8_t algorithm, void *arg);
void flex_algo_free(struct flex_algos *flex_algos, struct flex_algo *fa);
struct flex_algo *flex_algo_lookup(struct flex_algos *flex_algos,
uint8_t algorithm);
bool flex_algo_definition_cmp(struct flex_algo *fa1, struct flex_algo *fa2);
void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm);
bool flex_algo_id_valid(uint16_t algorithm);
char *flex_algo_metric_type_print(char *type_str, size_t sz,
enum flex_algo_metric_type metric_type);
Expand Down

0 comments on commit 9c0e668

Please sign in to comment.