🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16178

[PATCH net-next 08/15] batman-adv: always consume skb in batadv_forw_packet_alloc()

#16178
From: Simon Wunderlich
Date: Sat, 14 Nov 2026 09:15
95 lines
11900 bytes
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
Technical Details
Message-ID: <20261114091556.3336038-9-sw@simonwunderlich.de>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363136-linux-kernel-netdev=dewy.ru
References: <20261114091556.3336038-1-sw@simonwunderlich.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363136-linux-kernel-netdev=dewy.ru
From: sw@simonwunderlich.de (Simon Wunderlich)
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <20261114091556.3336038-9-sw@simonwunderlich.de>
References: <20261114091556.3336038-1-sw@simonwunderlich.de>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1538539"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:5J5FM5fkPiEZdd9PtMIKNwikjpI= sha256:10bYFBRJWQLlBAjE4oehEFhKc2lvvuTwvNKWE6zaNJ8=
	sha1:0KseGrekr/S3fQ2elFJCjdxfz/A= sha256:wGtDsK7x3kojIyUvdN+ZHgrz364y8+JJ6uXkpDi24Ys=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id A1E21114780; Sat, 14 Nov 2026 12:17:06 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=simonwunderlich.de
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 21QMuUBozTrJ;
	Sat, 14 Nov 2026 12:17:03 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-363136-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=simonwunderlich.de
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 7194D114776; Sat, 14 Nov 2026 12:16:55 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 8BCFA603B1; Sat, 14 Nov 2026 09:16:33 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794647771;
	b=IQz2qFLA/gsf0L0zYdNAfc6CaAZxQeApiqZ7WC829aYOIqZ0D4jj7UYVikL13ZN0ydl/
	 Fo4RqWQ8DUTWMV6GYgOG4smlV2YbwyLs/oQNzyRa55D8K0eVsXxshPD1ZOx6ApRcVNeJn
	 K06yqzlSy2jXH3GafvCmZCSYrc4+Cl28Mud0Yq1u2gKrsXPnH4X3dT70ED91Vjqjyh0Vl
	 V7YXJ6eBAZuN/JhndXoKpQUVhtAKyKMm404HstOw3Ick6cvseBAbeUNVhHaEJBXbs9hWZ
	 16Kzd8A0xEiU1r9+rljk5RzkES70gCD7nt0ExPkiK8WuLwHywaxzaEh9pKf/DHGNnUg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794647771;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=I1AmFeLV+vRIYLKijEb73ZThGt5Z4q1iPlXzgCCWvak=;
	b=F0zZ9wTlSKUnGoua5HPD9Q4xkPrqploK8OJjMfPy2KowYhQM0Nu5TgLpvIyW0JfYygHI
	 ZVjA3rOaXac3Vx7c62FoxXYth1kBIJOgMpYJWIA7URGgsAuo0AZLyh02PfD8rUTlERW5F
	 P+952aMGMpuA1V3PlJP5FBnHnrGzLPEoynQ/nMlz5LUIseDSxHr+Ojz8aeTjJ7VY/BVTU
	 Eb9OkOIZdiSmZqxlEZI4I4ULPLb2tXKxeFHkBT6pqIe5Kn+6C6szWumspd0wej42VqsnY
	 N9/W2aa01VepAnt1FtBi0YVqT5zxSHVgLK+JisY1PBTmMILcA3ml6p6zkl7S/OjO9ng==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=xDcF1+s3;
	dmarc=pass header.from=simonwunderlich.de;
	spf=pass smtp.mailfrom=simonwunderlich.de;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F73460A2603;
	Sat, 14 Nov 2026 09:16:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=xDcF1+s3
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=23.88.38.48
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794647770;
	b=kWotzoqhdhiB8kwjtnD93b7JI5cJVmasO/nyli8+NGdsDToWnS95RbUysiXNuFYCCeXr
	 K2mIhn6LpdvhAKWyt0ih0f0lxcKr5N0gNy93GB7oh5dNK+OMEpN5t4FoXmr/cubeLg30V
	 HLFr5eE4JRBYPDIjYB2briwusNQXu3C3TwxMyNveBF4WpF2HuI9pK8Rq4rPAwGfIeBpSz
	 OzqPaGaDKu4IH44a6D0T5gCEVws2pYzFMfoVjuhc5/LANl/Z2hFa+cu3aMuyTNyq2Lxtz
	 oOkoNi9GZYoyPHq9/ftUEQXZUuYrEsGI+hSygsBshUk0yxUiCFWQP2HIFia8z6ehgvQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794647770;
	h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=I1AmFeLV+vRIYLKijEb73ZThGt5Z4q1iPlXzgCCWvak=;
	b=LHtn1cbJeI83w/Dn2pquRhtgoRN3uVSSIC7+ktUGZ2xx/E/oUXV8HwI18YtTmHml+Rj7
	 XuY2MIroLAGoUHgyKaPIRUR1q2FEz60OGFm8Q1xE2bOZwuAwo1SiM3pfn1T+rapnXYLLM
	 3kwi8ju3Z7QDphCQ+scrRJJZyqgWdlGPf7Y2FGjAbgG6osCUG9ryKSqQk+LGv8exG13oT
	 vguR6CrxBncdmUD8ztGWJTKEpOrDfrUE2fQPxwiASIn7R4DUSkGdsAc6OM+PUb87Y2UOf
	 iv9F0MhBtZlk04GB79I6b3Dzt22AmnrroO1TyoHRVXRS2t+/kHNe//aa00Ns2GCXZdg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=simonwunderlich.de;
	spf=pass smtp.mailfrom=simonwunderlich.de;
	dkim=pass header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=xDcF1+s3;
	arc=none smtp.remote-ip=23.88.38.48
X-Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id CF108606A899
	for <netdev@vger.kernel.org>; Sat, 14 Nov 2026 09:16:09 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CF108606A899
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=simonwunderlich.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=simonwunderlich.de
X-Received: from kero.packetmixer.de (unknown [IPv6:2a02:3037:6ed:dd6c:838:344b:3152:2d5e])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by mail.simonwunderlich.de (Postfix) with UTF8SMTPSA id D4770FA25D;
	Sat, 14 Nov 2026 10:16:05 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=simonwunderlich.de;
	s=09092022; t=1794647766;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=I1AmFeLV+vRIYLKijEb73ZThGt5Z4q1iPlXzgCCWvak=;
	b=xDcF1+s3P2oLaMfM2p732UW1Nfi6BCW9Q+vAyUklNfDwMoZ50w6PUU397IlAL7tipjRYFL
	+hF5uF6imTipVXOVcPT7mWmi5OEUPsKGe1tgZszhnlJQvWxgUqEfZws5aeWeWC5t8YeybW
	uz/hn7CoYHCRNxuG3Seki9CMxP8eOcPofrZ5kvufveH8KLpGQTZHi3uo/+872yP0GUfMag
	57XACPAIj+Wg0IrsKEoQnCjwJItpQOUMadq6ASqh4Q224W25usBmU5qRlvxHOhF+LxnmZT
	itV42ij7N0t4d44QQ1AL7Pcq4P4Ub8L8kVixSMmVbzX7mNuuSo4uoFcGxgKP3w==
X-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>
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261114091556.3336038-1-sw@simonwunderlich.de>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list