b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16*
@ 2016-08-22 13:56 Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 01/20] batman-adv: Place kref_get for orig_node_vlan near use Simon Wunderlich
                   ` (20 more replies)
  0 siblings, 21 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n

Hi David,

this is our third (and final, for now) pull request for batman-adv in this round,
with mostly maintainability stuff.

Please pull or let me know of any problem!

Thank you,
      Simon

The following changes since commit 4c09a08b47ffac9aa3bc91870aa54c9ae39d9674:

  batman-adv: Indicate netlink socket can be used with netns. (2016-08-09 07:54:43 +0200)

are available in the git repository at:

  git://git.open-mesh.org/linux-merge.git tags/batadv-next-for-davem-20160822

for you to fetch changes up to dc1cbd145eecf21209d0322874e1766bcbce3e3f:

  batman-adv: Allow to disable debugfs support (2016-08-09 07:54:54 +0200)

----------------------------------------------------------------
This feature patchset includes the following changes:

 - place kref_get near usage of referenced objects, separate patches
   for various used objects to improve readability and maintainability
   by Sven Eckelmann (18 patches)

 - Keep batadv net device when all hard interfaces disappear, to
   improve situations where tools currently use work arounds, by
   Sven Eckelmann

 - Add an option to disable debugfs support to minimize footprint when
   userspace uses netlink only, by Sven Eckelmann

----------------------------------------------------------------
Sven Eckelmann (20):
      batman-adv: Place kref_get for orig_node_vlan near use
      batman-adv: Place kref_get for orig_ifinfo near use
      batman-adv: Place kref_get for tt_orig_list_entry near use
      batman-adv: Place kref_get for neigh_ifinfo near use
      batman-adv: Place kref_get for neigh_node near use
      batman-adv: Place kref_get for orig_node near use
      batman-adv: Place kref_get for tt_local_entry near use
      batman-adv: Place kref_get for tt_common near use
      batman-adv: Place kref_get for bla_claim near use
      batman-adv: Place kref_get for bla_backbone_gw near use
      batman-adv: Place kref_get for dat_entry near use
      batman-adv: Place kref_get for gw_node near use
      batman-adv: Place kref_get for hard_iface near use
      batman-adv: Place kref_get for softif_vlan near use
      batman-adv: Place kref_get for nc_node near use
      batman-adv: Place kref_get for nc_path near use
      batman-adv: Place kref_get for tvlv_container near use
      batman-adv: Place kref_get for tvlv_handler near use
      batman-adv: Keep batadv netdev when hardif disappears
      batman-adv: Allow to disable debugfs support

 net/batman-adv/Kconfig                 | 15 +++++++++++++--
 net/batman-adv/Makefile                |  4 ++--
 net/batman-adv/bat_algo.c              |  2 ++
 net/batman-adv/bat_iv_ogm.c            | 19 ++++++++++++++++---
 net/batman-adv/bat_v.c                 | 12 ++++++++++++
 net/batman-adv/bat_v_ogm.c             |  5 ++---
 net/batman-adv/bridge_loop_avoidance.c | 13 ++++++++-----
 net/batman-adv/debugfs.h               |  2 +-
 net/batman-adv/distributed-arp-table.c |  4 +++-
 net/batman-adv/gateway_client.c        | 10 ++++++++--
 net/batman-adv/hard-interface.c        |  8 +++-----
 net/batman-adv/icmp_socket.h           | 18 +++++++++++++++++-
 net/batman-adv/main.c                  |  2 ++
 net/batman-adv/multicast.c             |  2 ++
 net/batman-adv/network-coding.c        | 11 ++++++-----
 net/batman-adv/originator.c            | 12 ++++++++----
 net/batman-adv/soft-interface.c        |  4 ++++
 net/batman-adv/translation-table.c     | 10 +++++++---
 net/batman-adv/tvlv.c                  |  9 +++++++++
 net/batman-adv/types.h                 |  6 ++++++
 20 files changed, 131 insertions(+), 37 deletions(-)

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 01/20] batman-adv: Place kref_get for orig_node_vlan near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 02/20] batman-adv: Place kref_get for orig_ifinfo " Simon Wunderlich
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/originator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 95c8555..5108af1 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -133,9 +133,9 @@ batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
 		goto out;
 
 	kref_init(&vlan->refcount);
-	kref_get(&vlan->refcount);
 	vlan->vid = vid;
 
+	kref_get(&vlan->refcount);
 	hlist_add_head_rcu(&vlan->list, &orig_node->vlan_list);
 
 out:
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 02/20] batman-adv: Place kref_get for orig_ifinfo near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 01/20] batman-adv: Place kref_get for orig_node_vlan near use Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 03/20] batman-adv: Place kref_get for tt_orig_list_entry " Simon Wunderlich
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/originator.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 5108af1..8828964 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -386,6 +386,7 @@ batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node,
 	orig_ifinfo->if_outgoing = if_outgoing;
 	INIT_HLIST_NODE(&orig_ifinfo->list);
 	kref_init(&orig_ifinfo->refcount);
+
 	kref_get(&orig_ifinfo->refcount);
 	hlist_add_head_rcu(&orig_ifinfo->list,
 			   &orig_node->ifinfo_list);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 03/20] batman-adv: Place kref_get for tt_orig_list_entry near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 01/20] batman-adv: Place kref_get for orig_node_vlan near use Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 02/20] batman-adv: Place kref_get for orig_ifinfo " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 04/20] batman-adv: Place kref_get for neigh_ifinfo " Simon Wunderlich
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/translation-table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 2080407..5cc500f 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1567,9 +1567,9 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
 	orig_entry->orig_node = orig_node;
 	orig_entry->ttvn = ttvn;
 	kref_init(&orig_entry->refcount);
-	kref_get(&orig_entry->refcount);
 
 	spin_lock_bh(&tt_global->list_lock);
+	kref_get(&orig_entry->refcount);
 	hlist_add_head_rcu(&orig_entry->list,
 			   &tt_global->orig_list);
 	spin_unlock_bh(&tt_global->list_lock);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 04/20] batman-adv: Place kref_get for neigh_ifinfo near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (2 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 03/20] batman-adv: Place kref_get for tt_orig_list_entry " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 05/20] batman-adv: Place kref_get for neigh_node " Simon Wunderlich
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/originator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 8828964..5e99a6e 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -460,9 +460,9 @@ batadv_neigh_ifinfo_new(struct batadv_neigh_node *neigh,
 
 	INIT_HLIST_NODE(&neigh_ifinfo->list);
 	kref_init(&neigh_ifinfo->refcount);
-	kref_get(&neigh_ifinfo->refcount);
 	neigh_ifinfo->if_outgoing = if_outgoing;
 
+	kref_get(&neigh_ifinfo->refcount);
 	hlist_add_head_rcu(&neigh_ifinfo->list, &neigh->ifinfo_list);
 
 out:
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 05/20] batman-adv: Place kref_get for neigh_node near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (3 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 04/20] batman-adv: Place kref_get for neigh_ifinfo " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 06/20] batman-adv: Place kref_get for orig_node " Simon Wunderlich
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/originator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 5e99a6e..0792de8 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -654,8 +654,8 @@ batadv_neigh_node_create(struct batadv_orig_node *orig_node,
 
 	/* extra reference for return */
 	kref_init(&neigh_node->refcount);
-	kref_get(&neigh_node->refcount);
 
+	kref_get(&neigh_node->refcount);
 	hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
 
 	batadv_dbg(BATADV_DBG_BATMAN, orig_node->bat_priv,
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 06/20] batman-adv: Place kref_get for orig_node near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (4 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 05/20] batman-adv: Place kref_get for neigh_node " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 07/20] batman-adv: Place kref_get for tt_local_entry " Simon Wunderlich
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/bat_iv_ogm.c     | 7 ++++---
 net/batman-adv/bat_v_ogm.c      | 5 ++---
 net/batman-adv/gateway_client.c | 2 +-
 net/batman-adv/network-coding.c | 7 +++----
 net/batman-adv/originator.c     | 1 -
 5 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 9ed4f1f..3c7900d 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -324,17 +324,18 @@ batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)
 	if (!orig_node->bat_iv.bcast_own_sum)
 		goto free_orig_node;
 
+	kref_get(&orig_node->refcount);
 	hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
 				     batadv_choose_orig, orig_node,
 				     &orig_node->hash_entry);
 	if (hash_added != 0)
-		goto free_orig_node;
+		goto free_orig_node_hash;
 
 	return orig_node;
 
-free_orig_node:
-	/* free twice, as batadv_orig_node_new sets refcount to 2 */
+free_orig_node_hash:
 	batadv_orig_node_put(orig_node);
+free_orig_node:
 	batadv_orig_node_put(orig_node);
 
 	return NULL;
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index 6fbba4e..1aeeadc 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -73,13 +73,12 @@ struct batadv_orig_node *batadv_v_ogm_orig_get(struct batadv_priv *bat_priv,
 	if (!orig_node)
 		return NULL;
 
+	kref_get(&orig_node->refcount);
 	hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
 				     batadv_choose_orig, orig_node,
 				     &orig_node->hash_entry);
 	if (hash_added != 0) {
-		/* orig_node->refcounter is initialised to 2 by
-		 * batadv_orig_node_new()
-		 */
+		/* remove refcnt for newly created orig_node and hash entry */
 		batadv_orig_node_put(orig_node);
 		batadv_orig_node_put(orig_node);
 		orig_node = NULL;
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index c2928c2..b889e1f 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -339,8 +339,8 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
 	if (!gw_node)
 		return;
 
-	kref_get(&orig_node->refcount);
 	INIT_HLIST_NODE(&gw_node->list);
+	kref_get(&orig_node->refcount);
 	gw_node->orig_node = orig_node;
 	gw_node->bandwidth_down = ntohl(gateway->bandwidth_down);
 	gw_node->bandwidth_up = ntohl(gateway->bandwidth_up);
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index 293ef4f..3814cfb 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -856,14 +856,13 @@ batadv_nc_get_nc_node(struct batadv_priv *bat_priv,
 	if (!nc_node)
 		return NULL;
 
-	kref_get(&orig_neigh_node->refcount);
-
 	/* Initialize nc_node */
 	INIT_LIST_HEAD(&nc_node->list);
-	ether_addr_copy(nc_node->addr, orig_node->orig);
-	nc_node->orig_node = orig_neigh_node;
 	kref_init(&nc_node->refcount);
 	kref_get(&nc_node->refcount);
+	ether_addr_copy(nc_node->addr, orig_node->orig);
+	kref_get(&orig_neigh_node->refcount);
+	nc_node->orig_node = orig_neigh_node;
 
 	/* Select ingoing or outgoing coding node */
 	if (in_coding) {
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 0792de8..0b7d57a 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -989,7 +989,6 @@ struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
 
 	/* extra reference for return */
 	kref_init(&orig_node->refcount);
-	kref_get(&orig_node->refcount);
 
 	orig_node->bat_priv = bat_priv;
 	ether_addr_copy(orig_node->orig, addr);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 07/20] batman-adv: Place kref_get for tt_local_entry near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (5 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 06/20] batman-adv: Place kref_get for orig_node " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 08/20] batman-adv: Place kref_get for tt_common " Simon Wunderlich
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/translation-table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 5cc500f..094da1a 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -734,7 +734,6 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,
 	if (batadv_is_wifi_netdev(in_dev))
 		tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
 	kref_init(&tt_local->common.refcount);
-	kref_get(&tt_local->common.refcount);
 	tt_local->last_seen = jiffies;
 	tt_local->common.added_at = tt_local->last_seen;
 	tt_local->vlan = vlan;
@@ -746,6 +745,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr,
 	    is_multicast_ether_addr(addr))
 		tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE;
 
+	kref_get(&tt_local->common.refcount);
 	hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
 				     batadv_choose_tt, &tt_local->common,
 				     &tt_local->common.hash_entry);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 08/20] batman-adv: Place kref_get for tt_common near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (6 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 07/20] batman-adv: Place kref_get for tt_local_entry " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 09/20] batman-adv: Place kref_get for bla_claim " Simon Wunderlich
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/translation-table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 094da1a..d94e298 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1645,13 +1645,13 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
 		if (flags & BATADV_TT_CLIENT_ROAM)
 			tt_global_entry->roam_at = jiffies;
 		kref_init(&common->refcount);
-		kref_get(&common->refcount);
 		common->added_at = jiffies;
 
 		INIT_HLIST_HEAD(&tt_global_entry->orig_list);
 		atomic_set(&tt_global_entry->orig_list_count, 0);
 		spin_lock_init(&tt_global_entry->list_lock);
 
+		kref_get(&common->refcount);
 		hash_added = batadv_hash_add(bat_priv->tt.global_hash,
 					     batadv_compare_tt,
 					     batadv_choose_tt, common,
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 09/20] batman-adv: Place kref_get for bla_claim near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (7 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 08/20] batman-adv: Place kref_get for tt_common " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 10/20] batman-adv: Place kref_get for bla_backbone_gw " Simon Wunderlich
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/bridge_loop_avoidance.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 35ed1d3..b0517a0 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -718,12 +718,13 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
 		claim->lasttime = jiffies;
 		kref_get(&backbone_gw->refcount);
 		claim->backbone_gw = backbone_gw;
-
 		kref_init(&claim->refcount);
-		kref_get(&claim->refcount);
+
 		batadv_dbg(BATADV_DBG_BLA, bat_priv,
 			   "bla_add_claim(): adding new entry %pM, vid %d to hash ...\n",
 			   mac, BATADV_PRINT_VID(vid));
+
+		kref_get(&claim->refcount);
 		hash_added = batadv_hash_add(bat_priv->bla.claim_hash,
 					     batadv_compare_claim,
 					     batadv_choose_claim, claim,
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 10/20] batman-adv: Place kref_get for bla_backbone_gw near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (8 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 09/20] batman-adv: Place kref_get for bla_claim " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 11/20] batman-adv: Place kref_get for dat_entry " Simon Wunderlich
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/bridge_loop_avoidance.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index b0517a0..1db3c12 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -526,11 +526,9 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, u8 *orig,
 	atomic_set(&entry->wait_periods, 0);
 	ether_addr_copy(entry->orig, orig);
 	INIT_WORK(&entry->report_work, batadv_bla_loopdetect_report);
-
-	/* one for the hash, one for returning */
 	kref_init(&entry->refcount);
-	kref_get(&entry->refcount);
 
+	kref_get(&entry->refcount);
 	hash_added = batadv_hash_add(bat_priv->bla.backbone_hash,
 				     batadv_compare_backbone_gw,
 				     batadv_choose_backbone_gw, entry,
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 11/20] batman-adv: Place kref_get for dat_entry near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (9 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 10/20] batman-adv: Place kref_get for bla_backbone_gw " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 12/20] batman-adv: Place kref_get for gw_node " Simon Wunderlich
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/distributed-arp-table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index b1cc8bf..059bc23 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -343,8 +343,8 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,
 	ether_addr_copy(dat_entry->mac_addr, mac_addr);
 	dat_entry->last_update = jiffies;
 	kref_init(&dat_entry->refcount);
-	kref_get(&dat_entry->refcount);
 
+	kref_get(&dat_entry->refcount);
 	hash_added = batadv_hash_add(bat_priv->dat.hash, batadv_compare_dat,
 				     batadv_hash_dat, dat_entry,
 				     &dat_entry->hash_entry);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 12/20] batman-adv: Place kref_get for gw_node near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (10 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 11/20] batman-adv: Place kref_get for dat_entry " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 13/20] batman-adv: Place kref_get for hard_iface " Simon Wunderlich
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/gateway_client.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index b889e1f..4b51b1c 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -339,14 +339,15 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
 	if (!gw_node)
 		return;
 
+	kref_init(&gw_node->refcount);
 	INIT_HLIST_NODE(&gw_node->list);
 	kref_get(&orig_node->refcount);
 	gw_node->orig_node = orig_node;
 	gw_node->bandwidth_down = ntohl(gateway->bandwidth_down);
 	gw_node->bandwidth_up = ntohl(gateway->bandwidth_up);
-	kref_init(&gw_node->refcount);
 
 	spin_lock_bh(&bat_priv->gw.list_lock);
+	kref_get(&gw_node->refcount);
 	hlist_add_head_rcu(&gw_node->list, &bat_priv->gw.list);
 	spin_unlock_bh(&bat_priv->gw.list_lock);
 
@@ -357,6 +358,9 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
 		   ntohl(gateway->bandwidth_down) % 10,
 		   ntohl(gateway->bandwidth_up) / 10,
 		   ntohl(gateway->bandwidth_up) % 10);
+
+	/* don't return reference to new gw_node */
+	batadv_gw_node_put(gw_node);
 }
 
 /**
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 13/20] batman-adv: Place kref_get for hard_iface near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (11 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 12/20] batman-adv: Place kref_get for gw_node " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 14/20] batman-adv: Place kref_get for softif_vlan " Simon Wunderlich
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/hard-interface.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 43c9a3e..9284c73 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -694,6 +694,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
 	INIT_HLIST_HEAD(&hard_iface->neigh_list);
 
 	spin_lock_init(&hard_iface->neigh_list_lock);
+	kref_init(&hard_iface->refcount);
 
 	hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
 	if (batadv_is_wifi_netdev(net_dev))
@@ -701,11 +702,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
 
 	batadv_v_hardif_init(hard_iface);
 
-	/* extra reference for return */
-	kref_init(&hard_iface->refcount);
-	kref_get(&hard_iface->refcount);
-
 	batadv_check_known_mac_addr(hard_iface->net_dev);
+	kref_get(&hard_iface->refcount);
 	list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
 
 	return hard_iface;
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 14/20] batman-adv: Place kref_get for softif_vlan near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (12 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 13/20] batman-adv: Place kref_get for hard_iface " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-23 13:20   ` Sergei Shtylyov
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 15/20] batman-adv: Place kref_get for nc_node " Simon Wunderlich
                   ` (6 subsequent siblings)
  20 siblings, 1 reply; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/soft-interface.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index e508bf5..49e16b6 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -594,6 +594,7 @@ int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
 	}
 
 	spin_lock_bh(&bat_priv->softif_vlan_list_lock);
+	kref_get(&vlan->refcount);
 	hlist_add_head_rcu(&vlan->list, &bat_priv->softif_vlan_list);
 	spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
 
@@ -604,6 +605,9 @@ int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
 			    bat_priv->soft_iface->dev_addr, vid,
 			    BATADV_NULL_IFINDEX, BATADV_NO_MARK);
 
+	/* don't return reference to new softif_vlan */
+	batadv_softif_vlan_put(vlan);
+
 	return 0;
 }
 
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 15/20] batman-adv: Place kref_get for nc_node near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (13 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 14/20] batman-adv: Place kref_get for softif_vlan " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 16/20] batman-adv: Place kref_get for nc_path " Simon Wunderlich
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/network-coding.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index 3814cfb..4f4cfe5 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -859,7 +859,6 @@ batadv_nc_get_nc_node(struct batadv_priv *bat_priv,
 	/* Initialize nc_node */
 	INIT_LIST_HEAD(&nc_node->list);
 	kref_init(&nc_node->refcount);
-	kref_get(&nc_node->refcount);
 	ether_addr_copy(nc_node->addr, orig_node->orig);
 	kref_get(&orig_neigh_node->refcount);
 	nc_node->orig_node = orig_neigh_node;
@@ -878,6 +877,7 @@ batadv_nc_get_nc_node(struct batadv_priv *bat_priv,
 
 	/* Add nc_node to orig_node */
 	spin_lock_bh(lock);
+	kref_get(&nc_node->refcount);
 	list_add_tail_rcu(&nc_node->list, list);
 	spin_unlock_bh(lock);
 
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 16/20] batman-adv: Place kref_get for nc_path near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (14 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 15/20] batman-adv: Place kref_get for nc_node " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 17/20] batman-adv: Place kref_get for tvlv_container " Simon Wunderlich
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/network-coding.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index 4f4cfe5..165cd27 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -978,7 +978,6 @@ static struct batadv_nc_path *batadv_nc_get_path(struct batadv_priv *bat_priv,
 	INIT_LIST_HEAD(&nc_path->packet_list);
 	spin_lock_init(&nc_path->packet_list_lock);
 	kref_init(&nc_path->refcount);
-	kref_get(&nc_path->refcount);
 	nc_path->last_valid = jiffies;
 	ether_addr_copy(nc_path->next_hop, dst);
 	ether_addr_copy(nc_path->prev_hop, src);
@@ -988,6 +987,7 @@ static struct batadv_nc_path *batadv_nc_get_path(struct batadv_priv *bat_priv,
 		   nc_path->next_hop);
 
 	/* Add nc_path to hash table */
+	kref_get(&nc_path->refcount);
 	hash_added = batadv_hash_add(hash, batadv_nc_hash_compare,
 				     batadv_nc_hash_choose, &nc_path_key,
 				     &nc_path->hash_entry);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 17/20] batman-adv: Place kref_get for tvlv_container near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (15 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 16/20] batman-adv: Place kref_get for nc_path " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 18/20] batman-adv: Place kref_get for tvlv_handler " Simon Wunderlich
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/tvlv.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 3d1cf0f..3533867 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -257,8 +257,13 @@ void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
 	spin_lock_bh(&bat_priv->tvlv.container_list_lock);
 	tvlv_old = batadv_tvlv_container_get(bat_priv, type, version);
 	batadv_tvlv_container_remove(bat_priv, tvlv_old);
+
+	kref_get(&tvlv_new->refcount);
 	hlist_add_head(&tvlv_new->list, &bat_priv->tvlv.container_list);
 	spin_unlock_bh(&bat_priv->tvlv.container_list_lock);
+
+	/* don't return reference to new tvlv_container */
+	batadv_tvlv_container_put(tvlv_new);
 }
 
 /**
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 18/20] batman-adv: Place kref_get for tvlv_handler near use
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (16 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 17/20] batman-adv: Place kref_get for tvlv_container " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-23 13:36   ` Sergei Shtylyov
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 19/20] batman-adv: Keep batadv netdev when hardif disappears Simon Wunderlich
                   ` (2 subsequent siblings)
  20 siblings, 1 reply; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

It is hard to understand why the refcnt is increased when it isn't done
near the actual place the new reference is used. So using kref_get right
before the place which requires the reference and in the same function
helps to avoid accidental problems caused by incorrect reference counting.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/tvlv.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 3533867..77654f0 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -547,8 +547,12 @@ void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
 	INIT_HLIST_NODE(&tvlv_handler->list);
 
 	spin_lock_bh(&bat_priv->tvlv.handler_list_lock);
+	kref_get(&tvlv_handler->refcount);
 	hlist_add_head_rcu(&tvlv_handler->list, &bat_priv->tvlv.handler_list);
 	spin_unlock_bh(&bat_priv->tvlv.handler_list_lock);
+
+	/* don't return reference to new tvlv_handler */
+	batadv_tvlv_handler_put(tvlv_handler);
 }
 
 /**
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 19/20] batman-adv: Keep batadv netdev when hardif disappears
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (17 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 18/20] batman-adv: Place kref_get for tvlv_handler " Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 20/20] batman-adv: Allow to disable debugfs support Simon Wunderlich
  2016-08-23  3:40 ` [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* David Miller
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

Switch-like virtual interfaces like bridge or openvswitch don't destroy
itself when all their attached netdevices dissappear. Instead they only
remove the link to the unregistered device and keep working until they get
removed manually.

This has the benefit that all configurations for this interfaces are kept
and daemons reacting to rtnl events can just add new slave interfaces
without going through the complete configuration of the switch-like
netdevice.

Handling unregister events of client devices similar in batman-adv allows
users to drop their current workaround of dummy netdevices attached to
batman-adv soft-interfaces.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/hard-interface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 9284c73..08ce361 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -725,7 +725,7 @@ static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface)
 	/* first deactivate interface */
 	if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
 		batadv_hardif_disable_interface(hard_iface,
-						BATADV_IF_CLEANUP_AUTO);
+						BATADV_IF_CLEANUP_KEEP);
 
 	if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
 		return;
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [B.A.T.M.A.N.] [PATCH 20/20] batman-adv: Allow to disable debugfs support
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (18 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 19/20] batman-adv: Keep batadv netdev when hardif disappears Simon Wunderlich
@ 2016-08-22 13:56 ` Simon Wunderlich
  2016-08-23  3:40 ` [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* David Miller
  20 siblings, 0 replies; 24+ messages in thread
From: Simon Wunderlich @ 2016-08-22 13:56 UTC (permalink / raw)
  To: davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

From: Sven Eckelmann <sven@narfation.org>

The files provided by batman-adv via debugfs are currently converted to
netlink. Tools which are not yet converted to use the netlink interface may
still rely on the old debugfs files. But systems which already upgraded
their tools can save some space by disabling this feature. The default
configuration of batman-adv on amd64 can reduce the size of the module by
around 11% when this feature is disabled.

    $ size net/batman-adv/batman-adv.ko*
       text    data     bss     dec     hex filename
     150507   10395    4160  165062   284c6 net/batman-adv/batman-adv.ko.y
     137106    7099    2112  146317   23b8d net/batman-adv/batman-adv.ko.n

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/Kconfig                 | 15 +++++++++++++--
 net/batman-adv/Makefile                |  4 ++--
 net/batman-adv/bat_algo.c              |  2 ++
 net/batman-adv/bat_iv_ogm.c            | 12 ++++++++++++
 net/batman-adv/bat_v.c                 | 12 ++++++++++++
 net/batman-adv/bridge_loop_avoidance.c |  4 ++++
 net/batman-adv/debugfs.h               |  2 +-
 net/batman-adv/distributed-arp-table.c |  2 ++
 net/batman-adv/gateway_client.c        |  2 ++
 net/batman-adv/icmp_socket.h           | 18 +++++++++++++++++-
 net/batman-adv/main.c                  |  2 ++
 net/batman-adv/multicast.c             |  2 ++
 net/batman-adv/network-coding.c        |  2 ++
 net/batman-adv/originator.c            |  4 ++++
 net/batman-adv/translation-table.c     |  4 ++++
 net/batman-adv/types.h                 |  6 ++++++
 16 files changed, 87 insertions(+), 6 deletions(-)

diff --git a/net/batman-adv/Kconfig b/net/batman-adv/Kconfig
index 833bb14..f20742c 100644
--- a/net/batman-adv/Kconfig
+++ b/net/batman-adv/Kconfig
@@ -73,10 +73,21 @@ config BATMAN_ADV_MCAST
 	  reduce the air overhead while improving the reliability of
 	  multicast messages.
 
-config BATMAN_ADV_DEBUG
-	bool "B.A.T.M.A.N. debugging"
+config BATMAN_ADV_DEBUGFS
+	bool "batman-adv debugfs entries"
 	depends on BATMAN_ADV
 	depends on DEBUG_FS
+	default y
+	help
+	  Enable this to export routing related debug tables via debugfs.
+	  The information for each soft-interface and used hard-interface can be
+	  found under batman_adv/
+
+	  If unsure, say Y.
+
+config BATMAN_ADV_DEBUG
+	bool "B.A.T.M.A.N. debugging"
+	depends on BATMAN_ADV_DEBUGFS
 	help
 	  This is an option for use by developers; most people should
 	  say N here. This enables compilation of support for
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile
index a83fc6c..f724d3c 100644
--- a/net/batman-adv/Makefile
+++ b/net/batman-adv/Makefile
@@ -24,14 +24,14 @@ batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v_elp.o
 batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v_ogm.o
 batman-adv-y += bitarray.o
 batman-adv-$(CONFIG_BATMAN_ADV_BLA) += bridge_loop_avoidance.o
-batman-adv-$(CONFIG_DEBUG_FS) += debugfs.o
+batman-adv-$(CONFIG_BATMAN_ADV_DEBUGFS) += debugfs.o
 batman-adv-$(CONFIG_BATMAN_ADV_DAT) += distributed-arp-table.o
 batman-adv-y += fragmentation.o
 batman-adv-y += gateway_client.o
 batman-adv-y += gateway_common.o
 batman-adv-y += hard-interface.o
 batman-adv-y += hash.o
-batman-adv-y += icmp_socket.o
+batman-adv-$(CONFIG_BATMAN_ADV_DEBUGFS) += icmp_socket.o
 batman-adv-$(CONFIG_BATMAN_ADV_DEBUG) += log.o
 batman-adv-y += main.o
 batman-adv-$(CONFIG_BATMAN_ADV_MCAST) += multicast.o
diff --git a/net/batman-adv/bat_algo.c b/net/batman-adv/bat_algo.c
index f2cc50d3..623d043 100644
--- a/net/batman-adv/bat_algo.c
+++ b/net/batman-adv/bat_algo.c
@@ -101,6 +101,7 @@ int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
 	return 0;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
 {
 	struct batadv_algo_ops *bat_algo_ops;
@@ -113,6 +114,7 @@ int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
 
 	return 0;
 }
+#endif
 
 static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
 {
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 3c7900d..e2d18d0 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -1855,6 +1855,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
 	return NET_RX_SUCCESS;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_iv_ogm_orig_print_neigh - print neighbors for the originator table
  * @orig_node: the orig_node for which the neighbors are printed
@@ -1952,6 +1953,7 @@ next:
 	if (batman_count == 0)
 		seq_puts(seq, "No batman nodes in range ...\n");
 }
+#endif
 
 /**
  * batadv_iv_ogm_neigh_get_tq_avg - Get the TQ average for a neighbour on a
@@ -2182,6 +2184,7 @@ batadv_iv_ogm_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,
 	cb->args[2] = sub;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_iv_hardif_neigh_print - print a single hop neighbour node
  * @seq: neighbour table seq_file struct
@@ -2232,6 +2235,7 @@ static void batadv_iv_neigh_print(struct batadv_priv *bat_priv,
 	if (batman_count == 0)
 		seq_puts(seq, "No batman nodes in range ...\n");
 }
+#endif
 
 /**
  * batadv_iv_ogm_neigh_diff - calculate tq difference of two neighbors
@@ -2618,6 +2622,7 @@ out:
 	return ret;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /* fails if orig_node has no router */
 static int batadv_iv_gw_write_buffer_text(struct batadv_priv *bat_priv,
 					  struct seq_file *seq,
@@ -2681,6 +2686,7 @@ static void batadv_iv_gw_print(struct batadv_priv *bat_priv,
 	if (gw_count == 0)
 		seq_puts(seq, "No gateways in range ...\n");
 }
+#endif
 
 /**
  * batadv_iv_gw_dump_entry - Dump a gateway into a message
@@ -2798,11 +2804,15 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
 	.neigh = {
 		.cmp = batadv_iv_ogm_neigh_cmp,
 		.is_similar_or_better = batadv_iv_ogm_neigh_is_sob,
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 		.print = batadv_iv_neigh_print,
+#endif
 		.dump = batadv_iv_ogm_neigh_dump,
 	},
 	.orig = {
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 		.print = batadv_iv_ogm_orig_print,
+#endif
 		.dump = batadv_iv_ogm_orig_dump,
 		.free = batadv_iv_ogm_orig_free,
 		.add_if = batadv_iv_ogm_orig_add_if,
@@ -2811,7 +2821,9 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
 	.gw = {
 		.get_best_gw_node = batadv_iv_gw_get_best_gw_node,
 		.is_eligible = batadv_iv_gw_is_eligible,
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 		.print = batadv_iv_gw_print,
+#endif
 		.dump = batadv_iv_gw_dump,
 	},
 };
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
index 9e872dc..e79f6f0 100644
--- a/net/batman-adv/bat_v.c
+++ b/net/batman-adv/bat_v.c
@@ -129,6 +129,7 @@ batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh)
 		  batadv_v_elp_throughput_metric_update);
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_v_orig_print_neigh - print neighbors for the originator table
  * @orig_node: the orig_node for which the neighbors are printed
@@ -212,6 +213,7 @@ static void batadv_v_neigh_print(struct batadv_priv *bat_priv,
 	if (batman_count == 0)
 		seq_puts(seq, "No batman nodes in range ...\n");
 }
+#endif
 
 /**
  * batadv_v_neigh_dump_neigh - Dump a neighbour into a message
@@ -345,6 +347,7 @@ batadv_v_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb,
 	cb->args[1] = idx;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_v_orig_print - print the originator table
  * @bat_priv: the bat priv with all the soft interface information
@@ -411,6 +414,7 @@ next:
 	if (batman_count == 0)
 		seq_puts(seq, "No batman nodes in range ...\n");
 }
+#endif
 
 /**
  * batadv_v_orig_dump_subentry - Dump an originator subentry into a
@@ -827,6 +831,7 @@ out:
 	return ret;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /* fails if orig_node has no router */
 static int batadv_v_gw_write_buffer_text(struct batadv_priv *bat_priv,
 					 struct seq_file *seq,
@@ -896,6 +901,7 @@ static void batadv_v_gw_print(struct batadv_priv *bat_priv,
 	if (gw_count == 0)
 		seq_puts(seq, "No gateways in range ...\n");
 }
+#endif
 
 /**
  * batadv_v_gw_dump_entry - Dump a gateway into a message
@@ -1034,11 +1040,15 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = {
 		.hardif_init = batadv_v_hardif_neigh_init,
 		.cmp = batadv_v_neigh_cmp,
 		.is_similar_or_better = batadv_v_neigh_is_sob,
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 		.print = batadv_v_neigh_print,
+#endif
 		.dump = batadv_v_neigh_dump,
 	},
 	.orig = {
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 		.print = batadv_v_orig_print,
+#endif
 		.dump = batadv_v_orig_dump,
 	},
 	.gw = {
@@ -1046,7 +1056,9 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = {
 		.show_sel_class = batadv_v_show_sel_class,
 		.get_best_gw_node = batadv_v_gw_get_best_gw_node,
 		.is_eligible = batadv_v_gw_is_eligible,
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 		.print = batadv_v_gw_print,
+#endif
 		.dump = batadv_v_gw_dump,
 	},
 };
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 1db3c12..e7f690b 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -1996,6 +1996,7 @@ out:
 	return ret;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_bla_claim_table_seq_print_text - print the claim table in a seq file
  * @seq: seq file to print on
@@ -2056,6 +2057,7 @@ out:
 		batadv_hardif_put(primary_if);
 	return 0;
 }
+#endif
 
 /**
  * batadv_bla_claim_dump_entry - dump one entry of the claim table
@@ -2219,6 +2221,7 @@ out:
 	return ret;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_bla_backbone_table_seq_print_text - print the backbone table in a seq
  *  file
@@ -2282,6 +2285,7 @@ out:
 		batadv_hardif_put(primary_if);
 	return 0;
 }
+#endif
 
 /**
  * batadv_bla_backbone_dump_entry - dump one entry of the backbone table
diff --git a/net/batman-adv/debugfs.h b/net/batman-adv/debugfs.h
index 1ab4e2e6..c68ff3d 100644
--- a/net/batman-adv/debugfs.h
+++ b/net/batman-adv/debugfs.h
@@ -26,7 +26,7 @@ struct net_device;
 
 #define BATADV_DEBUGFS_SUBDIR "batman_adv"
 
-#if IS_ENABLED(CONFIG_DEBUG_FS)
+#if IS_ENABLED(CONFIG_BATMAN_ADV_DEBUGFS)
 
 void batadv_debugfs_init(void);
 void batadv_debugfs_destroy(void);
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 059bc23..e257efd 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -795,6 +795,7 @@ void batadv_dat_free(struct batadv_priv *bat_priv)
 	batadv_dat_hash_free(bat_priv);
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_dat_cache_seq_print_text - print the local DAT hash table
  * @seq: seq file to print on
@@ -846,6 +847,7 @@ out:
 		batadv_hardif_put(primary_if);
 	return 0;
 }
+#endif
 
 /**
  * batadv_arp_get_type - parse an ARP packet and gets the type
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index 4b51b1c..de055d6 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -482,6 +482,7 @@ void batadv_gw_node_free(struct batadv_priv *bat_priv)
 	spin_unlock_bh(&bat_priv->gw.list_lock);
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset)
 {
 	struct net_device *net_dev = (struct net_device *)seq->private;
@@ -509,6 +510,7 @@ int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset)
 
 	return 0;
 }
+#endif
 
 /**
  * batadv_gw_dump - Dump gateways into a message
diff --git a/net/batman-adv/icmp_socket.h b/net/batman-adv/icmp_socket.h
index 618d5de..e44a7da 100644
--- a/net/batman-adv/icmp_socket.h
+++ b/net/batman-adv/icmp_socket.h
@@ -26,9 +26,25 @@ struct batadv_icmp_header;
 
 #define BATADV_ICMP_SOCKET "socket"
 
-void batadv_socket_init(void);
 int batadv_socket_setup(struct batadv_priv *bat_priv);
+
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
+
+void batadv_socket_init(void);
 void batadv_socket_receive_packet(struct batadv_icmp_header *icmph,
 				  size_t icmp_len);
 
+#else
+
+static inline void batadv_socket_init(void)
+{
+}
+
+static inline void
+batadv_socket_receive_packet(struct batadv_icmp_header *icmph, size_t icmp_len)
+{
+}
+
+#endif
+
 #endif /* _NET_BATMAN_ADV_ICMP_SOCKET_H_ */
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index ef07e5b..2c017ab 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -282,6 +282,7 @@ bool batadv_is_my_mac(struct batadv_priv *bat_priv, const u8 *addr)
 	return is_my_mac;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_seq_print_text_primary_if_get - called from debugfs table printing
  *  function that requires the primary interface
@@ -317,6 +318,7 @@ batadv_seq_print_text_primary_if_get(struct seq_file *seq)
 out:
 	return primary_if;
 }
+#endif
 
 /**
  * batadv_max_header_len - calculate maximum encapsulation overhead for a
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index 894df60..13661f4 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -1134,6 +1134,7 @@ void batadv_mcast_init(struct batadv_priv *bat_priv)
 				     BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_mcast_flags_print_header - print own mcast flags to debugfs table
  * @bat_priv: the bat priv with all the soft interface information
@@ -1234,6 +1235,7 @@ int batadv_mcast_flags_seq_print_text(struct seq_file *seq, void *offset)
 
 	return 0;
 }
+#endif
 
 /**
  * batadv_mcast_free - free the multicast optimizations structures
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index 165cd27..e3baf69 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -1881,6 +1881,7 @@ void batadv_nc_mesh_free(struct batadv_priv *bat_priv)
 	batadv_hash_destroy(bat_priv->nc.decoding_hash);
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_nc_nodes_seq_print_text - print the nc node information
  * @seq: seq file to print on
@@ -1980,3 +1981,4 @@ int batadv_nc_init_debugfs(struct batadv_priv *bat_priv)
 out:
 	return -ENOMEM;
 }
+#endif
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 0b7d57a..5f3bfc4 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -693,6 +693,7 @@ batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,
 	return batadv_neigh_node_create(orig_node, hard_iface, neigh_addr);
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_hardif_neigh_seq_print_text - print the single hop neighbour list
  * @seq: neighbour table seq_file struct
@@ -726,6 +727,7 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset)
 	bat_priv->algo_ops->neigh.print(bat_priv, seq);
 	return 0;
 }
+#endif
 
 /**
  * batadv_hardif_neigh_dump - Dump to netlink the neighbor infos for a specific
@@ -1339,6 +1341,7 @@ void batadv_purge_orig_ref(struct batadv_priv *bat_priv)
 	_batadv_purge_orig(bat_priv);
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
 {
 	struct net_device *net_dev = (struct net_device *)seq->private;
@@ -1412,6 +1415,7 @@ out:
 		batadv_hardif_put(hard_iface);
 	return 0;
 }
+#endif
 
 /**
  * batadv_orig_dump - Dump to netlink the originator infos for a specific
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index d94e298..7f66309 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1047,6 +1047,7 @@ container_register:
 	kfree(tt_data);
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 int batadv_tt_local_seq_print_text(struct seq_file *seq, void *offset)
 {
 	struct net_device *net_dev = (struct net_device *)seq->private;
@@ -1114,6 +1115,7 @@ out:
 		batadv_hardif_put(primary_if);
 	return 0;
 }
+#endif
 
 /**
  * batadv_tt_local_dump_entry - Dump one TT local entry into a message
@@ -1796,6 +1798,7 @@ batadv_transtable_best_orig(struct batadv_priv *bat_priv,
 	return best_entry;
 }
 
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 /**
  * batadv_tt_global_print_entry - print all orig nodes who announce the address
  *  for this global entry
@@ -1919,6 +1922,7 @@ out:
 		batadv_hardif_put(primary_if);
 	return 0;
 }
+#endif
 
 /**
  * batadv_tt_global_dump_subentry - Dump all TT local entries into a message
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index b5f01a3..b3dd1a3 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -1431,7 +1431,9 @@ struct batadv_algo_neigh_ops {
 				     struct batadv_hard_iface *if_outgoing1,
 				     struct batadv_neigh_node *neigh2,
 				     struct batadv_hard_iface *if_outgoing2);
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 	void (*print)(struct batadv_priv *priv, struct seq_file *seq);
+#endif
 	void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
 		     struct batadv_priv *priv,
 		     struct batadv_hard_iface *hard_iface);
@@ -1453,8 +1455,10 @@ struct batadv_algo_orig_ops {
 	int (*add_if)(struct batadv_orig_node *orig_node, int max_if_num);
 	int (*del_if)(struct batadv_orig_node *orig_node, int max_if_num,
 		      int del_if_num);
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 	void (*print)(struct batadv_priv *priv, struct seq_file *seq,
 		      struct batadv_hard_iface *hard_iface);
+#endif
 	void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
 		     struct batadv_priv *priv,
 		     struct batadv_hard_iface *hard_iface);
@@ -1480,7 +1484,9 @@ struct batadv_algo_gw_ops {
 	bool (*is_eligible)(struct batadv_priv *bat_priv,
 			    struct batadv_orig_node *curr_gw_orig,
 			    struct batadv_orig_node *orig_node);
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
 	void (*print)(struct batadv_priv *bat_priv, struct seq_file *seq);
+#endif
 	void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,
 		     struct batadv_priv *priv);
 };
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16*
  2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
                   ` (19 preceding siblings ...)
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 20/20] batman-adv: Allow to disable debugfs support Simon Wunderlich
@ 2016-08-23  3:40 ` David Miller
  20 siblings, 0 replies; 24+ messages in thread
From: David Miller @ 2016-08-23  3:40 UTC (permalink / raw)
  To: sw; +Cc: netdev, b.a.t.m.a.n

From: Simon Wunderlich <sw@simonwunderlich.de>
Date: Mon, 22 Aug 2016 15:56:00 +0200

> this is our third (and final, for now) pull request for batman-adv in this round,
> with mostly maintainability stuff.
> 
> Please pull or let me know of any problem!

Pulled, thanks Simon.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH 14/20] batman-adv: Place kref_get for softif_vlan near use
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 14/20] batman-adv: Place kref_get for softif_vlan " Simon Wunderlich
@ 2016-08-23 13:20   ` Sergei Shtylyov
  0 siblings, 0 replies; 24+ messages in thread
From: Sergei Shtylyov @ 2016-08-23 13:20 UTC (permalink / raw)
  To: Simon Wunderlich, davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

Hello.

On 8/22/2016 4:56 PM, Simon Wunderlich wrote:

> From: Sven Eckelmann <sven@narfation.org>
>
> It is hard to understand why the refcnt is increased when it isn't done
> near the actual place the new reference is used. So using kref_get right
> before the place which requires the reference and in the same function
> helps to avoid accidental problems caused by incorrect reference counting.

     I don't think your boilerplate log works for this patch where you are 
*adding* the ref-counting.

> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
> ---
>  net/batman-adv/soft-interface.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
> index e508bf5..49e16b6 100644
> --- a/net/batman-adv/soft-interface.c
> +++ b/net/batman-adv/soft-interface.c
> @@ -594,6 +594,7 @@ int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
>  	}
>
>  	spin_lock_bh(&bat_priv->softif_vlan_list_lock);
> +	kref_get(&vlan->refcount);
>  	hlist_add_head_rcu(&vlan->list, &bat_priv->softif_vlan_list);
>  	spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
>
> @@ -604,6 +605,9 @@ int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
>  			    bat_priv->soft_iface->dev_addr, vid,
>  			    BATADV_NULL_IFINDEX, BATADV_NO_MARK);
>
> +	/* don't return reference to new softif_vlan */
> +	batadv_softif_vlan_put(vlan);
> +
>  	return 0;
>  }
>

MBR, Sergei


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH 18/20] batman-adv: Place kref_get for tvlv_handler near use
  2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 18/20] batman-adv: Place kref_get for tvlv_handler " Simon Wunderlich
@ 2016-08-23 13:36   ` Sergei Shtylyov
  0 siblings, 0 replies; 24+ messages in thread
From: Sergei Shtylyov @ 2016-08-23 13:36 UTC (permalink / raw)
  To: Simon Wunderlich, davem; +Cc: netdev, b.a.t.m.a.n, Marek Lindner

On 8/22/2016 4:56 PM, Simon Wunderlich wrote:

> From: Sven Eckelmann <sven@narfation.org>
>
> It is hard to understand why the refcnt is increased when it isn't done
> near the actual place the new reference is used. So using kref_get right
> before the place which requires the reference and in the same function
> helps to avoid accidental problems caused by incorrect reference counting.

      Neither does the boilerplate work for this patch...

> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
> ---
>  net/batman-adv/tvlv.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
> index 3533867..77654f0 100644
> --- a/net/batman-adv/tvlv.c
> +++ b/net/batman-adv/tvlv.c
> @@ -547,8 +547,12 @@ void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
>  	INIT_HLIST_NODE(&tvlv_handler->list);
>
>  	spin_lock_bh(&bat_priv->tvlv.handler_list_lock);
> +	kref_get(&tvlv_handler->refcount);
>  	hlist_add_head_rcu(&tvlv_handler->list, &bat_priv->tvlv.handler_list);
>  	spin_unlock_bh(&bat_priv->tvlv.handler_list_lock);
> +
> +	/* don't return reference to new tvlv_handler */
> +	batadv_tvlv_handler_put(tvlv_handler);
>  }
>
>  /**

MBR, Sergei


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2016-08-23 13:36 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-22 13:56 [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 01/20] batman-adv: Place kref_get for orig_node_vlan near use Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 02/20] batman-adv: Place kref_get for orig_ifinfo " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 03/20] batman-adv: Place kref_get for tt_orig_list_entry " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 04/20] batman-adv: Place kref_get for neigh_ifinfo " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 05/20] batman-adv: Place kref_get for neigh_node " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 06/20] batman-adv: Place kref_get for orig_node " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 07/20] batman-adv: Place kref_get for tt_local_entry " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 08/20] batman-adv: Place kref_get for tt_common " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 09/20] batman-adv: Place kref_get for bla_claim " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 10/20] batman-adv: Place kref_get for bla_backbone_gw " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 11/20] batman-adv: Place kref_get for dat_entry " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 12/20] batman-adv: Place kref_get for gw_node " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 13/20] batman-adv: Place kref_get for hard_iface " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 14/20] batman-adv: Place kref_get for softif_vlan " Simon Wunderlich
2016-08-23 13:20   ` Sergei Shtylyov
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 15/20] batman-adv: Place kref_get for nc_node " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 16/20] batman-adv: Place kref_get for nc_path " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 17/20] batman-adv: Place kref_get for tvlv_container " Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 18/20] batman-adv: Place kref_get for tvlv_handler " Simon Wunderlich
2016-08-23 13:36   ` Sergei Shtylyov
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 19/20] batman-adv: Keep batadv netdev when hardif disappears Simon Wunderlich
2016-08-22 13:56 ` [B.A.T.M.A.N.] [PATCH 20/20] batman-adv: Allow to disable debugfs support Simon Wunderlich
2016-08-23  3:40 ` [B.A.T.M.A.N.] [PATCH 00/20] pull request for net-next: batman-adv 2016-08-16* David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).