From: Simon Wunderlich <sw@simonwunderlich.de>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
b.a.t.m.a.n@lists.open-mesh.org,
Sven Eckelmann <sven@narfation.org>,
Simon Wunderlich <sw@simonwunderlich.de>
Subject: [PATCH net-next 08/15] batman-adv: always consume skb in batadv_forw_packet_alloc()
Date: Sat, 14 Nov 2026 10:15:49 +0100 [thread overview]
Message-ID: <20261114091556.3336038-9-sw@simonwunderlich.de> (raw)
In-Reply-To: <20261114091556.3336038-1-sw@simonwunderlich.de>
From: Sven Eckelmann <sven@narfation.org>
On success, batadv_forw_packet_alloc() stores the skb in the new
forw_packet, and batadv_forw_packet_free() frees it later. On failure
(queue full or out of memory), the skb was left for the caller to free.
Whether the caller still owned the skb therefore depended on the return
value.
Free the skb inside batadv_forw_packet_alloc() on failure, so the skb is
always consumed, and drop the kfree_skb() calls from both callers.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
net/batman-adv/bat_iv_ogm.c | 4 +---
net/batman-adv/send.c | 14 +++++++-------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 376c0f80bcee9..5faac7419e43a 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -647,10 +647,8 @@ static bool batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
queue_left = own_packet ? NULL : &bat_priv->batman_queue_left;
forw_packet_aggr = batadv_forw_packet_alloc(if_incoming, if_outgoing,
queue_left, bat_priv, skb);
- if (!forw_packet_aggr) {
- kfree_skb(skb);
+ if (!forw_packet_aggr)
return false;
- }
forw_packet_aggr->skb->priority = TC_PRIO_CONTROL;
skb_reserve(forw_packet_aggr->skb, ETH_HLEN);
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 929b6dd34c107..6672f81798e91 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -481,6 +481,9 @@ void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet,
* (optional) if_incoming, if_outgoing and queue_left. If queue_left
* is NULL then bat_priv is optional, too.
*
+ * The skb is always consumed: on success, it is owned by the returned
+ * forwarding packet, on failure it is freed.
+ *
* Return: An allocated forwarding packet on success, NULL otherwise.
*/
struct batadv_forw_packet *
@@ -505,6 +508,7 @@ batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"%s queue is full\n", qname);
+ kfree_skb(skb);
return NULL;
}
@@ -532,6 +536,7 @@ batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
if (queue_left)
atomic_inc(queue_left);
+ kfree_skb(skb);
return NULL;
}
@@ -753,13 +758,13 @@ static int batadv_forw_bcast_packet_to_list(struct batadv_priv *bat_priv,
newskb = skb_clone(skb, GFP_ATOMIC);
if (!newskb)
- goto err;
+ return NETDEV_TX_BUSY;
forw_packet = batadv_forw_packet_alloc(if_in, if_out,
&bat_priv->bcast_queue_left,
bat_priv, newskb);
if (!forw_packet)
- goto err_packet_free;
+ return NETDEV_TX_BUSY;
forw_packet->own = own_packet;
@@ -770,11 +775,6 @@ static int batadv_forw_bcast_packet_to_list(struct batadv_priv *bat_priv,
batadv_forw_packet_bcast_queue(bat_priv, forw_packet, send_time);
return NETDEV_TX_OK;
-
-err_packet_free:
- kfree_skb(newskb);
-err:
- return NETDEV_TX_BUSY;
}
/**
--
2.47.3
next prev parent reply other threads:[~2026-11-14 9:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 9:15 [PATCH net-next 00/15] pull request for net-next: batman-adv 2026-11-14 Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 01/15] batman-adv: bla: use dedicated key type for claim hash Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 02/15] batman-adv: bla: use dedicated key type for backbone gateway hash Simon Wunderlich
[not found] ` <sashiko-outbox-215348@kernel.org>
2026-11-15 9:37 ` Sven Eckelmann
2026-11-14 9:15 ` [PATCH net-next 03/15] batman-adv: dat: use dedicated key type for DAT hash Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 04/15] batman-adv: tt: use dedicated key type for hashes Simon Wunderlich
[not found] ` <sashiko-outbox-215350@kernel.org>
2026-11-15 9:42 ` Sven Eckelmann
2026-11-14 9:15 ` [PATCH net-next 05/15] batman-adv: originator: pass explicit key to orig_hash Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 06/15] batman-adv: hash: document key argument of hash operations Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 07/15] batman-adv: never consume skb in BLA rx and DAT incoming snooping Simon Wunderlich
[not found] ` <sashiko-outbox-215353@kernel.org>
2026-11-15 9:44 ` Sven Eckelmann
2026-11-14 9:15 ` Simon Wunderlich [this message]
2026-11-14 9:15 ` [PATCH net-next 09/15] batman-adv: split fragment forwarding into lookup and forward Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 10/15] batman-adv: document skb ownership of always-consuming functions Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 11/15] batman-adv: tt: increase hash generation when purging clients Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 12/15] batman-adv: dat: increase hash generation when purging entries Simon Wunderlich
[not found] ` <sashiko-outbox-215358@kernel.org>
2026-11-15 9:50 ` Sven Eckelmann
2026-11-14 9:15 ` [PATCH net-next 13/15] batman-adv: bla: " Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 14/15] batman-adv: increase orig hash generation when purging originators Simon Wunderlich
2026-11-14 9:15 ` [PATCH net-next 15/15] batman-adv: annotate functions returning objects with __must_check Simon Wunderlich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261114091556.3336038-9-sw@simonwunderlich.de \
--to=sw@simonwunderlich.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sven@narfation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox