]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
[IPV4]: Unify assignment of fi to fib_result
authorDenis V. Lunev <den@openvz.org>
Sat, 8 Dec 2007 08:31:44 +0000 (00:31 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jan 2008 22:57:01 +0000 (14:57 -0800)
Signed-off-by: Denis V. Lunev <den@openvz.org>
Acked-by: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/fib_hash.c
net/ipv4/fib_lookup.h
net/ipv4/fib_trie.c

index 143a5213a185cb6c6fb6ca8b7e4d5830006b6cdb..86087d45c64e29548fdc134fe5dcf330f6f65654 100644 (file)
@@ -315,10 +315,7 @@ fn_hash_select_default(struct fib_table *tb, const struct flowi *flp, struct fib
                                        break;
                        } else if (!fib_detect_death(fi, order, &last_resort,
                                                     &last_idx, fn_hash_last_dflt)) {
-                               if (res->fi)
-                                       fib_info_put(res->fi);
-                               res->fi = fi;
-                               atomic_inc(&fi->fib_clntref);
+                               fib_result_assign(res, fi);
                                fn_hash_last_dflt = order;
                                goto out;
                        }
@@ -333,21 +330,13 @@ fn_hash_select_default(struct fib_table *tb, const struct flowi *flp, struct fib
        }
 
        if (!fib_detect_death(fi, order, &last_resort, &last_idx, fn_hash_last_dflt)) {
-               if (res->fi)
-                       fib_info_put(res->fi);
-               res->fi = fi;
-               atomic_inc(&fi->fib_clntref);
+               fib_result_assign(res, fi);
                fn_hash_last_dflt = order;
                goto out;
        }
 
-       if (last_idx >= 0) {
-               if (res->fi)
-                       fib_info_put(res->fi);
-               res->fi = last_resort;
-               if (last_resort)
-                       atomic_inc(&last_resort->fib_clntref);
-       }
+       if (last_idx >= 0)
+               fib_result_assign(res, last_resort);
        fn_hash_last_dflt = last_idx;
 out:
        read_unlock(&fib_hash_lock);
index 6c9dd4282db03ad576012cb316b0fb701587f3d8..26ee66d78c183e3dbe0c6463016809fd0b537117 100644 (file)
@@ -38,4 +38,14 @@ extern int fib_detect_death(struct fib_info *fi, int order,
                            struct fib_info **last_resort,
                            int *last_idx, int dflt);
 
+static inline void fib_result_assign(struct fib_result *res,
+                                    struct fib_info *fi)
+{
+       if (res->fi != NULL)
+               fib_info_put(res->fi);
+       res->fi = fi;
+       if (fi != NULL)
+               atomic_inc(&fi->fib_clntref);
+}
+
 #endif /* _FIB_LOOKUP_H */
index d48a9bbcf54d800abda77847b7820e3d2202b531..c7c5c6c802dfd2edc58756f0b071b5220bf6f46f 100644 (file)
@@ -1831,10 +1831,7 @@ fn_trie_select_default(struct fib_table *tb, const struct flowi *flp, struct fib
                                break;
                } else if (!fib_detect_death(fi, order, &last_resort,
                                             &last_idx, trie_last_dflt)) {
-                       if (res->fi)
-                               fib_info_put(res->fi);
-                       res->fi = fi;
-                       atomic_inc(&fi->fib_clntref);
+                       fib_result_assign(res, fi);
                        trie_last_dflt = order;
                        goto out;
                }
@@ -1847,20 +1844,12 @@ fn_trie_select_default(struct fib_table *tb, const struct flowi *flp, struct fib
        }
 
        if (!fib_detect_death(fi, order, &last_resort, &last_idx, trie_last_dflt)) {
-               if (res->fi)
-                       fib_info_put(res->fi);
-               res->fi = fi;
-               atomic_inc(&fi->fib_clntref);
+               fib_result_assign(res, fi);
                trie_last_dflt = order;
                goto out;
        }
-       if (last_idx >= 0) {
-               if (res->fi)
-                       fib_info_put(res->fi);
-               res->fi = last_resort;
-               if (last_resort)
-                       atomic_inc(&last_resort->fib_clntref);
-       }
+       if (last_idx >= 0)
+               fib_result_assign(res, last_resort);
        trie_last_dflt = last_idx;
  out:;
        rcu_read_unlock();