batadv_tt_global_entry_get_orig() searches the originator list associated to a given tt_global_entry and possibly for the tt_orig_list_entry associated to the orig_node passed as argument.
batadv_tt_global_entry_has_orig() has been modified in order to use the new function and avoid code duplication. Now it also returns bool instead of int.
Signed-off-by: Antonio Quartulli ordex@autistici.org --- translation-table.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/translation-table.c b/translation-table.c index 0f02514..2e90a97 100644 --- a/translation-table.c +++ b/translation-table.c @@ -627,17 +627,17 @@ static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv) spin_unlock_bh(&bat_priv->tt_changes_list_lock); }
-/* find out if an orig_node is already in the list of a tt_global_entry. - * returns 1 if found, 0 otherwise +/* find out if an orig_node is already in the list of a tt_global_entry and + * returns it with an increased refcounter if found, NULL otherwise. + * */ -static bool -batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry, +static struct batadv_tt_orig_list_entry * +batadv_tt_global_entry_get_orig(const struct batadv_tt_global_entry *entry, const struct batadv_orig_node *orig_node) { - struct batadv_tt_orig_list_entry *tmp_orig_entry; + struct batadv_tt_orig_list_entry *tmp_orig_entry, *orig_entry = NULL; const struct hlist_head *head; struct hlist_node *node; - bool found = false;
rcu_read_lock(); head = &entry->orig_list; @@ -647,13 +647,30 @@ batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry, if (!atomic_inc_not_zero(&tmp_orig_entry->refcount)) continue;
- found = true; - batadv_tt_orig_list_entry_free_ref(tmp_orig_entry); - break; + orig_entry = tmp_orig_entry; + break; } rcu_read_unlock();
- return found; + return orig_entry; +} + +/* find out if an orig_node is already in the list of a tt_global_entry. + * returns true if found, false otherwise + */ +static bool +batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry, + const struct batadv_orig_node *orig_node) +{ + bool res = false; + struct batadv_tt_orig_list_entry *orig_entry; + + orig_entry = batadv_tt_global_entry_get_orig(entry, orig_node); + if (orig_entry) { + res = true; + batadv_tt_orig_list_entry_free_ref(orig_entry); + } + return res; }
static void