Skip to content

Commit 5a6228a

Browse files
NicolasDichteldavem330
authored andcommitted
lwtunnel: change prototype of lwtunnel_state_get()
It saves some lines and simplify a bit the code when the state is returning by this function. It's also useful to handle a NULL entry. To avoid too long lines, I've also renamed lwtunnel_state_get() and lwtunnel_state_put() to lwtstate_get() and lwtstate_put(). CC: Thomas Graf <tgraf@suug.ch> CC: Roopa Prabhu <roopa@cumulusnetworks.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Thomas Graf <tgraf@suug.ch> Acked-by: Roopa Prabhu <roopa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d943659 commit 5a6228a

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

include/net/lwtunnel.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ extern const struct lwtunnel_encap_ops __rcu *
3535
lwtun_encaps[LWTUNNEL_ENCAP_MAX+1];
3636

3737
#ifdef CONFIG_LWTUNNEL
38-
static inline void lwtunnel_state_get(struct lwtunnel_state *lws)
38+
static inline struct lwtunnel_state *
39+
lwtstate_get(struct lwtunnel_state *lws)
3940
{
40-
atomic_inc(&lws->refcnt);
41+
if (lws)
42+
atomic_inc(&lws->refcnt);
43+
44+
return lws;
4145
}
4246

43-
static inline void lwtunnel_state_put(struct lwtunnel_state *lws)
47+
static inline void lwtstate_put(struct lwtunnel_state *lws)
4448
{
4549
if (!lws)
4650
return;
@@ -74,11 +78,13 @@ int lwtunnel_output6(struct sock *sk, struct sk_buff *skb);
7478

7579
#else
7680

77-
static inline void lwtunnel_state_get(struct lwtunnel_state *lws)
81+
static inline struct lwtunnel_state *
82+
lwtstate_get(struct lwtunnel_state *lws)
7883
{
84+
return lws;
7985
}
8086

81-
static inline void lwtunnel_state_put(struct lwtunnel_state *lws)
87+
static inline void lwtstate_put(struct lwtunnel_state *lws)
8288
{
8389
}
8490

net/ipv4/fib_semantics.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static void free_fib_info_rcu(struct rcu_head *head)
209209
change_nexthops(fi) {
210210
if (nexthop_nh->nh_dev)
211211
dev_put(nexthop_nh->nh_dev);
212-
lwtunnel_state_put(nexthop_nh->nh_lwtstate);
212+
lwtstate_put(nexthop_nh->nh_lwtstate);
213213
free_nh_exceptions(nexthop_nh);
214214
rt_fibinfo_free_cpus(nexthop_nh->nh_pcpu_rth_output);
215215
rt_fibinfo_free(&nexthop_nh->nh_rth_input);
@@ -514,8 +514,8 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
514514
nla, &lwtstate);
515515
if (ret)
516516
goto errout;
517-
lwtunnel_state_get(lwtstate);
518-
nexthop_nh->nh_lwtstate = lwtstate;
517+
nexthop_nh->nh_lwtstate =
518+
lwtstate_get(lwtstate);
519519
}
520520
}
521521

@@ -971,8 +971,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
971971
if (err)
972972
goto failure;
973973

974-
lwtunnel_state_get(lwtstate);
975-
nh->nh_lwtstate = lwtstate;
974+
nh->nh_lwtstate = lwtstate_get(lwtstate);
976975
}
977976
nh->nh_oif = cfg->fc_oif;
978977
nh->nh_gw = cfg->fc_gw;

net/ipv4/route.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ static void ipv4_dst_destroy(struct dst_entry *dst)
13581358
list_del(&rt->rt_uncached);
13591359
spin_unlock_bh(&ul->lock);
13601360
}
1361-
lwtunnel_state_put(rt->rt_lwtstate);
1361+
lwtstate_put(rt->rt_lwtstate);
13621362
}
13631363

13641364
void rt_flush_dev(struct net_device *dev)
@@ -1407,12 +1407,7 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
14071407
#ifdef CONFIG_IP_ROUTE_CLASSID
14081408
rt->dst.tclassid = nh->nh_tclassid;
14091409
#endif
1410-
if (nh->nh_lwtstate) {
1411-
lwtunnel_state_get(nh->nh_lwtstate);
1412-
rt->rt_lwtstate = nh->nh_lwtstate;
1413-
} else {
1414-
rt->rt_lwtstate = NULL;
1415-
}
1410+
rt->rt_lwtstate = lwtstate_get(nh->nh_lwtstate);
14161411
if (unlikely(fnhe))
14171412
cached = rt_bind_exception(rt, fnhe, daddr);
14181413
else if (!(rt->dst.flags & DST_NOCACHE))

net/ipv6/ip6_fib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)
178178
static void rt6_release(struct rt6_info *rt)
179179
{
180180
if (atomic_dec_and_test(&rt->rt6i_ref)) {
181-
lwtunnel_state_put(rt->rt6i_lwtstate);
181+
lwtstate_put(rt->rt6i_lwtstate);
182182
rt6_free_pcpu(rt);
183183
dst_free(&rt->dst);
184184
}

net/ipv6/route.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,8 +1778,7 @@ int ip6_route_add(struct fib6_config *cfg)
17781778
cfg->fc_encap, &lwtstate);
17791779
if (err)
17801780
goto out;
1781-
lwtunnel_state_get(lwtstate);
1782-
rt->rt6i_lwtstate = lwtstate;
1781+
rt->rt6i_lwtstate = lwtstate_get(lwtstate);
17831782
if (lwtunnel_output_redirect(rt->rt6i_lwtstate))
17841783
rt->dst.output = lwtunnel_output6;
17851784
}
@@ -2161,10 +2160,7 @@ static void ip6_rt_copy_init(struct rt6_info *rt, struct rt6_info *ort)
21612160
#endif
21622161
rt->rt6i_prefsrc = ort->rt6i_prefsrc;
21632162
rt->rt6i_table = ort->rt6i_table;
2164-
if (ort->rt6i_lwtstate) {
2165-
lwtunnel_state_get(ort->rt6i_lwtstate);
2166-
rt->rt6i_lwtstate = ort->rt6i_lwtstate;
2167-
}
2163+
rt->rt6i_lwtstate = lwtstate_get(ort->rt6i_lwtstate);
21682164
}
21692165

21702166
#ifdef CONFIG_IPV6_ROUTE_INFO

0 commit comments

Comments
 (0)