Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Simon Wunderlich
Sat, 14 Nov 2026 09:15
[PATCH net-next 05/15] batman-adv: originator: pass explicit key to orig_hash
Author: Simon Wunderlich
Date: Sat, 14 Nov 2026 09:15
Date: Sat, 14 Nov 2026 09:15
121 lines
13662 bytes
13662 bytes
From: Sven Eckelmann <sven@narfation.org>
The key of the orig_hash is the originator address. But batadv_hash_add()
was given the whole orig_node, while batadv_orig_hash_find() is given the
bare address, and batadv_compare_orig() and the lookup compare the
orig_node pointer itself against the address. This only works because
orig is the first member of struct batadv_orig_node.
Pass orig_node->orig as key to batadv_hash_add(), compare explicitly
against orig_node->orig in batadv_compare_orig(), use it for the lookup,
and let batadv_orig_hash_find() take a const u8 * address instead of an
untyped pointer.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
net/batman-adv/bat_iv_ogm.c | 2 +-
net/batman-adv/bat_v_ogm.c | 2 +-
net/batman-adv/originator.c | 19 ++++++++++---------
net/batman-adv/originator.h | 2 +-
4 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 0b2134a8f963a..376c0f80bcee9 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -155,7 +155,7 @@ batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)
kref_get(&orig_node->refcount);
hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
- batadv_choose_orig, orig_node,
+ batadv_choose_orig, orig_node->orig,
&orig_node->hash_entry);
if (hash_added != 0)
goto free_orig_node_hash;
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index cf3c1d22761b9..4abb4c871e8c5 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -68,7 +68,7 @@ struct batadv_orig_node *batadv_v_ogm_orig_get(struct batadv_priv *bat_priv,
kref_get(&orig_node->refcount);
hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
- batadv_choose_orig, orig_node,
+ batadv_choose_orig, orig_node->orig,
&orig_node->hash_entry);
if (hash_added != 0) {
/* remove refcnt for newly created orig_node and hash entry */
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 1ac3e0ad66c79..391d97bc938b9 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -45,12 +45,12 @@ static struct lock_class_key batadv_orig_hash_lock_class_key;
/**
* batadv_orig_hash_find() - Find and return originator from orig_hash
* @bat_priv: the bat priv with all the mesh interface information
- * @data: mac address of the originator
+ * @addr: mac address of the originator
*
* Return: orig_node (with increased refcnt), NULL on errors
*/
struct batadv_orig_node *
-batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data)
+batadv_orig_hash_find(struct batadv_priv *bat_priv, const u8 *addr)
{
struct batadv_hashtable *hash = bat_priv->orig_hash;
struct batadv_orig_node *orig_node_tmp = NULL;
@@ -61,12 +61,12 @@ batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data)
if (!hash)
return NULL;
- index = batadv_choose_orig(data, hash->size);
+ index = batadv_choose_orig(addr, hash->size);
head = &hash->table[index];
rcu_read_lock();
hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
- if (!batadv_compare_eth(orig_node, data))
+ if (!batadv_compare_orig(&orig_node->hash_entry, addr))
continue;
if (!kref_get_unless_zero(&orig_node->refcount))
@@ -85,16 +85,17 @@ static void batadv_purge_orig(struct work_struct *work);
/**
* batadv_compare_orig() - comparing function used in the originator hash table
* @node: node in the local table
- * @data2: second object to compare the node to
+ * @data2: mac address of the originator to compare the node to
*
- * Return: true if they are the same originator
+ * Return: true if the node is the originator with the given address
*/
bool batadv_compare_orig(const struct hlist_node *node, const void *data2)
{
- const void *data1 = container_of(node, struct batadv_orig_node,
- hash_entry);
+ const struct batadv_orig_node *orig_node;
- return batadv_compare_eth(data1, data2);
+ orig_node = container_of(node, struct batadv_orig_node, hash_entry);
+
+ return batadv_compare_eth(orig_node->orig, data2);
}
/**
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index fabfc3e67c6eb..dff729ecf2df1 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -83,7 +83,7 @@ static inline u32 batadv_choose_orig(const void *data, u32 size)
}
struct batadv_orig_node *
-batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data);
+batadv_orig_hash_find(struct batadv_priv *bat_priv, const u8 *addr);
/**
* batadv_orig_node_vlan_put() - decrement the refcounter and possibly release
--
2.47.3
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads