From: Sven Eckelmann __batadv_tt_local_event() allocates the new change before it searches changes_list for an already queued change of the same client. But the new change is only needed when no such change was found. For ADD+ADD, DEL+DEL, DEL+ADD and ADD+DEL, only the flags of the queued change are replaced and the just allocated change is freed again. A failed allocation therefore also drops events which don't need any memory. The queued change then keeps its outdated flags. Search for the queued change first and only allocate a new one when the client has no queued change. The update of a queued change can then no longer fail. Reported-by: Sashiko Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123171827.3294525-2-sw%40simonwunderlich.de?part=11 Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- net/batman-adv/translation-table.c | 35 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 998c7f285e1d..37ccd5464dda 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -678,22 +678,14 @@ static bool __batadv_tt_local_event(struct batadv_priv *bat_priv, __must_hold(&common->flags_lock) { struct batadv_tt_change_node *tt_change_node; + __be16 vid = htons(common->key.vid); struct batadv_tt_change_node *entry; - struct batadv_tt_change_node *safe; bool del_op_requested; + bool queued = true; size_t changes; lockdep_assert_held(&common->flags_lock); - tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC); - if (!tt_change_node) - return false; - - memset(tt_change_node->change.reserved, 0, - sizeof(tt_change_node->change.reserved)); - ether_addr_copy(tt_change_node->change.addr, common->key.addr); - tt_change_node->change.vid = htons(common->key.vid); - del_op_requested = flags & BATADV_TT_CLIENT_DEL; /* the ROAM flag is only meaningful for the receiver in combination @@ -703,17 +695,14 @@ static bool __batadv_tt_local_event(struct batadv_priv *bat_priv, if (!del_op_requested) flags &= ~BATADV_TT_CLIENT_ROAM; - tt_change_node->change.flags = flags; - /* check for ADD+DEL, DEL+ADD, ADD+ADD or DEL+DEL events */ spin_lock_bh(&bat_priv->tt.changes_list_lock); changes = READ_ONCE(bat_priv->tt.local_changes); - list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list, - list) { + list_for_each_entry(entry, &bat_priv->tt.changes_list, list) { if (!batadv_compare_eth(entry->change.addr, common->key.addr)) continue; - if (entry->change.vid != tt_change_node->change.vid) + if (entry->change.vid != vid) continue; /* the other nodes may know the client with different @@ -723,19 +712,31 @@ static bool __batadv_tt_local_event(struct batadv_priv *bat_priv, */ entry->change.flags = flags; - kmem_cache_free(batadv_tt_change_cache, tt_change_node); goto update_changes; } + tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC); + if (!tt_change_node) { + queued = false; + goto unlock; + } + + memset(tt_change_node->change.reserved, 0, + sizeof(tt_change_node->change.reserved)); + ether_addr_copy(tt_change_node->change.addr, common->key.addr); + tt_change_node->change.vid = vid; + tt_change_node->change.flags = flags; + /* track the change in the OGMinterval list */ list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list); changes++; update_changes: WRITE_ONCE(bat_priv->tt.local_changes, changes); +unlock: spin_unlock_bh(&bat_priv->tt.changes_list_lock); - return true; + return queued; } /** -- 2.47.3