Change inflate/halve to use the ERR_PTR return value method to
avoid having to pass error code by reference.

Signed-off-by: Stephen Hemminger <[EMAIL PROTECTED]>

Index: fib/net/ipv4/fib_trie.c
===================================================================
--- fib.orig/net/ipv4/fib_trie.c
+++ fib/net/ipv4/fib_trie.c
@@ -163,8 +163,8 @@ static void put_child(struct trie *t, st
 static void tnode_put_child_reorg(struct tnode *tn, int i, struct node *n, int 
wasfull);
 static int tnode_child_length(struct tnode *tn);
 static struct node *resize(struct trie *t, struct tnode *tn);
-static struct tnode *inflate(struct trie *t, struct tnode *tn, int *err);
-static struct tnode *halve(struct trie *t, struct tnode *tn, int *err);
+static struct tnode *inflate(struct trie *t, struct tnode *tn);
+static struct tnode *halve(struct trie *t, struct tnode *tn);
 static void tnode_free(struct tnode *tn);
 static void trie_dump_seq(struct seq_file *seq, struct trie *t);
 extern struct fib_alias *fib_find_alias(struct list_head *fah, u8 tos, u32 
prio);
@@ -565,9 +565,8 @@ static struct node *resize(struct trie *
               50 * (tn->full_children + tnode_child_length(tn) - 
tn->empty_children) >=
                                inflate_threshold * tnode_child_length(tn))) {
 
-               tn = inflate(t, tn, &err);
-
-               if (err) {
+               tn = inflate(t, tn);
+               if (IS_ERR(tn)) {
 #ifdef CONFIG_IP_FIB_TRIE_STATS
                        t->stats.resize_node_skipped++;
 #endif
@@ -587,9 +586,8 @@ static struct node *resize(struct trie *
               100 * (tnode_child_length(tn) - tn->empty_children) <
               halve_threshold * tnode_child_length(tn)) {
 
-               tn = halve(t, tn, &err);
-
-               if (err) {
+               tn = halve(t, tn);
+               if (IS_ERR(tn)) {
 #ifdef CONFIG_IP_FIB_TRIE_STATS
                        t->stats.resize_node_skipped++;
 #endif
@@ -621,7 +619,7 @@ static struct node *resize(struct trie *
        return (struct node *) tn;
 }
 
-static struct tnode *inflate(struct trie *t, struct tnode *tn, int *err)
+static struct tnode *inflate(struct trie *t, struct tnode *tn)
 {
        struct tnode *inode;
        struct tnode *oldtnode = tn;
@@ -632,10 +630,8 @@ static struct tnode *inflate(struct trie
 
        tn = tnode_new(oldtnode->key, oldtnode->pos, oldtnode->bits + 1);
 
-       if (!tn) {
-               *err = -ENOMEM;
-               return oldtnode;
-       }
+       if (!tn) 
+               return ERR_PTR(-ENOMEM);
 
        /*
         * Preallocate and store tnodes before the actual work so we
@@ -657,18 +653,16 @@ static struct tnode *inflate(struct trie
 
                        left = tnode_new(inode->key&(~m), inode->pos + 1,
                                         inode->bits - 1);
+                       if (left)
+                               goto nomem;
 
-                       if (!left) {
-                               *err = -ENOMEM;
-                               break;
-                       }
-               
                        right = tnode_new(inode->key|m, inode->pos + 1,
                                          inode->bits - 1);
 
                        if (!right) {
-                               *err = -ENOMEM;
-                               break;
+                               tnode_free(left);
+                               goto nomem;
+
                        }
 
                        put_child(t, tn, 2*i, (struct node *) left);
@@ -676,20 +670,6 @@ static struct tnode *inflate(struct trie
                }
        }
 
-       if (*err) {
-               int size = tnode_child_length(tn);
-               int j;
-
-               for(j = 0; j < size; j++)
-                       if (tn->child[j])
-                               tnode_free((struct tnode *)tn->child[j]);
-
-               tnode_free(tn);
-       
-               *err = -ENOMEM;
-               return oldtnode;
-       }
-
        for(i = 0; i < olen; i++) {
                struct node *node = tnode_get_child(oldtnode, i);
 
@@ -768,9 +748,22 @@ static struct tnode *inflate(struct trie
        }
        tnode_free(oldtnode);
        return tn;
+nomem:
+       {
+               int size = tnode_child_length(tn);
+               int j;
+
+               for(j = 0; j < size; j++)
+                       if (tn->child[j])
+                               tnode_free((struct tnode *)tn->child[j]);
+
+               tnode_free(tn);
+       
+               return ERR_PTR(-ENOMEM);
+       }
 }
 
-static struct tnode *halve(struct trie *t, struct tnode *tn, int *err)
+static struct tnode *halve(struct trie *t, struct tnode *tn)
 {
        struct tnode *oldtnode = tn;
        struct node *left, *right;
@@ -781,10 +774,8 @@ static struct tnode *halve(struct trie *
 
        tn = tnode_new(oldtnode->key, oldtnode->pos, oldtnode->bits - 1);
 
-       if (!tn) {
-               *err = -ENOMEM;
-               return oldtnode;
-       }
+       if (!tn)
+               return ERR_PTR(-ENOMEM);
 
        /*
         * Preallocate and store tnodes before the actual work so we
@@ -799,29 +790,15 @@ static struct tnode *halve(struct trie *
 
                /* Two nonempty children */
                if (left && right)  {
-                       struct tnode *newBinNode =
-                               tnode_new(left->key, tn->pos + tn->bits, 1);
+                       struct tnode *newn;
 
-                       if (!newBinNode) {
-                               *err = -ENOMEM;
-                               break;
-                       }
-                       put_child(t, tn, i/2, (struct node *)newBinNode);
-               }
-       }
-
-       if (*err) {
-               int size = tnode_child_length(tn);
-               int j;
+                       newn = tnode_new(left->key, tn->pos + tn->bits, 1);
 
-               for(j = 0; j < size; j++)
-                       if (tn->child[j])
-                               tnode_free((struct tnode *)tn->child[j]);
+                       if (!newn) 
+                               goto nomem;
 
-               tnode_free(tn);
-       
-               *err = -ENOMEM;
-               return oldtnode;
+                       put_child(t, tn, i/2, (struct node *)newn);
+               }
        }
 
        for(i = 0; i < olen; i += 2) {
@@ -851,6 +828,19 @@ static struct tnode *halve(struct trie *
        }
        tnode_free(oldtnode);
        return tn;
+nomem:
+       {
+               int size = tnode_child_length(tn);
+               int j;
+
+               for(j = 0; j < size; j++)
+                       if (tn->child[j])
+                               tnode_free((struct tnode *)tn->child[j]);
+
+               tnode_free(tn);
+       
+               return ERR_PTR(-ENOMEM);
+       }
 }
 
 static void *trie_init(struct trie *t)

--

-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to