Skip to content

Commit 6f0a6b5

Browse files
Marek Lindnersimonwunderlich
authored andcommitted
batman-adv: refactor batadv_neigh_node_* functions to follow common style
Signed-off-by: Marek Lindner <[email protected]> Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent 21c02be commit 6f0a6b5

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

net/batman-adv/bat_iv_ogm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
336336
{
337337
struct batadv_neigh_node *neigh_node;
338338

339-
neigh_node = batadv_neigh_node_new(orig_node, hard_iface, neigh_addr);
339+
neigh_node = batadv_neigh_node_get_or_create(orig_node,
340+
hard_iface, neigh_addr);
340341
if (!neigh_node)
341342
goto out;
342343

net/batman-adv/bat_v_elp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ static void batadv_v_elp_neigh_update(struct batadv_priv *bat_priv,
443443
if (!orig_neigh)
444444
return;
445445

446-
neigh = batadv_neigh_node_new(orig_neigh, if_incoming, neigh_addr);
446+
neigh = batadv_neigh_node_get_or_create(orig_neigh,
447+
if_incoming, neigh_addr);
447448
if (!neigh)
448449
goto orig_free;
449450

net/batman-adv/bat_v_ogm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,8 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,
683683
if (!orig_node)
684684
return;
685685

686-
neigh_node = batadv_neigh_node_new(orig_node, if_incoming,
687-
ethhdr->h_source);
686+
neigh_node = batadv_neigh_node_get_or_create(orig_node, if_incoming,
687+
ethhdr->h_source);
688688
if (!neigh_node)
689689
goto out;
690690

net/batman-adv/originator.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,19 +602,19 @@ batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface,
602602
}
603603

604604
/**
605-
* batadv_neigh_node_new - create and init a new neigh_node object
605+
* batadv_neigh_node_create - create a neigh node object
606606
* @orig_node: originator object representing the neighbour
607607
* @hard_iface: the interface where the neighbour is connected to
608608
* @neigh_addr: the mac address of the neighbour interface
609609
*
610610
* Allocates a new neigh_node object and initialises all the generic fields.
611611
*
612-
* Return: neighbor when found. Othwerwise NULL
612+
* Return: the neighbour node if found or created or NULL otherwise.
613613
*/
614-
struct batadv_neigh_node *
615-
batadv_neigh_node_new(struct batadv_orig_node *orig_node,
616-
struct batadv_hard_iface *hard_iface,
617-
const u8 *neigh_addr)
614+
static struct batadv_neigh_node *
615+
batadv_neigh_node_create(struct batadv_orig_node *orig_node,
616+
struct batadv_hard_iface *hard_iface,
617+
const u8 *neigh_addr)
618618
{
619619
struct batadv_neigh_node *neigh_node;
620620
struct batadv_hardif_neigh_node *hardif_neigh = NULL;
@@ -666,6 +666,29 @@ batadv_neigh_node_new(struct batadv_orig_node *orig_node,
666666
return neigh_node;
667667
}
668668

669+
/**
670+
* batadv_neigh_node_get_or_create - retrieve or create a neigh node object
671+
* @orig_node: originator object representing the neighbour
672+
* @hard_iface: the interface where the neighbour is connected to
673+
* @neigh_addr: the mac address of the neighbour interface
674+
*
675+
* Return: the neighbour node if found or created or NULL otherwise.
676+
*/
677+
struct batadv_neigh_node *
678+
batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,
679+
struct batadv_hard_iface *hard_iface,
680+
const u8 *neigh_addr)
681+
{
682+
struct batadv_neigh_node *neigh_node = NULL;
683+
684+
/* first check without locking to avoid the overhead */
685+
neigh_node = batadv_neigh_node_get(orig_node, hard_iface, neigh_addr);
686+
if (neigh_node)
687+
return neigh_node;
688+
689+
return batadv_neigh_node_create(orig_node, hard_iface, neigh_addr);
690+
}
691+
669692
/**
670693
* batadv_hardif_neigh_seq_print_text - print the single hop neighbour list
671694
* @seq: neighbour table seq_file struct

net/batman-adv/originator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface,
4646
void
4747
batadv_hardif_neigh_put(struct batadv_hardif_neigh_node *hardif_neigh);
4848
struct batadv_neigh_node *
49-
batadv_neigh_node_new(struct batadv_orig_node *orig_node,
50-
struct batadv_hard_iface *hard_iface,
51-
const u8 *neigh_addr);
49+
batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,
50+
struct batadv_hard_iface *hard_iface,
51+
const u8 *neigh_addr);
5252
void batadv_neigh_node_put(struct batadv_neigh_node *neigh_node);
5353
struct batadv_neigh_node *
5454
batadv_orig_router_get(struct batadv_orig_node *orig_node,

0 commit comments

Comments
 (0)