Skip to content

Commit 3830847

Browse files
committed
ipv6: Various cleanups in route.c
1) x == NULL --> !x 2) x != NULL --> x 3) (x&BIT) --> (x & BIT) 4) (BIT1|BIT2) --> (BIT1 | BIT2) 5) proper argument and struct member alignment Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 507c9b1 commit 3830847

1 file changed

Lines changed: 48 additions & 47 deletions

File tree

‎net/ipv6/route.c‎

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ static inline struct rt6_info *ip6_dst_alloc(struct dst_ops *ops,
247247
{
248248
struct rt6_info *rt = dst_alloc(ops, dev, 0, 0, flags);
249249

250-
if (rt != NULL)
250+
if (rt)
251251
memset(&rt->rt6i_table, 0,
252-
sizeof(*rt) - sizeof(struct dst_entry));
252+
sizeof(*rt) - sizeof(struct dst_entry));
253253

254254
return rt;
255255
}
@@ -263,7 +263,7 @@ static void ip6_dst_destroy(struct dst_entry *dst)
263263
if (!(rt->dst.flags & DST_HOST))
264264
dst_destroy_metrics_generic(dst);
265265

266-
if (idev != NULL) {
266+
if (idev) {
267267
rt->rt6i_idev = NULL;
268268
in6_dev_put(idev);
269269
}
@@ -299,10 +299,10 @@ static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev,
299299
struct net_device *loopback_dev =
300300
dev_net(dev)->loopback_dev;
301301

302-
if (dev != loopback_dev && idev != NULL && idev->dev == dev) {
302+
if (dev != loopback_dev && idev && idev->dev == dev) {
303303
struct inet6_dev *loopback_idev =
304304
in6_dev_get(loopback_dev);
305-
if (loopback_idev != NULL) {
305+
if (loopback_idev) {
306306
rt->rt6i_idev = loopback_idev;
307307
in6_dev_put(idev);
308308
}
@@ -344,7 +344,7 @@ static inline struct rt6_info *rt6_device_match(struct net *net,
344344
if (dev->ifindex == oif)
345345
return sprt;
346346
if (dev->flags & IFF_LOOPBACK) {
347-
if (sprt->rt6i_idev == NULL ||
347+
if (!sprt->rt6i_idev ||
348348
sprt->rt6i_idev->dev->ifindex != oif) {
349349
if (flags & RT6_LOOKUP_F_IFACE && oif)
350350
continue;
@@ -636,7 +636,7 @@ do { \
636636
goto restart; \
637637
} \
638638
} \
639-
} while(0)
639+
} while (0)
640640

641641
static struct rt6_info *ip6_pol_route_lookup(struct net *net,
642642
struct fib6_table *table,
@@ -727,7 +727,7 @@ static struct rt6_info *rt6_alloc_cow(const struct rt6_info *ort,
727727
struct neighbour *neigh;
728728
int attempts = !in_softirq();
729729

730-
if (!(rt->rt6i_flags&RTF_GATEWAY)) {
730+
if (!(rt->rt6i_flags & RTF_GATEWAY)) {
731731
if (rt->rt6i_dst.plen != 128 &&
732732
ipv6_addr_equal(&ort->rt6i_dst.addr, daddr))
733733
rt->rt6i_flags |= RTF_ANYCAST;
@@ -875,7 +875,7 @@ void ip6_route_input(struct sk_buff *skb)
875875
.flowi6_iif = skb->dev->ifindex,
876876
.daddr = iph->daddr,
877877
.saddr = iph->saddr,
878-
.flowlabel = (* (__be32 *) iph)&IPV6_FLOWINFO_MASK,
878+
.flowlabel = (* (__be32 *) iph) & IPV6_FLOWINFO_MASK,
879879
.flowi6_mark = skb->mark,
880880
.flowi6_proto = iph->nexthdr,
881881
};
@@ -997,7 +997,7 @@ static void ip6_link_failure(struct sk_buff *skb)
997997

998998
rt = (struct rt6_info *) skb_dst(skb);
999999
if (rt) {
1000-
if (rt->rt6i_flags&RTF_CACHE) {
1000+
if (rt->rt6i_flags & RTF_CACHE) {
10011001
dst_set_expires(&rt->dst, 0);
10021002
rt->rt6i_flags |= RTF_EXPIRES;
10031003
} else if (rt->rt6i_node && (rt->rt6i_flags & RTF_DEFAULT))
@@ -1073,11 +1073,11 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
10731073
struct inet6_dev *idev = in6_dev_get(dev);
10741074
struct net *net = dev_net(dev);
10751075

1076-
if (unlikely(idev == NULL))
1076+
if (unlikely(!idev))
10771077
return NULL;
10781078

10791079
rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops, dev, 0);
1080-
if (unlikely(rt == NULL)) {
1080+
if (unlikely(!rt)) {
10811081
in6_dev_put(idev);
10821082
goto out;
10831083
}
@@ -1238,23 +1238,23 @@ int ip6_route_add(struct fib6_config *cfg)
12381238
cfg->fc_metric = IP6_RT_PRIO_USER;
12391239

12401240
err = -ENOBUFS;
1241-
if (NULL != cfg->fc_nlinfo.nlh &&
1242-
!(cfg->fc_nlinfo.nlh->nlmsg_flags&NLM_F_CREATE)) {
1241+
if (cfg->fc_nlinfo.nlh &&
1242+
!(cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_CREATE)) {
12431243
table = fib6_get_table(net, cfg->fc_table);
1244-
if (table == NULL) {
1244+
if (!table) {
12451245
printk(KERN_WARNING "IPv6: NLM_F_CREATE should be specified when creating new route\n");
12461246
table = fib6_new_table(net, cfg->fc_table);
12471247
}
12481248
} else {
12491249
table = fib6_new_table(net, cfg->fc_table);
12501250
}
1251-
if (table == NULL) {
1251+
1252+
if (!table)
12521253
goto out;
1253-
}
12541254

12551255
rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops, NULL, DST_NOCOUNT);
12561256

1257-
if (rt == NULL) {
1257+
if (!rt) {
12581258
err = -ENOMEM;
12591259
goto out;
12601260
}
@@ -1303,8 +1303,9 @@ int ip6_route_add(struct fib6_config *cfg)
13031303
they would result in kernel looping; promote them to reject routes
13041304
*/
13051305
if ((cfg->fc_flags & RTF_REJECT) ||
1306-
(dev && (dev->flags&IFF_LOOPBACK) && !(addr_type&IPV6_ADDR_LOOPBACK)
1307-
&& !(cfg->fc_flags&RTF_LOCAL))) {
1306+
(dev && (dev->flags & IFF_LOOPBACK) &&
1307+
!(addr_type & IPV6_ADDR_LOOPBACK) &&
1308+
!(cfg->fc_flags & RTF_LOCAL))) {
13081309
/* hold loopback dev/idev if we haven't done so. */
13091310
if (dev != net->loopback_dev) {
13101311
if (dev) {
@@ -1345,13 +1346,13 @@ int ip6_route_add(struct fib6_config *cfg)
13451346
some exceptions. --ANK
13461347
*/
13471348
err = -EINVAL;
1348-
if (!(gwa_type&IPV6_ADDR_UNICAST))
1349+
if (!(gwa_type & IPV6_ADDR_UNICAST))
13491350
goto out;
13501351

13511352
grt = rt6_lookup(net, gw_addr, NULL, cfg->fc_ifindex, 1);
13521353

13531354
err = -EHOSTUNREACH;
1354-
if (grt == NULL)
1355+
if (!grt)
13551356
goto out;
13561357
if (dev) {
13571358
if (dev != grt->rt6i_dev) {
@@ -1364,20 +1365,20 @@ int ip6_route_add(struct fib6_config *cfg)
13641365
dev_hold(dev);
13651366
in6_dev_hold(grt->rt6i_idev);
13661367
}
1367-
if (!(grt->rt6i_flags&RTF_GATEWAY))
1368+
if (!(grt->rt6i_flags & RTF_GATEWAY))
13681369
err = 0;
13691370
dst_release(&grt->dst);
13701371

13711372
if (err)
13721373
goto out;
13731374
}
13741375
err = -EINVAL;
1375-
if (dev == NULL || (dev->flags&IFF_LOOPBACK))
1376+
if (!dev || (dev->flags & IFF_LOOPBACK))
13761377
goto out;
13771378
}
13781379

13791380
err = -ENODEV;
1380-
if (dev == NULL)
1381+
if (!dev)
13811382
goto out;
13821383

13831384
if (!ipv6_addr_any(&cfg->fc_prefsrc)) {
@@ -1474,7 +1475,7 @@ static int ip6_route_del(struct fib6_config *cfg)
14741475
int err = -ESRCH;
14751476

14761477
table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table);
1477-
if (table == NULL)
1478+
if (!table)
14781479
return err;
14791480

14801481
read_lock_bh(&table->tb6_lock);
@@ -1486,7 +1487,7 @@ static int ip6_route_del(struct fib6_config *cfg)
14861487
if (fn) {
14871488
for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {
14881489
if (cfg->fc_ifindex &&
1489-
(rt->rt6i_dev == NULL ||
1490+
(!rt->rt6i_dev ||
14901491
rt->rt6i_dev->ifindex != cfg->fc_ifindex))
14911492
continue;
14921493
if (cfg->fc_flags & RTF_GATEWAY &&
@@ -1631,7 +1632,7 @@ void rt6_redirect(const struct in6_addr *dest, const struct in6_addr *src,
16311632
goto out;
16321633

16331634
nrt = ip6_rt_copy(rt, dest);
1634-
if (nrt == NULL)
1635+
if (!nrt)
16351636
goto out;
16361637

16371638
nrt->rt6i_flags = RTF_GATEWAY|RTF_UP|RTF_DYNAMIC|RTF_CACHE;
@@ -1648,7 +1649,7 @@ void rt6_redirect(const struct in6_addr *dest, const struct in6_addr *src,
16481649
netevent.new = &nrt->dst;
16491650
call_netevent_notifiers(NETEVENT_REDIRECT, &netevent);
16501651

1651-
if (rt->rt6i_flags&RTF_CACHE) {
1652+
if (rt->rt6i_flags & RTF_CACHE) {
16521653
ip6_del_rt(rt);
16531654
return;
16541655
}
@@ -1669,7 +1670,7 @@ static void rt6_do_pmtu_disc(const struct in6_addr *daddr, const struct in6_addr
16691670
int allfrag = 0;
16701671
again:
16711672
rt = rt6_lookup(net, daddr, saddr, ifindex, 0);
1672-
if (rt == NULL)
1673+
if (!rt)
16731674
return;
16741675

16751676
if (rt6_check_expired(rt)) {
@@ -1817,7 +1818,7 @@ static struct rt6_info *rt6_get_route_info(struct net *net,
18171818
struct fib6_table *table;
18181819

18191820
table = fib6_get_table(net, RT6_TABLE_INFO);
1820-
if (table == NULL)
1821+
if (!table)
18211822
return NULL;
18221823

18231824
write_lock_bh(&table->tb6_lock);
@@ -1876,7 +1877,7 @@ struct rt6_info *rt6_get_dflt_router(const struct in6_addr *addr, struct net_dev
18761877
struct fib6_table *table;
18771878

18781879
table = fib6_get_table(dev_net(dev), RT6_TABLE_DFLT);
1879-
if (table == NULL)
1880+
if (!table)
18801881
return NULL;
18811882

18821883
write_lock_bh(&table->tb6_lock);
@@ -1921,7 +1922,7 @@ void rt6_purge_dflt_routers(struct net *net)
19211922

19221923
/* NOTE: Keep consistent with rt6_get_dflt_router */
19231924
table = fib6_get_table(net, RT6_TABLE_DFLT);
1924-
if (table == NULL)
1925+
if (!table)
19251926
return;
19261927

19271928
restart:
@@ -2061,7 +2062,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
20612062
net->loopback_dev, 0);
20622063
struct neighbour *neigh;
20632064

2064-
if (rt == NULL) {
2065+
if (!rt) {
20652066
if (net_ratelimit())
20662067
pr_warning("IPv6: Maximum number of routes reached,"
20672068
" consider increasing route/max_size.\n");
@@ -2127,7 +2128,7 @@ static int fib6_remove_prefsrc(struct rt6_info *rt, void *arg)
21272128
struct net *net = ((struct arg_dev_net_ip *)arg)->net;
21282129
struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr;
21292130

2130-
if (((void *)rt->rt6i_dev == dev || dev == NULL) &&
2131+
if (((void *)rt->rt6i_dev == dev || !dev) &&
21312132
rt != net->ipv6.ip6_null_entry &&
21322133
ipv6_addr_equal(addr, &rt->rt6i_prefsrc.addr)) {
21332134
/* remove prefsrc entry */
@@ -2157,7 +2158,7 @@ static int fib6_ifdown(struct rt6_info *rt, void *arg)
21572158
const struct arg_dev_net *adn = arg;
21582159
const struct net_device *dev = adn->dev;
21592160

2160-
if ((rt->rt6i_dev == dev || dev == NULL) &&
2161+
if ((rt->rt6i_dev == dev || !dev) &&
21612162
rt != adn->net->ipv6.ip6_null_entry) {
21622163
RT6_TRACE("deleted by ifdown %p\n", rt);
21632164
return -1;
@@ -2194,7 +2195,7 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg)
21942195
*/
21952196

21962197
idev = __in6_dev_get(arg->dev);
2197-
if (idev == NULL)
2198+
if (!idev)
21982199
return 0;
21992200

22002201
/* For administrative MTU increase, there is no way to discover
@@ -2374,7 +2375,7 @@ static int rt6_fill_node(struct net *net,
23742375
}
23752376

23762377
nlh = nlmsg_put(skb, pid, seq, type, sizeof(*rtm), flags);
2377-
if (nlh == NULL)
2378+
if (!nlh)
23782379
return -EMSGSIZE;
23792380

23802381
rtm = nlmsg_data(nlh);
@@ -2388,25 +2389,25 @@ static int rt6_fill_node(struct net *net,
23882389
table = RT6_TABLE_UNSPEC;
23892390
rtm->rtm_table = table;
23902391
NLA_PUT_U32(skb, RTA_TABLE, table);
2391-
if (rt->rt6i_flags&RTF_REJECT)
2392+
if (rt->rt6i_flags & RTF_REJECT)
23922393
rtm->rtm_type = RTN_UNREACHABLE;
2393-
else if (rt->rt6i_flags&RTF_LOCAL)
2394+
else if (rt->rt6i_flags & RTF_LOCAL)
23942395
rtm->rtm_type = RTN_LOCAL;
2395-
else if (rt->rt6i_dev && (rt->rt6i_dev->flags&IFF_LOOPBACK))
2396+
else if (rt->rt6i_dev && (rt->rt6i_dev->flags & IFF_LOOPBACK))
23962397
rtm->rtm_type = RTN_LOCAL;
23972398
else
23982399
rtm->rtm_type = RTN_UNICAST;
23992400
rtm->rtm_flags = 0;
24002401
rtm->rtm_scope = RT_SCOPE_UNIVERSE;
24012402
rtm->rtm_protocol = rt->rt6i_protocol;
2402-
if (rt->rt6i_flags&RTF_DYNAMIC)
2403+
if (rt->rt6i_flags & RTF_DYNAMIC)
24032404
rtm->rtm_protocol = RTPROT_REDIRECT;
24042405
else if (rt->rt6i_flags & RTF_ADDRCONF)
24052406
rtm->rtm_protocol = RTPROT_KERNEL;
2406-
else if (rt->rt6i_flags&RTF_DEFAULT)
2407+
else if (rt->rt6i_flags & RTF_DEFAULT)
24072408
rtm->rtm_protocol = RTPROT_RA;
24082409

2409-
if (rt->rt6i_flags&RTF_CACHE)
2410+
if (rt->rt6i_flags & RTF_CACHE)
24102411
rtm->rtm_flags |= RTM_F_CLONED;
24112412

24122413
if (dst) {
@@ -2546,7 +2547,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
25462547
}
25472548

25482549
skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
2549-
if (skb == NULL) {
2550+
if (!skb) {
25502551
err = -ENOBUFS;
25512552
goto errout;
25522553
}
@@ -2581,10 +2582,10 @@ void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info)
25812582
int err;
25822583

25832584
err = -ENOBUFS;
2584-
seq = info->nlh != NULL ? info->nlh->nlmsg_seq : 0;
2585+
seq = info->nlh ? info->nlh->nlmsg_seq : 0;
25852586

25862587
skb = nlmsg_new(rt6_nlmsg_size(), gfp_any());
2587-
if (skb == NULL)
2588+
if (!skb)
25882589
goto errout;
25892590

25902591
err = rt6_fill_node(net, skb, rt, NULL, NULL, 0,

0 commit comments

Comments
 (0)