Commit fea86ad8 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller

[IPV4] fib_trie: fib_insert_node cleanup

The only error from fib_insert_node is if memory allocation fails, so
instead of passing by reference, just use the convention of returning
NULL.
Signed-off-by: default avatarStephen Hemminger <stephen.hemminger@vyatta.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 187b5188
...@@ -980,8 +980,7 @@ static struct node *trie_rebalance(struct trie *t, struct tnode *tn) ...@@ -980,8 +980,7 @@ static struct node *trie_rebalance(struct trie *t, struct tnode *tn)
/* only used from updater-side */ /* only used from updater-side */
static struct list_head * static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen)
fib_insert_node(struct trie *t, int *err, u32 key, int plen)
{ {
int pos, newpos; int pos, newpos;
struct tnode *tp = NULL, *tn = NULL; struct tnode *tp = NULL, *tn = NULL;
...@@ -1043,10 +1042,8 @@ fib_insert_node(struct trie *t, int *err, u32 key, int plen) ...@@ -1043,10 +1042,8 @@ fib_insert_node(struct trie *t, int *err, u32 key, int plen)
li = leaf_info_new(plen); li = leaf_info_new(plen);
if (!li) { if (!li)
*err = -ENOMEM; return NULL;
goto done;
}
fa_head = &li->falh; fa_head = &li->falh;
insert_leaf_info(&l->list, li); insert_leaf_info(&l->list, li);
...@@ -1055,18 +1052,15 @@ fib_insert_node(struct trie *t, int *err, u32 key, int plen) ...@@ -1055,18 +1052,15 @@ fib_insert_node(struct trie *t, int *err, u32 key, int plen)
t->size++; t->size++;
l = leaf_new(); l = leaf_new();
if (!l) { if (!l)
*err = -ENOMEM; return NULL;
goto done;
}
l->key = key; l->key = key;
li = leaf_info_new(plen); li = leaf_info_new(plen);
if (!li) { if (!li) {
tnode_free((struct tnode *) l); tnode_free((struct tnode *) l);
*err = -ENOMEM; return NULL;
goto done;
} }
fa_head = &li->falh; fa_head = &li->falh;
...@@ -1102,8 +1096,7 @@ fib_insert_node(struct trie *t, int *err, u32 key, int plen) ...@@ -1102,8 +1096,7 @@ fib_insert_node(struct trie *t, int *err, u32 key, int plen)
if (!tn) { if (!tn) {
free_leaf_info(li); free_leaf_info(li);
tnode_free((struct tnode *) l); tnode_free((struct tnode *) l);
*err = -ENOMEM; return NULL;
goto done;
} }
node_set_parent((struct node *)tn, tp); node_set_parent((struct node *)tn, tp);
...@@ -1262,11 +1255,12 @@ static int fn_trie_insert(struct fib_table *tb, struct fib_config *cfg) ...@@ -1262,11 +1255,12 @@ static int fn_trie_insert(struct fib_table *tb, struct fib_config *cfg)
*/ */
if (!fa_head) { if (!fa_head) {
err = 0; fa_head = fib_insert_node(t, key, plen);
fa_head = fib_insert_node(t, &err, key, plen); if (unlikely(!fa_head)) {
if (err) err = -ENOMEM;
goto out_free_new_fa; goto out_free_new_fa;
} }
}
list_add_tail_rcu(&new_fa->fa_list, list_add_tail_rcu(&new_fa->fa_list,
(fa ? &fa->fa_list : fa_head)); (fa ? &fa->fa_list : fa_head));
......
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