ipv6: Various cleanups in ip6_route.c

1) x == NULL --> !x
2) x != NULL --> x
3) if() --> if ()
4) while() --> while ()
5) (x & BIT) == 0 --> !(x & BIT)
6) (x&BIT) --> (x & BIT)
7) x=y --> x = y
8) (BIT1|BIT2) --> (BIT1 | BIT2)
9) if ((x & BIT)) --> if (x & BIT)
10) proper argument and struct member alignment

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller
2011-12-03 17:50:45 -05:00
parent 340e8dc1fb
commit 507c9b1e07

View File

@@ -190,7 +190,7 @@ static struct fib6_table *fib6_alloc_table(struct net *net, u32 id)
struct fib6_table *table; struct fib6_table *table;
table = kzalloc(sizeof(*table), GFP_ATOMIC); table = kzalloc(sizeof(*table), GFP_ATOMIC);
if (table != NULL) { if (table) {
table->tb6_id = id; table->tb6_id = id;
table->tb6_root.leaf = net->ipv6.ip6_null_entry; table->tb6_root.leaf = net->ipv6.ip6_null_entry;
table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
@@ -210,7 +210,7 @@ struct fib6_table *fib6_new_table(struct net *net, u32 id)
return tb; return tb;
tb = fib6_alloc_table(net, id); tb = fib6_alloc_table(net, id);
if (tb != NULL) if (tb)
fib6_link_table(net, tb); fib6_link_table(net, tb);
return tb; return tb;
@@ -367,7 +367,7 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
s_e = cb->args[1]; s_e = cb->args[1];
w = (void *)cb->args[2]; w = (void *)cb->args[2];
if (w == NULL) { if (!w) {
/* New dump: /* New dump:
* *
* 1. hook callback destructor. * 1. hook callback destructor.
@@ -379,7 +379,7 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
* 2. allocate and initialize walker. * 2. allocate and initialize walker.
*/ */
w = kzalloc(sizeof(*w), GFP_ATOMIC); w = kzalloc(sizeof(*w), GFP_ATOMIC);
if (w == NULL) if (!w)
return -ENOMEM; return -ENOMEM;
w->func = fib6_dump_node; w->func = fib6_dump_node;
cb->args[2] = (long)w; cb->args[2] = (long)w;
@@ -467,7 +467,7 @@ static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr,
if (plen == fn->fn_bit) { if (plen == fn->fn_bit) {
/* clean up an intermediate node */ /* clean up an intermediate node */
if ((fn->fn_flags & RTN_RTINFO) == 0) { if (!(fn->fn_flags & RTN_RTINFO)) {
rt6_release(fn->leaf); rt6_release(fn->leaf);
fn->leaf = NULL; fn->leaf = NULL;
} }
@@ -512,7 +512,7 @@ static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr,
ln = node_alloc(); ln = node_alloc();
if (ln == NULL) if (!ln)
return NULL; return NULL;
ln->fn_bit = plen; ln->fn_bit = plen;
@@ -555,7 +555,7 @@ insert_above:
in = node_alloc(); in = node_alloc();
ln = node_alloc(); ln = node_alloc();
if (in == NULL || ln == NULL) { if (!in || !ln) {
if (in) if (in)
node_free(in); node_free(in);
if (ln) if (ln)
@@ -609,7 +609,7 @@ insert_above:
ln = node_alloc(); ln = node_alloc();
if (ln == NULL) if (!ln)
return NULL; return NULL;
ln->fn_bit = plen; ln->fn_bit = plen;
@@ -642,9 +642,9 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
{ {
struct rt6_info *iter = NULL; struct rt6_info *iter = NULL;
struct rt6_info **ins; struct rt6_info **ins;
int replace = (NULL != info->nlh && int replace = (info->nlh &&
(info->nlh->nlmsg_flags & NLM_F_REPLACE)); (info->nlh->nlmsg_flags & NLM_F_REPLACE));
int add = (NULL == info->nlh || int add = (!info->nlh ||
(info->nlh->nlmsg_flags & NLM_F_CREATE)); (info->nlh->nlmsg_flags & NLM_F_CREATE));
int found = 0; int found = 0;
@@ -659,7 +659,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
/* /*
* Same priority level * Same priority level
*/ */
if (NULL != info->nlh && if (info->nlh &&
(info->nlh->nlmsg_flags & NLM_F_EXCL)) (info->nlh->nlmsg_flags & NLM_F_EXCL))
return -EEXIST; return -EEXIST;
if (replace) { if (replace) {
@@ -707,7 +707,7 @@ add:
inet6_rt_notify(RTM_NEWROUTE, rt, info); inet6_rt_notify(RTM_NEWROUTE, rt, info);
info->nl_net->ipv6.rt6_stats->fib_rt_entries++; info->nl_net->ipv6.rt6_stats->fib_rt_entries++;
if ((fn->fn_flags & RTN_RTINFO) == 0) { if (!(fn->fn_flags & RTN_RTINFO)) {
info->nl_net->ipv6.rt6_stats->fib_route_nodes++; info->nl_net->ipv6.rt6_stats->fib_route_nodes++;
fn->fn_flags |= RTN_RTINFO; fn->fn_flags |= RTN_RTINFO;
} }
@@ -725,7 +725,7 @@ add:
atomic_inc(&rt->rt6i_ref); atomic_inc(&rt->rt6i_ref);
inet6_rt_notify(RTM_NEWROUTE, rt, info); inet6_rt_notify(RTM_NEWROUTE, rt, info);
rt6_release(iter); rt6_release(iter);
if ((fn->fn_flags & RTN_RTINFO) == 0) { if (!(fn->fn_flags & RTN_RTINFO)) {
info->nl_net->ipv6.rt6_stats->fib_route_nodes++; info->nl_net->ipv6.rt6_stats->fib_route_nodes++;
fn->fn_flags |= RTN_RTINFO; fn->fn_flags |= RTN_RTINFO;
} }
@@ -761,10 +761,11 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
int err = -ENOMEM; int err = -ENOMEM;
int allow_create = 1; int allow_create = 1;
int replace_required = 0; int replace_required = 0;
if (NULL != info->nlh) {
if (info->nlh) {
if (!(info->nlh->nlmsg_flags & NLM_F_CREATE)) if (!(info->nlh->nlmsg_flags & NLM_F_CREATE))
allow_create = 0; allow_create = 0;
if ((info->nlh->nlmsg_flags&NLM_F_REPLACE)) if (info->nlh->nlmsg_flags & NLM_F_REPLACE)
replace_required = 1; replace_required = 1;
} }
if (!allow_create && !replace_required) if (!allow_create && !replace_required)
@@ -779,7 +780,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
fn = NULL; fn = NULL;
} }
if (fn == NULL) if (!fn)
goto out; goto out;
pn = fn; pn = fn;
@@ -788,7 +789,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
if (rt->rt6i_src.plen) { if (rt->rt6i_src.plen) {
struct fib6_node *sn; struct fib6_node *sn;
if (fn->subtree == NULL) { if (!fn->subtree) {
struct fib6_node *sfn; struct fib6_node *sfn;
/* /*
@@ -803,7 +804,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
/* Create subtree root node */ /* Create subtree root node */
sfn = node_alloc(); sfn = node_alloc();
if (sfn == NULL) if (!sfn)
goto st_failure; goto st_failure;
sfn->leaf = info->nl_net->ipv6.ip6_null_entry; sfn->leaf = info->nl_net->ipv6.ip6_null_entry;
@@ -818,7 +819,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
offsetof(struct rt6_info, rt6i_src), offsetof(struct rt6_info, rt6i_src),
allow_create, replace_required); allow_create, replace_required);
if (sn == NULL) { if (!sn) {
/* If it is failed, discard just allocated /* If it is failed, discard just allocated
root, and then (in st_failure) stale node root, and then (in st_failure) stale node
in main tree. in main tree.
@@ -840,11 +841,11 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
err = PTR_ERR(sn); err = PTR_ERR(sn);
sn = NULL; sn = NULL;
} }
if (sn == NULL) if (!sn)
goto st_failure; goto st_failure;
} }
if (fn->leaf == NULL) { if (!fn->leaf) {
fn->leaf = rt; fn->leaf = rt;
atomic_inc(&rt->rt6i_ref); atomic_inc(&rt->rt6i_ref);
} }
@@ -853,8 +854,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt, struct nl_info *info)
#endif #endif
err = fib6_add_rt2node(fn, rt, info); err = fib6_add_rt2node(fn, rt, info);
if (!err) {
if (err == 0) {
fib6_start_gc(info->nl_net, rt); fib6_start_gc(info->nl_net, rt);
if (!(rt->rt6i_flags & RTF_CACHE)) if (!(rt->rt6i_flags & RTF_CACHE))
fib6_prune_clones(info->nl_net, pn, rt); fib6_prune_clones(info->nl_net, pn, rt);
@@ -934,7 +934,6 @@ static struct fib6_node * fib6_lookup_1(struct fib6_node *root,
fn = next; fn = next;
continue; continue;
} }
break; break;
} }
@@ -985,8 +984,7 @@ struct fib6_node * fib6_lookup(struct fib6_node *root, const struct in6_addr *da
}; };
fn = fib6_lookup_1(root, daddr ? args : args + 1); fn = fib6_lookup_1(root, daddr ? args : args + 1);
if (!fn || fn->fn_flags & RTN_TL_ROOT)
if (fn == NULL || fn->fn_flags & RTN_TL_ROOT)
fn = root; fn = root;
return fn; return fn;
@@ -1066,7 +1064,6 @@ static struct rt6_info *fib6_find_prefix(struct net *net, struct fib6_node *fn)
while (fn) { while (fn) {
if (fn->left) if (fn->left)
return fn->left->leaf; return fn->left->leaf;
if (fn->right) if (fn->right)
return fn->right->leaf; return fn->right->leaf;
@@ -1110,7 +1107,7 @@ static struct fib6_node *fib6_repair_tree(struct net *net,
) { ) {
fn->leaf = fib6_find_prefix(net, fn); fn->leaf = fib6_find_prefix(net, fn);
#if RT6_DEBUG >= 2 #if RT6_DEBUG >= 2
if (fn->leaf==NULL) { if (!fn->leaf) {
WARN_ON(!fn->leaf); WARN_ON(!fn->leaf);
fn->leaf = net->ipv6.ip6_null_entry; fn->leaf = net->ipv6.ip6_null_entry;
} }
@@ -1143,7 +1140,7 @@ static struct fib6_node *fib6_repair_tree(struct net *net,
read_lock(&fib6_walker_lock); read_lock(&fib6_walker_lock);
FOR_WALKERS(w) { FOR_WALKERS(w) {
if (child == NULL) { if (!child) {
if (w->root == fn) { if (w->root == fn) {
w->root = w->node = NULL; w->root = w->node = NULL;
RT6_TRACE("W %p adjusted by delroot 1\n", w); RT6_TRACE("W %p adjusted by delroot 1\n", w);
@@ -1206,7 +1203,7 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
if (w->state == FWS_C && w->leaf == rt) { if (w->state == FWS_C && w->leaf == rt) {
RT6_TRACE("walker %p adjusted by delroute\n", w); RT6_TRACE("walker %p adjusted by delroute\n", w);
w->leaf = rt->dst.rt6_next; w->leaf = rt->dst.rt6_next;
if (w->leaf == NULL) if (!w->leaf)
w->state = FWS_U; w->state = FWS_U;
} }
} }
@@ -1215,7 +1212,7 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
rt->dst.rt6_next = NULL; rt->dst.rt6_next = NULL;
/* If it was last route, expunge its radix tree node */ /* If it was last route, expunge its radix tree node */
if (fn->leaf == NULL) { if (!fn->leaf) {
fn->fn_flags &= ~RTN_RTINFO; fn->fn_flags &= ~RTN_RTINFO;
net->ipv6.rt6_stats->fib_route_nodes--; net->ipv6.rt6_stats->fib_route_nodes--;
fn = fib6_repair_tree(net, fn); fn = fib6_repair_tree(net, fn);
@@ -1256,7 +1253,7 @@ int fib6_del(struct rt6_info *rt, struct nl_info *info)
return -ENOENT; return -ENOENT;
} }
#endif #endif
if (fn == NULL || rt == net->ipv6.ip6_null_entry) if (!fn || rt == net->ipv6.ip6_null_entry)
return -ENOENT; return -ENOENT;
WARN_ON(!(fn->fn_flags & RTN_RTINFO)); WARN_ON(!(fn->fn_flags & RTN_RTINFO));
@@ -1317,7 +1314,7 @@ static int fib6_walk_continue(struct fib6_walker_t *w)
for (;;) { for (;;) {
fn = w->node; fn = w->node;
if (fn == NULL) if (!fn)
return 0; return 0;
if (w->prune && fn != w->root && if (w->prune && fn != w->root &&