b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] batman-adv: Avoid double freeing of bat_counters
@ 2013-04-17 10:28 Martin Hundebøll
  2013-04-17 12:05 ` Antonio Quartulli
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Hundebøll @ 2013-04-17 10:28 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Martin Hundebøll

On errors in batadv_mesh_init(), bat_counters will be freed in both
batadv_mesh_free() and batadv_softif_init_late(). This patch fixes this
by returning earlier from batadv_softif_init_late() in case of errors in
batadv_mesh_init().

Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
---
 soft-interface.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/soft-interface.c b/soft-interface.c
index c2a9c20..4de4d0f 100644
--- a/soft-interface.c
+++ b/soft-interface.c
@@ -503,6 +503,9 @@ static int batadv_softif_init_late(struct net_device *dev)
 
 unreg_debugfs:
 	batadv_debugfs_del_meshif(dev);
+
+	return ret;
+
 free_bat_counters:
 	free_percpu(bat_priv->bat_counters);
 
-- 
1.8.2.1


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

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Avoid double freeing of bat_counters
  2013-04-17 10:28 [B.A.T.M.A.N.] [PATCH] batman-adv: Avoid double freeing of bat_counters Martin Hundebøll
@ 2013-04-17 12:05 ` Antonio Quartulli
  2013-04-17 12:36   ` [B.A.T.M.A.N.] [PATCHv2] " Martin Hundebøll
  0 siblings, 1 reply; 7+ messages in thread
From: Antonio Quartulli @ 2013-04-17 12:05 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking
  Cc: Martin Hundebøll

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

On Wed, Apr 17, 2013 at 12:28:50PM +0200, Martin Hundebøll wrote:
> On errors in batadv_mesh_init(), bat_counters will be freed in both
> batadv_mesh_free() and batadv_softif_init_late(). This patch fixes this
> by returning earlier from batadv_softif_init_late() in case of errors in
> batadv_mesh_init().
> 
> Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
> ---
>  soft-interface.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/soft-interface.c b/soft-interface.c
> index c2a9c20..4de4d0f 100644
> --- a/soft-interface.c
> +++ b/soft-interface.c
> @@ -503,6 +503,9 @@ static int batadv_softif_init_late(struct net_device *dev)
>  
>  unreg_debugfs:
>  	batadv_debugfs_del_meshif(dev);
> +
> +	return ret;
> +

Hi Martin, good catch!
But using 1 goto to execute 1 operation is not very good.
What about this:


ret = batadv_mesh_init(dev);
if (ret < 0)
	batadv_debugfs_del_meshif(dev);

return ret;


and remove the unreg_debugfs label at all (and its content)


Cheers,

-- 
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara

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

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

* [B.A.T.M.A.N.] [PATCHv2] batman-adv: Avoid double freeing of bat_counters
  2013-04-17 12:05 ` Antonio Quartulli
@ 2013-04-17 12:36   ` Martin Hundebøll
  2013-04-17 15:56     ` Marek Lindner
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Hundebøll @ 2013-04-17 12:36 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Martin Hundebøll

On errors in batadv_mesh_init(), bat_counters will be freed in both
batadv_mesh_free() and batadv_softif_init_late(). This patch fixes this
by returning earlier from batadv_softif_init_late() in case of errors in
batadv_mesh_init().

Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
---
v2:
  Removed label as suggested by Antonio

 soft-interface.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/soft-interface.c b/soft-interface.c
index c2a9c20..44089b3 100644
--- a/soft-interface.c
+++ b/soft-interface.c
@@ -497,12 +497,10 @@ static int batadv_softif_init_late(struct net_device *dev)
 
 	ret = batadv_mesh_init(dev);
 	if (ret < 0)
-		goto unreg_debugfs;
+		batadv_debugfs_del_meshif(dev);
 
-	return 0;
+	return ret;
 
-unreg_debugfs:
-	batadv_debugfs_del_meshif(dev);
 free_bat_counters:
 	free_percpu(bat_priv->bat_counters);
 
-- 
1.8.2.1


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

* Re: [B.A.T.M.A.N.] [PATCHv2] batman-adv: Avoid double freeing of bat_counters
  2013-04-17 12:36   ` [B.A.T.M.A.N.] [PATCHv2] " Martin Hundebøll
@ 2013-04-17 15:56     ` Marek Lindner
  2013-04-17 19:13       ` [B.A.T.M.A.N.] [PATCHv3] " Martin Hundebøll
  0 siblings, 1 reply; 7+ messages in thread
From: Marek Lindner @ 2013-04-17 15:56 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Wednesday, April 17, 2013 20:36:46 Martin Hundebøll wrote:
> --- a/soft-interface.c
> +++ b/soft-interface.c
> @@ -497,12 +497,10 @@ static int batadv_softif_init_late(struct net_device
> *dev) 
>         ret = batadv_mesh_init(dev);
>         if (ret < 0)
> -               goto unreg_debugfs;
> +               batadv_debugfs_del_meshif(dev);
>  
> -       return 0;
> +       return ret;
>  
> -unreg_debugfs:
> -       batadv_debugfs_del_meshif(dev);
>  free_bat_counters:
>         free_percpu(bat_priv->bat_counters);
>  

This looks like a valid problem but I do suggest setting bat_priv-
>bat_counters to NULL after calling free_percpu(). Otherwise we will run into 
this problem again when somebody else changes the order of the calls ...


Cheers,
Marek

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

* [B.A.T.M.A.N.] [PATCHv3] batman-adv: Avoid double freeing of bat_counters
  2013-04-17 15:56     ` Marek Lindner
@ 2013-04-17 19:13       ` Martin Hundebøll
  2013-04-17 19:53         ` Marek Lindner
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Hundebøll @ 2013-04-17 19:13 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Martin Hundebøll

On errors in batadv_mesh_init(), bat_counters will be freed in both
batadv_mesh_free() and batadv_softif_init_late(). This patch fixes this
by returning earlier from batadv_softif_init_late() in case of errors in
batadv_mesh_init() and by setting bat_counters to NULL after freeing.

Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
---
v2:
  Removed label as suggested by Antonio
v3:
  Set bat_counters to NULL after freeing

 main.c           | 1 +
 soft-interface.c | 9 ++++-----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/main.c b/main.c
index 3e30a0f..aae96ca 100644
--- a/main.c
+++ b/main.c
@@ -173,6 +173,7 @@ void batadv_mesh_free(struct net_device *soft_iface)
 	batadv_dat_free(bat_priv);
 
 	free_percpu(bat_priv->bat_counters);
+	bat_priv->bat_counters = NULL;
 
 	atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
 }
diff --git a/soft-interface.c b/soft-interface.c
index c2a9c20..6946caa 100644
--- a/soft-interface.c
+++ b/soft-interface.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
+#/* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
  *
  * Marek Lindner, Simon Wunderlich
  *
@@ -497,14 +497,13 @@ static int batadv_softif_init_late(struct net_device *dev)
 
 	ret = batadv_mesh_init(dev);
 	if (ret < 0)
-		goto unreg_debugfs;
+		batadv_debugfs_del_meshif(dev);
 
-	return 0;
+	return ret;
 
-unreg_debugfs:
-	batadv_debugfs_del_meshif(dev);
 free_bat_counters:
 	free_percpu(bat_priv->bat_counters);
+	bat_priv->bat_counters = NULL;
 
 	return ret;
 }
-- 
1.8.2.1


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

* Re: [B.A.T.M.A.N.] [PATCHv3] batman-adv: Avoid double freeing of bat_counters
  2013-04-17 19:13       ` [B.A.T.M.A.N.] [PATCHv3] " Martin Hundebøll
@ 2013-04-17 19:53         ` Marek Lindner
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Lindner @ 2013-04-17 19:53 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Martin Hundebøll

On Thursday, April 18, 2013 03:13:16 Martin Hundebøll wrote:
> On errors in batadv_mesh_init(), bat_counters will be freed in both
> batadv_mesh_free() and batadv_softif_init_late(). This patch fixes this
> by returning earlier from batadv_softif_init_late() in case of errors in
> batadv_mesh_init() and by setting bat_counters to NULL after freeing.
> 
> Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
> ---
> v2:
>   Removed label as suggested by Antonio
> v3:
>   Set bat_counters to NULL after freeing
> 
>  main.c           | 1 +
>  soft-interface.c | 9 ++++-----
>  2 files changed, 5 insertions(+), 5 deletions(-)

Applied in revision b10ac71 with minor modifications.

Thanks,
Marek

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

* [B.A.T.M.A.N.] [PATCH] batman-adv: Avoid double freeing of bat_counters
  2013-05-21 19:53 ` [B.A.T.M.A.N.] (no subject) Antonio Quartulli
@ 2013-05-21 19:53   ` Antonio Quartulli
  0 siblings, 0 replies; 7+ messages in thread
From: Antonio Quartulli @ 2013-05-21 19:53 UTC (permalink / raw)
  To: davem
  Cc: netdev, Martin Hundebøll, b.a.t.m.a.n, Marek Lindner,
	Antonio Quartulli

From: Martin Hundebøll <martin@hundeboll.net>

On errors in batadv_mesh_init(), bat_counters will be freed in both
batadv_mesh_free() and batadv_softif_init_late(). This patch fixes this
by returning earlier from batadv_softif_init_late() in case of errors in
batadv_mesh_init() and by setting bat_counters to NULL after freeing.

Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 net/batman-adv/main.c           | 1 +
 net/batman-adv/soft-interface.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 1240f07..51aafd6 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -181,6 +181,7 @@ void batadv_mesh_free(struct net_device *soft_iface)
 	batadv_originator_free(bat_priv);
 
 	free_percpu(bat_priv->bat_counters);
+	bat_priv->bat_counters = NULL;
 
 	atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
 }
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 6f20d33..819dfb0 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -505,6 +505,7 @@ unreg_debugfs:
 	batadv_debugfs_del_meshif(dev);
 free_bat_counters:
 	free_percpu(bat_priv->bat_counters);
+	bat_priv->bat_counters = NULL;
 
 	return ret;
 }
-- 
1.8.1.5


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

end of thread, other threads:[~2013-05-21 19:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-17 10:28 [B.A.T.M.A.N.] [PATCH] batman-adv: Avoid double freeing of bat_counters Martin Hundebøll
2013-04-17 12:05 ` Antonio Quartulli
2013-04-17 12:36   ` [B.A.T.M.A.N.] [PATCHv2] " Martin Hundebøll
2013-04-17 15:56     ` Marek Lindner
2013-04-17 19:13       ` [B.A.T.M.A.N.] [PATCHv3] " Martin Hundebøll
2013-04-17 19:53         ` Marek Lindner
     [not found] <pull request for net: batman-adv 2013-05-21>
2013-05-21 19:53 ` [B.A.T.M.A.N.] (no subject) Antonio Quartulli
2013-05-21 19:53   ` [B.A.T.M.A.N.] [PATCH] batman-adv: Avoid double freeing of bat_counters Antonio Quartulli

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