Re: [B.A.T.M.A.N.] [PATCH 05/11] batman-adv: handle routing code initialization properly

2012-04-18 Thread Antonio Quartulli
On Tue, Apr 17, 2012 at 10:46:30 -0400, David Miller wrote:
 From: Antonio Quartulli or...@autistici.org
 Date: Tue, 17 Apr 2012 13:58:21 +0200
 
  @@ -30,10 +30,11 @@
   #include send.h
   #include bat_algo.h
   
  -static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
  +static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
   {
  struct batman_ogm_packet *batman_ogm_packet;
  unsigned long random_seqno;
  +   int res = -1;
   
  /* randomize initial seqno to avoid collision */
  get_random_bytes(random_seqno, sizeof(unsigned long));
 
 Use real error codes, even as a default, instead of meaningless
 values like -1.

Actually all these kind of return values are handled internally the batman-adv
code so we didn't care so much to use real error codes. However using real codes
will surely increase readability.

I will modify this patch and I'll try to suggest other developers to use real
codes too.

Thank you.

-- 
Antonio Quartulli

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


pgp1ISbWxy7n9.pgp
Description: PGP signature


[B.A.T.M.A.N.] [PATCH 05/11] batman-adv: handle routing code initialization properly

2012-04-17 Thread Antonio Quartulli
From: Marek Lindner lindner_ma...@yahoo.de

Signed-off-by: Marek Lindner lindner_ma...@yahoo.de
Signed-off-by: Antonio Quartulli or...@autistici.org
---
 net/batman-adv/bat_iv_ogm.c |   11 ++-
 net/batman-adv/hard-interface.c |   15 ++-
 net/batman-adv/types.h  |2 +-
 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 b8cb031..f31f2e7 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -30,10 +30,11 @@
 #include send.h
 #include bat_algo.h
 
-static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
+static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
 {
struct batman_ogm_packet *batman_ogm_packet;
unsigned long random_seqno;
+   int res = -1;
 
/* randomize initial seqno to avoid collision */
get_random_bytes(random_seqno, sizeof(unsigned long));
@@ -42,6 +43,9 @@ static void bat_iv_ogm_iface_enable(struct hard_iface 
*hard_iface)
hard_iface-packet_len = BATMAN_OGM_LEN;
hard_iface-packet_buff = kmalloc(hard_iface-packet_len, GFP_ATOMIC);
 
+   if (!hard_iface-packet_buff)
+   goto out;
+
batman_ogm_packet = (struct batman_ogm_packet *)hard_iface-packet_buff;
batman_ogm_packet-header.packet_type = BAT_OGM;
batman_ogm_packet-header.version = COMPAT_VERSION;
@@ -50,6 +54,11 @@ static void bat_iv_ogm_iface_enable(struct hard_iface 
*hard_iface)
batman_ogm_packet-tq = TQ_MAX_VALUE;
batman_ogm_packet-tt_num_changes = 0;
batman_ogm_packet-ttvn = 0;
+
+   res = 0;
+
+out:
+   return res;
 }
 
 static 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 fd9715e..3b391fd 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,
if (!softif_is_valid(soft_iface)) {
pr_err(Can't create batman mesh interface %s: already exists 
as regular interface\n,
   soft_iface-name);
-   dev_put(soft_iface);
ret = -EINVAL;
-   goto err;
+   goto err_dev;
}
 
hard_iface-soft_iface = soft_iface;
bat_priv = netdev_priv(hard_iface-soft_iface);
 
-   bat_priv-bat_algo_ops-bat_iface_enable(hard_iface);
-
-   if (!hard_iface-packet_buff) {
-   bat_err(hard_iface-soft_iface,
-   Can't add interface packet (%s): out of memory\n,
-   hard_iface-net_dev-name);
+   ret = bat_priv-bat_algo_ops-bat_iface_enable(hard_iface);
+   if (ret  0) {
ret = -ENOMEM;
-   goto err;
+   goto err_dev;
}
 
hard_iface-if_num = bat_priv-num_ifaces;
@@ -363,6 +358,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
 out:
return 0;
 
+err_dev:
+   dev_put(soft_iface);
 err:
hardif_free_ref(hard_iface);
return ret;
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index b034cf2..dd78023 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -378,7 +378,7 @@ struct bat_algo_ops {
struct hlist_node list;
char *name;
/* init routing info when hard-interface is enabled */
-   void (*bat_iface_enable)(struct hard_iface *hard_iface);
+   int (*bat_iface_enable)(struct hard_iface *hard_iface);
/* de-init routing info when hard-interface is disabled */
void (*bat_iface_disable)(struct hard_iface *hard_iface);
/* init primary OGM when primary interface is selected */
-- 
1.7.9.4



Re: [B.A.T.M.A.N.] [PATCH 05/11] batman-adv: handle routing code initialization properly

2012-04-17 Thread David Miller
From: Antonio Quartulli or...@autistici.org
Date: Tue, 17 Apr 2012 13:58:21 +0200

 @@ -30,10 +30,11 @@
  #include send.h
  #include bat_algo.h
  
 -static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
 +static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
  {
   struct batman_ogm_packet *batman_ogm_packet;
   unsigned long random_seqno;
 + int res = -1;
  
   /* randomize initial seqno to avoid collision */
   get_random_bytes(random_seqno, sizeof(unsigned long));

Use real error codes, even as a default, instead of meaningless
values like -1.