batman-adv: move hardif refcount inc to batadv_neigh_node_new()

Message ID 1437856635-27068-1-git-send-email-mareklindner@neomailbox.ch (mailing list archive)
State Accepted, archived
Commit 02cf80cac9e92231c66360efac35406b05afba27
Headers

Commit Message

Marek Lindner July 25, 2015, 8:37 p.m. UTC
  The batadv_neigh_node cleanup function 'batadv_neigh_node_free_rcu()'
takes care of reducing the hardif refcounter, hence it's only logical
to assume the creating function of that same object
'batadv_neigh_node_new()' takes care of increasing the same refcounter.

Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
---
 net/batman-adv/bat_iv_ogm.c | 6 ------
 net/batman-adv/originator.c | 6 ++++++
 2 files changed, 6 insertions(+), 6 deletions(-)
  

Comments

Simon Wunderlich Aug. 3, 2015, 6:01 p.m. UTC | #1
On Sunday 26 July 2015 04:37:15 Marek Lindner wrote:
> The batadv_neigh_node cleanup function 'batadv_neigh_node_free_rcu()'
> takes care of reducing the hardif refcounter, hence it's only logical
> to assume the creating function of that same object
> 'batadv_neigh_node_new()' takes care of increasing the same refcounter.
> 
> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>


Acked-by: Simon Wunderlich <sw@simonwunderlich.de>

Cheers,
   Simon
  
Marek Lindner Aug. 3, 2015, 7:52 p.m. UTC | #2
On Monday, August 03, 2015 20:01:30 Simon Wunderlich wrote:
> On Sunday 26 July 2015 04:37:15 Marek Lindner wrote:
> > The batadv_neigh_node cleanup function 'batadv_neigh_node_free_rcu()'
> > takes care of reducing the hardif refcounter, hence it's only logical
> > to assume the creating function of that same object
> > 'batadv_neigh_node_new()' takes care of increasing the same refcounter.
> >
> > 
> >
> > Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
> 
> Acked-by: Simon Wunderlich <sw@simonwunderlich.de>

Applied in revision 02cf80c.

Regards,
Marek
  

Patch

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 5c12200..b9b8b33 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -303,12 +303,6 @@  batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
 	if (!neigh_node)
 		goto out;
 
-	if (!atomic_inc_not_zero(&hard_iface->refcount)) {
-		kfree(neigh_node);
-		neigh_node = NULL;
-		goto out;
-	}
-
 	neigh_node->orig_node = orig_neigh;
 	neigh_node->if_incoming = hard_iface;
 
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 610620a..f8317c1 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -461,6 +461,12 @@  batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
 	if (!neigh_node)
 		goto out;
 
+	if (!atomic_inc_not_zero(&hard_iface->refcount)) {
+		kfree(neigh_node);
+		neigh_node = NULL;
+		goto out;
+	}
+
 	INIT_HLIST_NODE(&neigh_node->list);
 	INIT_HLIST_HEAD(&neigh_node->ifinfo_list);
 	spin_lock_init(&neigh_node->ifinfo_lock);