b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove vis info on hashing errors
@ 2011-01-28 17:34 Sven Eckelmann
  2011-01-28 17:34 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Remove vis info element in free_info Sven Eckelmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sven Eckelmann @ 2011-01-28 17:34 UTC (permalink / raw)
  To: b.a.t.m.a.n

A newly created vis info object must be removed when it couldn't be
added to the hash. The old_info which has to be replaced was already
removed and isn't related to the hash anymore.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 batman-adv/vis.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/batman-adv/vis.c b/batman-adv/vis.c
index 2cdf01c..9d2729c 100644
--- a/batman-adv/vis.c
+++ b/batman-adv/vis.c
@@ -446,7 +446,7 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
 			      info);
 	if (hash_added < 0) {
 		/* did not work (for some reason) */
-		kref_put(&old_info->refcount, free_info);
+		kref_put(&info->refcount, free_info);
 		info = NULL;
 	}
 
-- 
1.7.2.3


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

* [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Remove vis info element in free_info
  2011-01-28 17:34 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove vis info on hashing errors Sven Eckelmann
@ 2011-01-28 17:34 ` Sven Eckelmann
  2011-01-28 17:34 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Make vis info stack traversal threadsafe Sven Eckelmann
  2011-01-29 17:44 ` [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove vis info on hashing errors Simon Wunderlich
  2 siblings, 0 replies; 4+ messages in thread
From: Sven Eckelmann @ 2011-01-28 17:34 UTC (permalink / raw)
  To: b.a.t.m.a.n

The free_info function will be called when no reference to the info
object exists anymore. It must be ensured that the allocated memory
gets freed and not only the elements which are managed by the info
object.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 batman-adv/vis.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/batman-adv/vis.c b/batman-adv/vis.c
index 9d2729c..584781e 100644
--- a/batman-adv/vis.c
+++ b/batman-adv/vis.c
@@ -64,6 +64,7 @@ static void free_info(struct kref *ref)
 
 	spin_unlock_bh(&bat_priv->vis_list_lock);
 	kfree_skb(info->skb_packet);
+	kfree(info);
 }
 
 /* Compare two vis packets, used by the hashing algorithm */
-- 
1.7.2.3


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

* [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Make vis info stack traversal threadsafe
  2011-01-28 17:34 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove vis info on hashing errors Sven Eckelmann
  2011-01-28 17:34 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Remove vis info element in free_info Sven Eckelmann
@ 2011-01-28 17:34 ` Sven Eckelmann
  2011-01-29 17:44 ` [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove vis info on hashing errors Simon Wunderlich
  2 siblings, 0 replies; 4+ messages in thread
From: Sven Eckelmann @ 2011-01-28 17:34 UTC (permalink / raw)
  To: b.a.t.m.a.n

The batman-adv vis server has to a stack which stores all information
about packets which should be send later. This stack is protected
with a spinlock that is used to prevent concurrent write access to it.

The send_vis_packets function has to take all elements from the stack
and send them to other hosts over the primary interface. The send will
be initiated without the lock which protects the stack.

The implementation using list_for_each_entry_safe has the problem that
it stores the next element as "safe ptr" to allow the deletion of the
current element in the list. The list may be modified during the
unlock/lock pair in the loop body which may make the safe pointer
not pointing to correct next element.

It is safer to remove and use the first element from the stack until no
elements are available. This does not need reduntant information which
would have to be validated each time the lock was removed.

Reported-by: Russell Senior <russell@personaltelco.net>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 batman-adv/vis.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/batman-adv/vis.c b/batman-adv/vis.c
index 584781e..323f013 100644
--- a/batman-adv/vis.c
+++ b/batman-adv/vis.c
@@ -825,7 +825,7 @@ static void send_vis_packets(struct work_struct *work)
 		container_of(work, struct delayed_work, work);
 	struct bat_priv *bat_priv =
 		container_of(delayed_work, struct bat_priv, vis_work);
-	struct vis_info *info, *temp;
+	struct vis_info *info;
 
 	spin_lock_bh(&bat_priv->vis_hash_lock);
 	purge_vis_packets(bat_priv);
@@ -835,8 +835,9 @@ static void send_vis_packets(struct work_struct *work)
 		send_list_add(bat_priv, bat_priv->my_vis_info);
 	}
 
-	list_for_each_entry_safe(info, temp, &bat_priv->vis_send_list,
-				 send_list) {
+	while (!list_empty(&bat_priv->vis_send_list)) {
+		info = list_first_entry(&bat_priv->vis_send_list,
+					typeof(*info), send_list);
 
 		kref_get(&info->refcount);
 		spin_unlock_bh(&bat_priv->vis_hash_lock);
-- 
1.7.2.3


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

* Re: [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove vis info on hashing errors
  2011-01-28 17:34 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove vis info on hashing errors Sven Eckelmann
  2011-01-28 17:34 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Remove vis info element in free_info Sven Eckelmann
  2011-01-28 17:34 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Make vis info stack traversal threadsafe Sven Eckelmann
@ 2011-01-29 17:44 ` Simon Wunderlich
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Wunderlich @ 2011-01-29 17:44 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

[-- Attachment #1: Type: text/plain, Size: 972 bytes --]

Hello Sven,

i've applied your patches in r1922-r1924.

Thanks for your contribution
	Simon

On Fri, Jan 28, 2011 at 06:34:05PM +0100, Sven Eckelmann wrote:
> A newly created vis info object must be removed when it couldn't be
> added to the hash. The old_info which has to be replaced was already
> removed and isn't related to the hash anymore.
> 
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
>  batman-adv/vis.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/batman-adv/vis.c b/batman-adv/vis.c
> index 2cdf01c..9d2729c 100644
> --- a/batman-adv/vis.c
> +++ b/batman-adv/vis.c
> @@ -446,7 +446,7 @@ static struct vis_info *add_packet(struct bat_priv *bat_priv,
>  			      info);
>  	if (hash_added < 0) {
>  		/* did not work (for some reason) */
> -		kref_put(&old_info->refcount, free_info);
> +		kref_put(&info->refcount, free_info);
>  		info = NULL;
>  	}
>  
> -- 
> 1.7.2.3
> 
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

end of thread, other threads:[~2011-01-29 17:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-28 17:34 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove vis info on hashing errors Sven Eckelmann
2011-01-28 17:34 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Remove vis info element in free_info Sven Eckelmann
2011-01-28 17:34 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Make vis info stack traversal threadsafe Sven Eckelmann
2011-01-29 17:44 ` [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove vis info on hashing errors Simon Wunderlich

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).