aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2012-02-07 04:20:48 -0500
committerAntonio Quartulli <ordex@autistici.org>2012-04-18 03:53:59 -0400
commit77af7575c4b11ce7d27b4cb372abd358b2dcd850 (patch)
tree7e29c816a445dbce85758313685046edb98844d5
parent00a50076a3afa4014cdd57e87e31a00ce4c4b67e (diff)
batman-adv: handle routing code initialization properly
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de> Signed-off-by: Antonio Quartulli <ordex@autistici.org>
-rw-r--r--net/batman-adv/bat_iv_ogm.c11
-rw-r--r--net/batman-adv/hard-interface.c15
-rw-r--r--net/batman-adv/types.h2
3 files changed, 17 insertions, 11 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 4cc66db699ed..271467033a1c 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -30,10 +30,11 @@
30#include "send.h" 30#include "send.h"
31#include "bat_algo.h" 31#include "bat_algo.h"
32 32
33static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface) 33static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
34{ 34{
35 struct batman_ogm_packet *batman_ogm_packet; 35 struct batman_ogm_packet *batman_ogm_packet;
36 uint32_t random_seqno; 36 uint32_t random_seqno;
37 int res = -1;
37 38
38 /* randomize initial seqno to avoid collision */ 39 /* randomize initial seqno to avoid collision */
39 get_random_bytes(&random_seqno, sizeof(random_seqno)); 40 get_random_bytes(&random_seqno, sizeof(random_seqno));
@@ -42,6 +43,9 @@ static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
42 hard_iface->packet_len = BATMAN_OGM_LEN; 43 hard_iface->packet_len = BATMAN_OGM_LEN;
43 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC); 44 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
44 45
46 if (!hard_iface->packet_buff)
47 goto out;
48
45 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; 49 batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
46 batman_ogm_packet->header.packet_type = BAT_OGM; 50 batman_ogm_packet->header.packet_type = BAT_OGM;
47 batman_ogm_packet->header.version = COMPAT_VERSION; 51 batman_ogm_packet->header.version = COMPAT_VERSION;
@@ -50,6 +54,11 @@ static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
50 batman_ogm_packet->tq = TQ_MAX_VALUE; 54 batman_ogm_packet->tq = TQ_MAX_VALUE;
51 batman_ogm_packet->tt_num_changes = 0; 55 batman_ogm_packet->tt_num_changes = 0;
52 batman_ogm_packet->ttvn = 0; 56 batman_ogm_packet->ttvn = 0;
57
58 res = 0;
59
60out:
61 return res;
53} 62}
54 63
55static void bat_iv_ogm_iface_disable(struct hard_iface *hard_iface) 64static void bat_iv_ogm_iface_disable(struct hard_iface *hard_iface)
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index fd9715ec6dbd..3b391fd3b5b2 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -304,22 +304,17 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
304 if (!softif_is_valid(soft_iface)) { 304 if (!softif_is_valid(soft_iface)) {
305 pr_err("Can't create batman mesh interface %s: already exists as regular interface\n", 305 pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
306 soft_iface->name); 306 soft_iface->name);
307 dev_put(soft_iface);
308 ret = -EINVAL; 307 ret = -EINVAL;
309 goto err; 308 goto err_dev;
310 } 309 }
311 310
312 hard_iface->soft_iface = soft_iface; 311 hard_iface->soft_iface = soft_iface;
313 bat_priv = netdev_priv(hard_iface->soft_iface); 312 bat_priv = netdev_priv(hard_iface->soft_iface);
314 313
315 bat_priv->bat_algo_ops->bat_iface_enable(hard_iface); 314 ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface);
316 315 if (ret < 0) {
317 if (!hard_iface->packet_buff) {
318 bat_err(hard_iface->soft_iface,
319 "Can't add interface packet (%s): out of memory\n",
320 hard_iface->net_dev->name);
321 ret = -ENOMEM; 316 ret = -ENOMEM;
322 goto err; 317 goto err_dev;
323 } 318 }
324 319
325 hard_iface->if_num = bat_priv->num_ifaces; 320 hard_iface->if_num = bat_priv->num_ifaces;
@@ -363,6 +358,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
363out: 358out:
364 return 0; 359 return 0;
365 360
361err_dev:
362 dev_put(soft_iface);
366err: 363err:
367 hardif_free_ref(hard_iface); 364 hardif_free_ref(hard_iface);
368 return ret; 365 return ret;
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index b034cf23bc9a..dd78023800bd 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -378,7 +378,7 @@ struct bat_algo_ops {
378 struct hlist_node list; 378 struct hlist_node list;
379 char *name; 379 char *name;
380 /* init routing info when hard-interface is enabled */ 380 /* init routing info when hard-interface is enabled */
381 void (*bat_iface_enable)(struct hard_iface *hard_iface); 381 int (*bat_iface_enable)(struct hard_iface *hard_iface);
382 /* de-init routing info when hard-interface is disabled */ 382 /* de-init routing info when hard-interface is disabled */
383 void (*bat_iface_disable)(struct hard_iface *hard_iface); 383 void (*bat_iface_disable)(struct hard_iface *hard_iface);
384 /* init primary OGM when primary interface is selected */ 384 /* init primary OGM when primary interface is selected */