batman-adv: refactor batadv_neigh_node_* functions to follow common style
authorMarek Lindner <mareklindner@neomailbox.ch>
Mon, 2 May 2016 17:52:08 +0000 (01:52 +0800)
committerSimon Wunderlich <sw@simonwunderlich.de>
Thu, 30 Jun 2016 08:29:43 +0000 (10:29 +0200)
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
net/batman-adv/bat_iv_ogm.c
net/batman-adv/bat_v_elp.c
net/batman-adv/bat_v_ogm.c
net/batman-adv/originator.c
net/batman-adv/originator.h

index ce2f203048d35a606487e9cd3a9acec3d72d85f6..aa11296e6bf8b3d3d2fcce2a87ca633c82725507 100644 (file)
@@ -336,7 +336,8 @@ batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
 {
        struct batadv_neigh_node *neigh_node;
 
-       neigh_node = batadv_neigh_node_new(orig_node, hard_iface, neigh_addr);
+       neigh_node = batadv_neigh_node_get_or_create(orig_node,
+                                                    hard_iface, neigh_addr);
        if (!neigh_node)
                goto out;
 
index df42eb1365a0122ce08d1fe7657492745f4957a8..8909d1eb962280180a30b5a7d4f6f04b225afeb2 100644 (file)
@@ -443,7 +443,8 @@ static void batadv_v_elp_neigh_update(struct batadv_priv *bat_priv,
        if (!orig_neigh)
                return;
 
-       neigh = batadv_neigh_node_new(orig_neigh, if_incoming, neigh_addr);
+       neigh = batadv_neigh_node_get_or_create(orig_neigh,
+                                               if_incoming, neigh_addr);
        if (!neigh)
                goto orig_free;
 
index 473ebb9a0e737a23c29c7293cfe193959f1aec07..23ea9bfb9f673ba66ffe0d1bcbe4a217b01801b2 100644 (file)
@@ -683,8 +683,8 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,
        if (!orig_node)
                return;
 
-       neigh_node = batadv_neigh_node_new(orig_node, if_incoming,
-                                          ethhdr->h_source);
+       neigh_node = batadv_neigh_node_get_or_create(orig_node, if_incoming,
+                                                    ethhdr->h_source);
        if (!neigh_node)
                goto out;
 
index 7f51bc2c06eb7699492c41f2fe46fe85b26147a2..b0bad5726557fe32c248c62164ced5276185c401 100644 (file)
@@ -602,19 +602,19 @@ batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface,
 }
 
 /**
- * batadv_neigh_node_new - create and init a new neigh_node object
+ * batadv_neigh_node_create - create a neigh node object
  * @orig_node: originator object representing the neighbour
  * @hard_iface: the interface where the neighbour is connected to
  * @neigh_addr: the mac address of the neighbour interface
  *
  * Allocates a new neigh_node object and initialises all the generic fields.
  *
- * Return: neighbor when found. Othwerwise NULL
+ * Return: the neighbour node if found or created or NULL otherwise.
  */
-struct batadv_neigh_node *
-batadv_neigh_node_new(struct batadv_orig_node *orig_node,
-                     struct batadv_hard_iface *hard_iface,
-                     const u8 *neigh_addr)
+static struct batadv_neigh_node *
+batadv_neigh_node_create(struct batadv_orig_node *orig_node,
+                        struct batadv_hard_iface *hard_iface,
+                        const u8 *neigh_addr)
 {
        struct batadv_neigh_node *neigh_node;
        struct batadv_hardif_neigh_node *hardif_neigh = NULL;
@@ -666,6 +666,29 @@ out:
        return neigh_node;
 }
 
+/**
+ * batadv_neigh_node_get_or_create - retrieve or create a neigh node object
+ * @orig_node: originator object representing the neighbour
+ * @hard_iface: the interface where the neighbour is connected to
+ * @neigh_addr: the mac address of the neighbour interface
+ *
+ * Return: the neighbour node if found or created or NULL otherwise.
+ */
+struct batadv_neigh_node *
+batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,
+                               struct batadv_hard_iface *hard_iface,
+                               const u8 *neigh_addr)
+{
+       struct batadv_neigh_node *neigh_node = NULL;
+
+       /* first check without locking to avoid the overhead */
+       neigh_node = batadv_neigh_node_get(orig_node, hard_iface, neigh_addr);
+       if (neigh_node)
+               return neigh_node;
+
+       return batadv_neigh_node_create(orig_node, hard_iface, neigh_addr);
+}
+
 /**
  * batadv_hardif_neigh_seq_print_text - print the single hop neighbour list
  * @seq: neighbour table seq_file struct
index 64a8951e58446fc11974622ab59b3b6a2d78dc34..566306bf05dc213ad27fcba38a553146deee12d6 100644 (file)
@@ -46,9 +46,9 @@ batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface,
 void
 batadv_hardif_neigh_put(struct batadv_hardif_neigh_node *hardif_neigh);
 struct batadv_neigh_node *
-batadv_neigh_node_new(struct batadv_orig_node *orig_node,
-                     struct batadv_hard_iface *hard_iface,
-                     const u8 *neigh_addr);
+batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,
+                               struct batadv_hard_iface *hard_iface,
+                               const u8 *neigh_addr);
 void batadv_neigh_node_put(struct batadv_neigh_node *neigh_node);
 struct batadv_neigh_node *
 batadv_orig_router_get(struct batadv_orig_node *orig_node,