batman-adv: move neigh_node->if_incoming->if_status check in find_router()

Message ID 1304583702-23969-1-git-send-email-ordex@autistici.org (mailing list archive)
State Superseded, archived
Headers

Commit Message

Antonio Quartulli May 5, 2011, 8:21 a.m. UTC
  Every time that find_router() is invoked, if_status has to be compared
with IF_ACTIVE. Moving this comparison inside find_router() will avoid to
write it each time.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 routing.c |    4 +++-
 unicast.c |    3 ---
 2 files changed, 3 insertions(+), 4 deletions(-)
  

Comments

Marek Lindner May 5, 2011, 12:20 p.m. UTC | #1
On Thursday 05 May 2011 10:21:42 Antonio Quartulli wrote:
>  return_router:
> +       if (router && router->if_incoming->if_status != IF_ACTIVE)
> +               router = NULL;
> +
>         rcu_read_unlock();
>         return router;

You are breaking the reference counting of 'router' here. While looking at 
your patch I found another refcount imbalance. Check the patch I just posted 
(Fix refcount imbalance in find_router).

Regards,
Marek
  
Antonio Quartulli May 8, 2011, 6:44 p.m. UTC | #2
On gio, mag 05, 2011 at 02:20:10 +0200, Marek Lindner wrote:
> On Thursday 05 May 2011 10:21:42 Antonio Quartulli wrote:
> >  return_router:
> > +       if (router && router->if_incoming->if_status != IF_ACTIVE)
> > +               router = NULL;
> > +
> >         rcu_read_unlock();
> >         return router;
> 
> You are breaking the reference counting of 'router' here. While looking at 
> your patch I found another refcount imbalance. Check the patch I just posted 
> (Fix refcount imbalance in find_router).

I see :)
And thanks for reviewing.

Regards,
  

Patch

diff --git a/routing.c b/routing.c
index 49f5715..c875164 100644
--- a/routing.c
+++ b/routing.c
@@ -1237,7 +1237,6 @@  struct neigh_node *find_router(struct bat_priv *bat_priv,
 
 	/* find the orig_node which has the primary interface. might
 	 * even be the same as our router_orig in many cases */
-
 	if (compare_eth(router_orig->primary_addr, router_orig->orig)) {
 		primary_orig_node = router_orig;
 	} else {
@@ -1266,6 +1265,9 @@  struct neigh_node *find_router(struct bat_priv *bat_priv,
 		router = find_ifalter_router(primary_orig_node, recv_if);
 
 return_router:
+	if (router && router->if_incoming->if_status != IF_ACTIVE)
+		router = NULL;
+
 	rcu_read_unlock();
 	return router;
 }
diff --git a/unicast.c b/unicast.c
index b46cbf1..1be53d7 100644
--- a/unicast.c
+++ b/unicast.c
@@ -314,9 +314,6 @@  find_router:
 	if (!neigh_node)
 		goto out;
 
-	if (neigh_node->if_incoming->if_status != IF_ACTIVE)
-		goto out;
-
 	if (my_skb_head_push(skb, sizeof(struct unicast_packet)) < 0)
 		goto out;