All of lore.kernel.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Free local translation table on error in tt_init
@ 2012-05-04  7:32 Sven Eckelmann
  2012-05-04  7:32 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Free bla hashes on error in bla_init Sven Eckelmann
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Sven Eckelmann @ 2012-05-04  7:32 UTC (permalink / raw)
  To: b.a.t.m.a.n

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 translation-table.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/translation-table.c b/translation-table.c
index 88c62f1..c3b7773 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -1776,8 +1776,10 @@ int tt_init(struct bat_priv *bat_priv)
 	if (!tt_local_init(bat_priv))
 		return 0;
 
-	if (!tt_global_init(bat_priv))
+	if (!tt_global_init(bat_priv)) {
+		tt_local_table_free(bat_priv);
 		return 0;
+	}
 
 	tt_start_timer(bat_priv);
 
-- 
1.7.10


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

* [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Free bla hashes on error in bla_init
  2012-05-04  7:32 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Free local translation table on error in tt_init Sven Eckelmann
@ 2012-05-04  7:32 ` Sven Eckelmann
  2012-05-04  7:32 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Return error codes instead of -1 on failures Sven Eckelmann
  2012-05-05 11:27 ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Sven Eckelmann
  2 siblings, 0 replies; 10+ messages in thread
From: Sven Eckelmann @ 2012-05-04  7:32 UTC (permalink / raw)
  To: b.a.t.m.a.n

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 bridge_loop_avoidance.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 8bb274b..9d1cb9b 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -1167,15 +1167,19 @@ int bla_init(struct bat_priv *bat_priv)
 		return 1;
 
 	bat_priv->claim_hash = hash_new(128);
+	if (!bat_priv->claim_hash)
+		return -1;
+
 	bat_priv->backbone_hash = hash_new(32);
+	if (!bat_priv->backbone_hash) {
+		hash_destroy(bat_priv->claim_hash);
+		return -1;
+	}
 
 	hash_set_lock_class(bat_priv->claim_hash, &claim_hash_lock_class_key);
 	hash_set_lock_class(bat_priv->backbone_hash,
 			    &backbone_hash_lock_class_key);
 
-	if (!bat_priv->claim_hash || !bat_priv->backbone_hash)
-		return -1;
-
 	bat_dbg(DBG_BLA, bat_priv, "bla hashes initialized\n");
 
 	bla_start_timer(bat_priv);
-- 
1.7.10


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

* [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Return error codes instead of -1 on failures
  2012-05-04  7:32 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Free local translation table on error in tt_init Sven Eckelmann
  2012-05-04  7:32 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Free bla hashes on error in bla_init Sven Eckelmann
@ 2012-05-04  7:32 ` Sven Eckelmann
  2012-05-05 11:27 ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Sven Eckelmann
  2 siblings, 0 replies; 10+ messages in thread
From: Sven Eckelmann @ 2012-05-04  7:32 UTC (permalink / raw)
  To: b.a.t.m.a.n

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Fix non-negative error return codes in bat_algo_register. Found by Antonio
Quartulli <ordex@autistici.org>

 bat_sysfs.c             |    2 +-
 bridge_loop_avoidance.c |    8 ++++----
 main.c                  |   27 ++++++++++++++++-----------
 originator.c            |   18 +++++++++---------
 translation-table.c     |   24 ++++++++++++++----------
 vis.c                   |    8 ++++----
 6 files changed, 48 insertions(+), 39 deletions(-)

diff --git a/bat_sysfs.c b/bat_sysfs.c
index acb2640..6ba3d89 100644
--- a/bat_sysfs.c
+++ b/bat_sysfs.c
@@ -680,7 +680,7 @@ void sysfs_del_hardif(struct kobject **hardif_obj)
 int throw_uevent(struct bat_priv *bat_priv, enum uev_type type,
 		 enum uev_action action, const char *data)
 {
-	int ret = -1;
+	int ret = -ENOMEM;
 	struct hard_iface *primary_if = NULL;
 	struct kobject *bat_kobj;
 	char *uevent_env[4] = { NULL, NULL, NULL, NULL };
diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 9d1cb9b..4ac1061 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -1164,16 +1164,16 @@ int bla_init(struct bat_priv *bat_priv)
 	bat_priv->bcast_duplist_curr = 0;
 
 	if (bat_priv->claim_hash)
-		return 1;
+		return 0;
 
 	bat_priv->claim_hash = hash_new(128);
 	if (!bat_priv->claim_hash)
-		return -1;
+		return -ENOMEM;
 
 	bat_priv->backbone_hash = hash_new(32);
 	if (!bat_priv->backbone_hash) {
 		hash_destroy(bat_priv->claim_hash);
-		return -1;
+		return -ENOMEM;
 	}
 
 	hash_set_lock_class(bat_priv->claim_hash, &claim_hash_lock_class_key);
@@ -1183,7 +1183,7 @@ int bla_init(struct bat_priv *bat_priv)
 	bat_dbg(DBG_BLA, bat_priv, "bla hashes initialized\n");
 
 	bla_start_timer(bat_priv);
-	return 1;
+	return 0;
 }
 
 /**
diff --git a/main.c b/main.c
index 79dd604..805373f 100644
--- a/main.c
+++ b/main.c
@@ -92,6 +92,7 @@ static void __exit batman_exit(void)
 int mesh_init(struct net_device *soft_iface)
 {
 	struct bat_priv *bat_priv = netdev_priv(soft_iface);
+	int ret;
 
 	spin_lock_init(&bat_priv->forw_bat_list_lock);
 	spin_lock_init(&bat_priv->forw_bcast_list_lock);
@@ -110,30 +111,32 @@ int mesh_init(struct net_device *soft_iface)
 	INIT_LIST_HEAD(&bat_priv->tt_req_list);
 	INIT_LIST_HEAD(&bat_priv->tt_roam_list);
 
-	if (originator_init(bat_priv) < 1)
+	ret = originator_init(bat_priv);
+	if (ret < 0)
 		goto err;
 
-	if (tt_init(bat_priv) < 1)
+	ret = tt_init(bat_priv);
+	if (ret < 0)
 		goto err;
 
 	tt_local_add(soft_iface, soft_iface->dev_addr, NULL_IFINDEX);
 
-	if (vis_init(bat_priv) < 1)
+	ret = vis_init(bat_priv);
+	if (ret < 0)
 		goto err;
 
-	if (bla_init(bat_priv) < 1)
+	ret = bla_init(bat_priv);
+	if (ret < 0)
 		goto err;
 
 	atomic_set(&bat_priv->gw_reselect, 0);
 	atomic_set(&bat_priv->mesh_state, MESH_ACTIVE);
-	goto end;
+
+	return 0;
 
 err:
 	mesh_free(soft_iface);
-	return -1;
-
-end:
-	return 0;
+	return ret;
 }
 
 void mesh_free(struct net_device *soft_iface)
@@ -321,12 +324,13 @@ static struct bat_algo_ops *bat_algo_get(char *name)
 int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
 {
 	struct bat_algo_ops *bat_algo_ops_tmp;
-	int ret = -1;
+	int ret;
 
 	bat_algo_ops_tmp = bat_algo_get(bat_algo_ops->name);
 	if (bat_algo_ops_tmp) {
 		pr_info("Trying to register already registered routing algorithm: %s\n",
 			bat_algo_ops->name);
+		ret = -EEXIST;
 		goto out;
 	}
 
@@ -339,6 +343,7 @@ int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
 	    !bat_algo_ops->bat_ogm_emit) {
 		pr_info("Routing algo '%s' does not implement required ops\n",
 			bat_algo_ops->name);
+		ret = -EINVAL;
 		goto out;
 	}
 
@@ -353,7 +358,7 @@ out:
 int bat_algo_select(struct bat_priv *bat_priv, char *name)
 {
 	struct bat_algo_ops *bat_algo_ops;
-	int ret = -1;
+	int ret = -EINVAL;
 
 	bat_algo_ops = bat_algo_get(name);
 	if (!bat_algo_ops)
diff --git a/originator.c b/originator.c
index 30889c9..61e091d 100644
--- a/originator.c
+++ b/originator.c
@@ -51,7 +51,7 @@ static int compare_orig(const struct hlist_node *node, const void *data2)
 int originator_init(struct bat_priv *bat_priv)
 {
 	if (bat_priv->orig_hash)
-		return 1;
+		return 0;
 
 	bat_priv->orig_hash = hash_new(1024);
 
@@ -59,10 +59,10 @@ int originator_init(struct bat_priv *bat_priv)
 		goto err;
 
 	start_purge_timer(bat_priv);
-	return 1;
+	return 0;
 
 err:
-	return 0;
+	return -ENOMEM;
 }
 
 void neigh_node_free_ref(struct neigh_node *neigh_node)
@@ -489,7 +489,7 @@ static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
 	data_ptr = kmalloc(max_if_num * sizeof(unsigned long) * NUM_WORDS,
 			   GFP_ATOMIC);
 	if (!data_ptr)
-		return -1;
+		return -ENOMEM;
 
 	memcpy(data_ptr, orig_node->bcast_own,
 	       (max_if_num - 1) * sizeof(unsigned long) * NUM_WORDS);
@@ -498,7 +498,7 @@ static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
 
 	data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
 	if (!data_ptr)
-		return -1;
+		return -ENOMEM;
 
 	memcpy(data_ptr, orig_node->bcast_own_sum,
 	       (max_if_num - 1) * sizeof(uint8_t));
@@ -529,7 +529,7 @@ int orig_hash_add_if(struct hard_iface *hard_iface, int max_if_num)
 			ret = orig_node_add_if(orig_node, max_if_num);
 			spin_unlock_bh(&orig_node->ogm_cnt_lock);
 
-			if (ret == -1)
+			if (ret == -ENOMEM)
 				goto err;
 		}
 		rcu_read_unlock();
@@ -555,7 +555,7 @@ static int orig_node_del_if(struct orig_node *orig_node,
 	chunk_size = sizeof(unsigned long) * NUM_WORDS;
 	data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
 	if (!data_ptr)
-		return -1;
+		return -ENOMEM;
 
 	/* copy first part */
 	memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
@@ -574,7 +574,7 @@ free_bcast_own:
 
 	data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
 	if (!data_ptr)
-		return -1;
+		return -ENOMEM;
 
 	memcpy(data_ptr, orig_node->bcast_own_sum,
 	       del_if_num * sizeof(uint8_t));
@@ -613,7 +613,7 @@ int orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num)
 					hard_iface->if_num);
 			spin_unlock_bh(&orig_node->ogm_cnt_lock);
 
-			if (ret == -1)
+			if (ret == -ENOMEM)
 				goto err;
 		}
 		rcu_read_unlock();
diff --git a/translation-table.c b/translation-table.c
index c3b7773..5bb2dcf 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -181,14 +181,14 @@ int tt_len(int changes_num)
 static int tt_local_init(struct bat_priv *bat_priv)
 {
 	if (bat_priv->tt_local_hash)
-		return 1;
+		return 0;
 
 	bat_priv->tt_local_hash = hash_new(1024);
 
 	if (!bat_priv->tt_local_hash)
-		return 0;
+		return -ENOMEM;
 
-	return 1;
+	return 0;
 }
 
 void tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
@@ -491,14 +491,14 @@ static void tt_local_table_free(struct bat_priv *bat_priv)
 static int tt_global_init(struct bat_priv *bat_priv)
 {
 	if (bat_priv->tt_global_hash)
-		return 1;
+		return 0;
 
 	bat_priv->tt_global_hash = hash_new(1024);
 
 	if (!bat_priv->tt_global_hash)
-		return 0;
+		return -ENOMEM;
 
-	return 1;
+	return 0;
 }
 
 static void tt_changes_list_free(struct bat_priv *bat_priv)
@@ -1773,12 +1773,16 @@ out:
 
 int tt_init(struct bat_priv *bat_priv)
 {
-	if (!tt_local_init(bat_priv))
-		return 0;
+	int ret;
 
-	if (!tt_global_init(bat_priv)) {
+	ret = tt_local_init(bat_priv);
+	if (ret < 0)
+		return ret;
+
+	ret = tt_global_init(bat_priv);
+	if (ret < 0) {
 		tt_local_table_free(bat_priv);
-		return 0;
+		return ret;
 	}
 
 	tt_start_timer(bat_priv);
diff --git a/vis.c b/vis.c
index cec216f..411c0e1 100644
--- a/vis.c
+++ b/vis.c
@@ -626,7 +626,7 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
 		best_tq = find_best_vis_server(bat_priv, info);
 
 		if (best_tq < 0)
-			return -1;
+			return best_tq;
 	}
 
 	for (i = 0; i < hash->size; i++) {
@@ -878,7 +878,7 @@ int vis_init(struct bat_priv *bat_priv)
 	int hash_added;
 
 	if (bat_priv->vis_hash)
-		return 1;
+		return 0;
 
 	spin_lock_bh(&bat_priv->vis_hash_lock);
 
@@ -929,7 +929,7 @@ int vis_init(struct bat_priv *bat_priv)
 
 	spin_unlock_bh(&bat_priv->vis_hash_lock);
 	start_vis_timer(bat_priv);
-	return 1;
+	return 0;
 
 free_info:
 	kfree(bat_priv->my_vis_info);
@@ -937,7 +937,7 @@ free_info:
 err:
 	spin_unlock_bh(&bat_priv->vis_hash_lock);
 	vis_quit(bat_priv);
-	return 0;
+	return -ENOMEM;
 }
 
 /* Decrease the reference count on a hash item info */
-- 
1.7.10


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

* [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized
  2012-05-04  7:32 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Free local translation table on error in tt_init Sven Eckelmann
  2012-05-04  7:32 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Free bla hashes on error in bla_init Sven Eckelmann
  2012-05-04  7:32 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Return error codes instead of -1 on failures Sven Eckelmann
@ 2012-05-05 11:27 ` Sven Eckelmann
  2012-05-05 11:27   ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: Return error codes instead of -1 on failures Sven Eckelmann
                     ` (2 more replies)
  2 siblings, 3 replies; 10+ messages in thread
From: Sven Eckelmann @ 2012-05-05 11:27 UTC (permalink / raw)
  To: b.a.t.m.a.n

We must be sure that there was no error during the creation of the hash before
we can set the hash lock class. The class set function was added to the wrong
place in 2c9aa3b4c37bd55148f5f25212c89e7bf5f28497

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 bridge_loop_avoidance.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 8bb274b..48831c2 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -1169,13 +1169,13 @@ int bla_init(struct bat_priv *bat_priv)
 	bat_priv->claim_hash = hash_new(128);
 	bat_priv->backbone_hash = hash_new(32);
 
+	if (!bat_priv->claim_hash || !bat_priv->backbone_hash)
+		return -1;
+
 	hash_set_lock_class(bat_priv->claim_hash, &claim_hash_lock_class_key);
 	hash_set_lock_class(bat_priv->backbone_hash,
 			    &backbone_hash_lock_class_key);
 
-	if (!bat_priv->claim_hash || !bat_priv->backbone_hash)
-		return -1;
-
 	bat_dbg(DBG_BLA, bat_priv, "bla hashes initialized\n");
 
 	bla_start_timer(bat_priv);
-- 
1.7.10


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

* [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: Return error codes instead of -1 on failures
  2012-05-05 11:27 ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Sven Eckelmann
@ 2012-05-05 11:27   ` Sven Eckelmann
  2012-05-06 12:36     ` Marek Lindner
  2012-05-05 14:49   ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Antonio Quartulli
  2012-05-06 12:24   ` Marek Lindner
  2 siblings, 1 reply; 10+ messages in thread
From: Sven Eckelmann @ 2012-05-05 11:27 UTC (permalink / raw)
  To: b.a.t.m.a.n

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 bat_sysfs.c             |    2 +-
 bridge_loop_avoidance.c |    6 +++---
 main.c                  |   27 ++++++++++++++++-----------
 originator.c            |   18 +++++++++---------
 translation-table.c     |   24 ++++++++++++++----------
 vis.c                   |    8 ++++----
 6 files changed, 47 insertions(+), 38 deletions(-)

diff --git a/bat_sysfs.c b/bat_sysfs.c
index acb2640..6ba3d89 100644
--- a/bat_sysfs.c
+++ b/bat_sysfs.c
@@ -680,7 +680,7 @@ void sysfs_del_hardif(struct kobject **hardif_obj)
 int throw_uevent(struct bat_priv *bat_priv, enum uev_type type,
 		 enum uev_action action, const char *data)
 {
-	int ret = -1;
+	int ret = -ENOMEM;
 	struct hard_iface *primary_if = NULL;
 	struct kobject *bat_kobj;
 	char *uevent_env[4] = { NULL, NULL, NULL, NULL };
diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 48831c2..89e9721 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -1164,13 +1164,13 @@ int bla_init(struct bat_priv *bat_priv)
 	bat_priv->bcast_duplist_curr = 0;
 
 	if (bat_priv->claim_hash)
-		return 1;
+		return 0;
 
 	bat_priv->claim_hash = hash_new(128);
 	bat_priv->backbone_hash = hash_new(32);
 
 	if (!bat_priv->claim_hash || !bat_priv->backbone_hash)
-		return -1;
+		return -ENOMEM;
 
 	hash_set_lock_class(bat_priv->claim_hash, &claim_hash_lock_class_key);
 	hash_set_lock_class(bat_priv->backbone_hash,
@@ -1179,7 +1179,7 @@ int bla_init(struct bat_priv *bat_priv)
 	bat_dbg(DBG_BLA, bat_priv, "bla hashes initialized\n");
 
 	bla_start_timer(bat_priv);
-	return 1;
+	return 0;
 }
 
 /**
diff --git a/main.c b/main.c
index 79dd604..805373f 100644
--- a/main.c
+++ b/main.c
@@ -92,6 +92,7 @@ static void __exit batman_exit(void)
 int mesh_init(struct net_device *soft_iface)
 {
 	struct bat_priv *bat_priv = netdev_priv(soft_iface);
+	int ret;
 
 	spin_lock_init(&bat_priv->forw_bat_list_lock);
 	spin_lock_init(&bat_priv->forw_bcast_list_lock);
@@ -110,30 +111,32 @@ int mesh_init(struct net_device *soft_iface)
 	INIT_LIST_HEAD(&bat_priv->tt_req_list);
 	INIT_LIST_HEAD(&bat_priv->tt_roam_list);
 
-	if (originator_init(bat_priv) < 1)
+	ret = originator_init(bat_priv);
+	if (ret < 0)
 		goto err;
 
-	if (tt_init(bat_priv) < 1)
+	ret = tt_init(bat_priv);
+	if (ret < 0)
 		goto err;
 
 	tt_local_add(soft_iface, soft_iface->dev_addr, NULL_IFINDEX);
 
-	if (vis_init(bat_priv) < 1)
+	ret = vis_init(bat_priv);
+	if (ret < 0)
 		goto err;
 
-	if (bla_init(bat_priv) < 1)
+	ret = bla_init(bat_priv);
+	if (ret < 0)
 		goto err;
 
 	atomic_set(&bat_priv->gw_reselect, 0);
 	atomic_set(&bat_priv->mesh_state, MESH_ACTIVE);
-	goto end;
+
+	return 0;
 
 err:
 	mesh_free(soft_iface);
-	return -1;
-
-end:
-	return 0;
+	return ret;
 }
 
 void mesh_free(struct net_device *soft_iface)
@@ -321,12 +324,13 @@ static struct bat_algo_ops *bat_algo_get(char *name)
 int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
 {
 	struct bat_algo_ops *bat_algo_ops_tmp;
-	int ret = -1;
+	int ret;
 
 	bat_algo_ops_tmp = bat_algo_get(bat_algo_ops->name);
 	if (bat_algo_ops_tmp) {
 		pr_info("Trying to register already registered routing algorithm: %s\n",
 			bat_algo_ops->name);
+		ret = -EEXIST;
 		goto out;
 	}
 
@@ -339,6 +343,7 @@ int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
 	    !bat_algo_ops->bat_ogm_emit) {
 		pr_info("Routing algo '%s' does not implement required ops\n",
 			bat_algo_ops->name);
+		ret = -EINVAL;
 		goto out;
 	}
 
@@ -353,7 +358,7 @@ out:
 int bat_algo_select(struct bat_priv *bat_priv, char *name)
 {
 	struct bat_algo_ops *bat_algo_ops;
-	int ret = -1;
+	int ret = -EINVAL;
 
 	bat_algo_ops = bat_algo_get(name);
 	if (!bat_algo_ops)
diff --git a/originator.c b/originator.c
index 30889c9..61e091d 100644
--- a/originator.c
+++ b/originator.c
@@ -51,7 +51,7 @@ static int compare_orig(const struct hlist_node *node, const void *data2)
 int originator_init(struct bat_priv *bat_priv)
 {
 	if (bat_priv->orig_hash)
-		return 1;
+		return 0;
 
 	bat_priv->orig_hash = hash_new(1024);
 
@@ -59,10 +59,10 @@ int originator_init(struct bat_priv *bat_priv)
 		goto err;
 
 	start_purge_timer(bat_priv);
-	return 1;
+	return 0;
 
 err:
-	return 0;
+	return -ENOMEM;
 }
 
 void neigh_node_free_ref(struct neigh_node *neigh_node)
@@ -489,7 +489,7 @@ static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
 	data_ptr = kmalloc(max_if_num * sizeof(unsigned long) * NUM_WORDS,
 			   GFP_ATOMIC);
 	if (!data_ptr)
-		return -1;
+		return -ENOMEM;
 
 	memcpy(data_ptr, orig_node->bcast_own,
 	       (max_if_num - 1) * sizeof(unsigned long) * NUM_WORDS);
@@ -498,7 +498,7 @@ static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
 
 	data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
 	if (!data_ptr)
-		return -1;
+		return -ENOMEM;
 
 	memcpy(data_ptr, orig_node->bcast_own_sum,
 	       (max_if_num - 1) * sizeof(uint8_t));
@@ -529,7 +529,7 @@ int orig_hash_add_if(struct hard_iface *hard_iface, int max_if_num)
 			ret = orig_node_add_if(orig_node, max_if_num);
 			spin_unlock_bh(&orig_node->ogm_cnt_lock);
 
-			if (ret == -1)
+			if (ret == -ENOMEM)
 				goto err;
 		}
 		rcu_read_unlock();
@@ -555,7 +555,7 @@ static int orig_node_del_if(struct orig_node *orig_node,
 	chunk_size = sizeof(unsigned long) * NUM_WORDS;
 	data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
 	if (!data_ptr)
-		return -1;
+		return -ENOMEM;
 
 	/* copy first part */
 	memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
@@ -574,7 +574,7 @@ free_bcast_own:
 
 	data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
 	if (!data_ptr)
-		return -1;
+		return -ENOMEM;
 
 	memcpy(data_ptr, orig_node->bcast_own_sum,
 	       del_if_num * sizeof(uint8_t));
@@ -613,7 +613,7 @@ int orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num)
 					hard_iface->if_num);
 			spin_unlock_bh(&orig_node->ogm_cnt_lock);
 
-			if (ret == -1)
+			if (ret == -ENOMEM)
 				goto err;
 		}
 		rcu_read_unlock();
diff --git a/translation-table.c b/translation-table.c
index 88c62f1..6743a66 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -181,14 +181,14 @@ int tt_len(int changes_num)
 static int tt_local_init(struct bat_priv *bat_priv)
 {
 	if (bat_priv->tt_local_hash)
-		return 1;
+		return 0;
 
 	bat_priv->tt_local_hash = hash_new(1024);
 
 	if (!bat_priv->tt_local_hash)
-		return 0;
+		return -ENOMEM;
 
-	return 1;
+	return 0;
 }
 
 void tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
@@ -491,14 +491,14 @@ static void tt_local_table_free(struct bat_priv *bat_priv)
 static int tt_global_init(struct bat_priv *bat_priv)
 {
 	if (bat_priv->tt_global_hash)
-		return 1;
+		return 0;
 
 	bat_priv->tt_global_hash = hash_new(1024);
 
 	if (!bat_priv->tt_global_hash)
-		return 0;
+		return -ENOMEM;
 
-	return 1;
+	return 0;
 }
 
 static void tt_changes_list_free(struct bat_priv *bat_priv)
@@ -1773,11 +1773,15 @@ out:
 
 int tt_init(struct bat_priv *bat_priv)
 {
-	if (!tt_local_init(bat_priv))
-		return 0;
+	int ret;
 
-	if (!tt_global_init(bat_priv))
-		return 0;
+	ret = tt_local_init(bat_priv);
+	if (ret < 0)
+		return ret;
+
+	ret = tt_global_init(bat_priv);
+	if (ret < 0)
+		return ret;
 
 	tt_start_timer(bat_priv);
 
diff --git a/vis.c b/vis.c
index cec216f..411c0e1 100644
--- a/vis.c
+++ b/vis.c
@@ -626,7 +626,7 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
 		best_tq = find_best_vis_server(bat_priv, info);
 
 		if (best_tq < 0)
-			return -1;
+			return best_tq;
 	}
 
 	for (i = 0; i < hash->size; i++) {
@@ -878,7 +878,7 @@ int vis_init(struct bat_priv *bat_priv)
 	int hash_added;
 
 	if (bat_priv->vis_hash)
-		return 1;
+		return 0;
 
 	spin_lock_bh(&bat_priv->vis_hash_lock);
 
@@ -929,7 +929,7 @@ int vis_init(struct bat_priv *bat_priv)
 
 	spin_unlock_bh(&bat_priv->vis_hash_lock);
 	start_vis_timer(bat_priv);
-	return 1;
+	return 0;
 
 free_info:
 	kfree(bat_priv->my_vis_info);
@@ -937,7 +937,7 @@ free_info:
 err:
 	spin_unlock_bh(&bat_priv->vis_hash_lock);
 	vis_quit(bat_priv);
-	return 0;
+	return -ENOMEM;
 }
 
 /* Decrease the reference count on a hash item info */
-- 
1.7.10


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

* Re: [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized
  2012-05-05 11:27 ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Sven Eckelmann
  2012-05-05 11:27   ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: Return error codes instead of -1 on failures Sven Eckelmann
@ 2012-05-05 14:49   ` Antonio Quartulli
  2012-05-05 15:04     ` Sven Eckelmann
  2012-05-06 12:24   ` Marek Lindner
  2 siblings, 1 reply; 10+ messages in thread
From: Antonio Quartulli @ 2012-05-05 14:49 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

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

On Sat, May 05, 2012 at 01:27:27 +0200, Sven Eckelmann wrote:
> We must be sure that there was no error during the creation of the hash before
> we can set the hash lock class. The class set function was added to the wrong
> place in 2c9aa3b4c37bd55148f5f25212c89e7bf5f28497
> 
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
>  bridge_loop_avoidance.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
> index 8bb274b..48831c2 100644
> --- a/bridge_loop_avoidance.c
> +++ b/bridge_loop_avoidance.c
> @@ -1169,13 +1169,13 @@ int bla_init(struct bat_priv *bat_priv)
>  	bat_priv->claim_hash = hash_new(128);
>  	bat_priv->backbone_hash = hash_new(32);
>  
> +	if (!bat_priv->claim_hash || !bat_priv->backbone_hash)
> +		return -1;
> +

if one hash_new succeeds and and the other fails, should we free the allocated
structure before returning?


Cheers,


-- 
Antonio Quartulli

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

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

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

* Re: [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized
  2012-05-05 14:49   ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Antonio Quartulli
@ 2012-05-05 15:04     ` Sven Eckelmann
  2012-05-05 15:16       ` Antonio Quartulli
  0 siblings, 1 reply; 10+ messages in thread
From: Sven Eckelmann @ 2012-05-05 15:04 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

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

On Saturday 05 May 2012 16:49:41 Antonio Quartulli wrote: 
> if one hash_new succeeds and and the other fails, should we free the
> allocated structure before returning?

Please read 201205041534.18504.lindner_marek@yahoo.de

Kind regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized
  2012-05-05 15:04     ` Sven Eckelmann
@ 2012-05-05 15:16       ` Antonio Quartulli
  0 siblings, 0 replies; 10+ messages in thread
From: Antonio Quartulli @ 2012-05-05 15:16 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

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

On Sat, May 05, 2012 at 05:04:39PM +0200, Sven Eckelmann wrote:
> On Saturday 05 May 2012 16:49:41 Antonio Quartulli wrote: 
> > if one hash_new succeeds and and the other fails, should we free the
> > allocated structure before returning?
> 
> Please read 201205041534.18504.lindner_marek@yahoo.de
Done.


Ok, great! :)

Thank you



-- 
Antonio Quartulli

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

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

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

* Re: [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized
  2012-05-05 11:27 ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Sven Eckelmann
  2012-05-05 11:27   ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: Return error codes instead of -1 on failures Sven Eckelmann
  2012-05-05 14:49   ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Antonio Quartulli
@ 2012-05-06 12:24   ` Marek Lindner
  2 siblings, 0 replies; 10+ messages in thread
From: Marek Lindner @ 2012-05-06 12:24 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Saturday, May 05, 2012 19:27:27 Sven Eckelmann wrote:
> We must be sure that there was no error during the creation of the hash
> before we can set the hash lock class. The class set function was added to
> the wrong place in 2c9aa3b4c37bd55148f5f25212c89e7bf5f28497

Applied in revision af01e99.

Thanks,
Marek

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

* Re: [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: Return error codes instead of -1 on failures
  2012-05-05 11:27   ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: Return error codes instead of -1 on failures Sven Eckelmann
@ 2012-05-06 12:36     ` Marek Lindner
  0 siblings, 0 replies; 10+ messages in thread
From: Marek Lindner @ 2012-05-06 12:36 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Saturday, May 05, 2012 19:27:28 Sven Eckelmann wrote:
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
>  bat_sysfs.c             |    2 +-
>  bridge_loop_avoidance.c |    6 +++---
>  main.c                  |   27 ++++++++++++++++-----------
>  originator.c            |   18 +++++++++---------
>  translation-table.c     |   24 ++++++++++++++----------
>  vis.c                   |    8 ++++----
>  6 files changed, 47 insertions(+), 38 deletions(-)

Applied in revision 2f29426.

Thanks,
Marek

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

end of thread, other threads:[~2012-05-06 12:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-04  7:32 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Free local translation table on error in tt_init Sven Eckelmann
2012-05-04  7:32 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Free bla hashes on error in bla_init Sven Eckelmann
2012-05-04  7:32 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Return error codes instead of -1 on failures Sven Eckelmann
2012-05-05 11:27 ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Sven Eckelmann
2012-05-05 11:27   ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: Return error codes instead of -1 on failures Sven Eckelmann
2012-05-06 12:36     ` Marek Lindner
2012-05-05 14:49   ` [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: Only set hash class after hash is initialized Antonio Quartulli
2012-05-05 15:04     ` Sven Eckelmann
2012-05-05 15:16       ` Antonio Quartulli
2012-05-06 12:24   ` Marek Lindner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.