Skip to content

Commit 990edb4

Browse files
iamkafaidavem330
authored andcommitted
ipv6: Re-arrange code in rt6_probe()
It is a prep work for the next patch to remove write_lock from rt6_probe(). 1. Reduce the number of if(neigh) check. From 4 to 1. 2. Bring the write_(un)lock() closer to the operations that the lock is protecting. Hopefully, the above make rt6_probe() more readable. Signed-off-by: Martin KaFai Lau <kafai@fb.com> Cc: Hannes Frederic Sowa <hannes@stressinduktion.org> Cc: Julian Anastasov <ja@ssi.bg> Cc: YOSHIFUJI Hideaki <hideaki.yoshifuji@miraclelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 205845a commit 990edb4

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

net/ipv6/route.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ static void rt6_probe_deferred(struct work_struct *w)
545545

546546
static void rt6_probe(struct rt6_info *rt)
547547
{
548+
struct __rt6_probe_work *work;
548549
struct neighbour *neigh;
549550
/*
550551
* Okay, this does not seem to be appropriate
@@ -559,34 +560,29 @@ static void rt6_probe(struct rt6_info *rt)
559560
rcu_read_lock_bh();
560561
neigh = __ipv6_neigh_lookup_noref(rt->dst.dev, &rt->rt6i_gateway);
561562
if (neigh) {
563+
work = NULL;
562564
write_lock(&neigh->lock);
563-
if (neigh->nud_state & NUD_VALID)
564-
goto out;
565-
}
566-
567-
if (!neigh ||
568-
time_after(jiffies, neigh->updated + rt->rt6i_idev->cnf.rtr_probe_interval)) {
569-
struct __rt6_probe_work *work;
570-
571-
work = kmalloc(sizeof(*work), GFP_ATOMIC);
572-
573-
if (neigh && work)
574-
__neigh_set_probe_once(neigh);
575-
576-
if (neigh)
577-
write_unlock(&neigh->lock);
578-
579-
if (work) {
580-
INIT_WORK(&work->work, rt6_probe_deferred);
581-
work->target = rt->rt6i_gateway;
582-
dev_hold(rt->dst.dev);
583-
work->dev = rt->dst.dev;
584-
schedule_work(&work->work);
565+
if (!(neigh->nud_state & NUD_VALID) &&
566+
time_after(jiffies,
567+
neigh->updated +
568+
rt->rt6i_idev->cnf.rtr_probe_interval)) {
569+
work = kmalloc(sizeof(*work), GFP_ATOMIC);
570+
if (work)
571+
__neigh_set_probe_once(neigh);
585572
}
586-
} else {
587-
out:
588573
write_unlock(&neigh->lock);
574+
} else {
575+
work = kmalloc(sizeof(*work), GFP_ATOMIC);
576+
}
577+
578+
if (work) {
579+
INIT_WORK(&work->work, rt6_probe_deferred);
580+
work->target = rt->rt6i_gateway;
581+
dev_hold(rt->dst.dev);
582+
work->dev = rt->dst.dev;
583+
schedule_work(&work->work);
589584
}
585+
590586
rcu_read_unlock_bh();
591587
}
592588
#else

0 commit comments

Comments
 (0)