Article View: linux.kernel.netdev
Article #6997[PATCH net-next v6 3/4] net: stmmac: release descriptor resources through priv->dma_conf on open failure
From: Ding Hui
Date: Sat, 24 Oct 2026 07:13
Date: Sat, 24 Oct 2026 07:13
92 lines
11681 bytes
11681 bytes
From: Ding Hui <dinghui@lixiang.com>
__stmmac_open() copies the temporary dma_conf passed by its callers
into the long-lived priv->dma_conf before setting up the hardware.
When the open fails after this copy, the descriptor resources now
belong to priv->dma_conf, but the error path returns without
releasing them and leaves stale pointers behind. The callers then
free the already-copied resources through the temporary dma_conf,
which aliases priv->dma_conf after the memcpy.
Fix this by making __stmmac_open() release the descriptor resources
through priv->dma_conf on failure. Callers of __stmmac_open() only
need to free the temporary dma_conf container in that case, while
failures before the call (PHY setup, serdes power up) still release
the resources through the temporary dma_conf via the existing
err_dma_resources path in stmmac_open().
stmmac_open() no longer jumps to the serdes label chain after
__stmmac_open() fails, as that chain would double-release the
descriptor resources and double-put the runtime PM reference, so the
cleanup is done inline instead.
The resource release is merged with the error unwinding that stops
the DMA engines and the MAC: failures after the hardware setup
first stop the DMA engines and the MAC, and then fall through to
the common init_error label that releases the descriptor resources,
while a stmmac_hw_setup() failure jumps to init_error directly as
the engines were never started.
Signed-off-by: Ding Hui <dinghui@lixiang.com>
---
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a8401b04d79f..b093119e752f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4246,7 +4246,7 @@ static int __stmmac_open(struct net_device *dev,
ret = stmmac_hw_setup(dev);
if (ret < 0) {
netdev_err(priv->dev, "%s: Hw setup failed\n", __func__);
- return ret;
+ goto init_error;
}
ret = stmmac_setup_ptp(priv);
@@ -4282,6 +4282,8 @@ static int __stmmac_open(struct net_device *dev,
stmmac_stop_all_dma(priv);
stmmac_mac_set(priv, priv->ioaddr, false);
+init_error:
+ free_dma_desc_resources(priv, &priv->dma_conf);
return ret;
}
@@ -4314,8 +4316,13 @@ static int stmmac_open(struct net_device *dev)
}
ret = __stmmac_open(dev, dma_conf);
- if (ret)
- goto err_serdes;
+ if (ret) {
+ stmmac_legacy_serdes_power_down(priv);
+ phylink_disconnect_phy(priv->phylink);
+ pm_runtime_put(priv->device);
+ kfree(dma_conf);
+ return ret;
+ }
kfree(dma_conf);
@@ -4324,8 +4331,6 @@ static int stmmac_open(struct net_device *dev)
return ret;
-err_serdes:
- stmmac_legacy_serdes_power_down(priv);
err_disconnect_phy:
phylink_disconnect_phy(priv->phylink);
err_runtime_pm:
@@ -6343,7 +6348,6 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
ret = __stmmac_open(dev, dma_conf);
if (ret) {
- free_dma_desc_resources(priv, dma_conf);
kfree(dma_conf);
netdev_err(priv->dev, "failed reopening the interface after MTU change\n");
return ret;
--
2.34.1
Technical Details
Message-ID:
<20261024071319.875921-4-dinghui1111@163.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351317-linux-kernel-netdev=dewy.ruReferences:
<20261024071319.875921-1-dinghui1111@163.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351317-linux-kernel-netdev=dewy.ru From: dinghui1111@163.com (Ding Hui) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v6 3/4] net: stmmac: release descriptor resources through priv->dma_conf on open failure Date: Sat, 24 Oct 2026 15:13:17 +0800 Organization: Usenet Network Message-ID: <20261024071319.875921-4-dinghui1111@163.com> References: <20261024071319.875921-1-dinghui1111@163.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="707279"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:a+wvo0QHUkjezN/JlrGHcZ7QVIM= sha256:iVe/r7oB5/0Xyir7fT4m0jqNIPpEduzbzXhpySEhQ8I= sha1:6XwhYvj/MZE2jt+/jsKPnKb2qcA= sha256:lb2cfsG8ouWMYNBlWjhTmpoIQNOIgoAXYsnK48fO59I= 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 EA6D01115F7; Sat, 24 Oct 2026 10:17:12 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.047 X-Spam-Status: No, score=-3.047 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, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=163.com 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 TRyKHFMzjzqL; Sat, 24 Oct 2026 10:17:09 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-351317-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=163.com X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 35A4C1115D2; Sat, 24 Oct 2026 10:17:00 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 728C72BD9B; Sat, 24 Oct 2026 07:15:42 +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=1792826129; b=j9xeJbtVVy2YS+7oK63ksUsuwTARW7/EtbBkEVcgtU8NOQK5nS4wER7AWBSYWaCGwf0p AWHBZ4EcyeWTb1Az0Ga6knxbZfqYzdDdmVC4nQWmbPJqYHAFy38NuDuj1TqTt4FPTfdY2 9zymhCc17R4aPVlZ6AK9VNEe9154NcUbI1C+84RCfes59tjsHwt83I5HGUL3vJl5X/iGp vyEdwWK7F5l/uam/F+hrDjIkY+1QfI1kPwRNwHXq7Sly4A2YLJsFnq+gv3JTjdi72xjyT KhZ9uOOHqptsDS4+5lcQcO9K6AUXQzJGiNpveE60hplG/DpObM3CLphTPHfNgHiNwpA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792826129; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received: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:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=bwf4WuvizE5NsoXFdTXjETdYXegFLEL7OxtAZ9dSDUQ=; b=uc+8ljiL58+DEySBvJ0sTx7kULK75OsIXLzGu8sOg/wZkCu3rZING+QTLKhIKmZbWlmO lqXvSYQz4i99W5GGeS7nPrVpV5r1S5I2gU9Kgdsuvbyp3cisPy12xIfVt9EdbBNTVoqOe ECIN6kSHR4zGd3M54B5l4UJpwRY57ZaXj+QDpW3mJxpMsaWQZ+goagKbM6OzHoG29cQ02 oaIQOJyBIDUB3EPdPG7MyWPkRGDlBcZoGDqmBKBM1OfE83nuJ90WJHETF5Kos/ApyBnhg b4XPk8ayvwOCmfiKCE5plBiamrgqbtDqKHUuwKTKf3HuG2T0kWpk15Odu5vixwajf5g== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b="JtEYmq/F"; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; 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 7EE3560A260C; Sat, 24 Oct 2026 07:15:29 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=JtEYmq/F X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.5 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792826123; b=V4EDQVz5jY1t2LpicjLY/NLLyUli1hQQfnITGciL52bCXG9+dgYoqZjeOe5JWIw4Yzqw IngmU/WYyRlbO7JzHrj5Memo3NigjPrOqYJAb7I4BWuOLTBLpKndKH+Pqfx/5ZEXmk5IT NqvpT4KnVG392k1Q1eeEPNCivZilZWQEOIlmFRRLVkGcVUcVvCj8B8X3D0c+46mQiIN0U 2koRu3hZLZFFDXX7lt2WlwXTHMlPNwmSo0FBJ4oC9yNrh9MR1yh34Czk4WC2PyppYHrfc p3pnabtkhLfoAg8ERX/zlEhLBHFqfpO1Pr050AQjHCdUEjFmlI3zfzVmPiTGmRd91qQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792826123; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=bwf4WuvizE5NsoXFdTXjETdYXegFLEL7OxtAZ9dSDUQ=; b=h/y8IHnsu4t/bXyy5y8+U2VxRBN3BVbc8qUWnFlEdmvyYmAQfS0NC3Efx8dGa1DbdEqQ u0+cxdDtdahHWgScm3Cr6ZwWwreQgl8OrzS0sWO/FmxidBXDgvrvWat0ZOIw+bmNxGjX8 Ei7DwNj2SIYRtewjXNCleutN4ih0JEuPpGqXzjZjrqZaM2PRj4SE9PKjJA1YlHFuTe8h3 bSIsb5KN71+z1L/hi7VWxCun6yeVoqPOi1DNnhXdfP+RDs3YoEzkpWbhIzcGezE0bDlK+ 4yvnmScPbRn+mQ4uIz4Fnxm6crHsOjSbWlz5skW8sX13VZO+Dyf2WPUaJolgXocJYLQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b="JtEYmq/F"; arc=none smtp.remote-ip=220.197.31.5 X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 ESMTPS id 5B228606A31E; Sat, 24 Oct 2026 07:15:21 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B228606A31E X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=bw f4WuvizE5NsoXFdTXjETdYXegFLEL7OxtAZ9dSDUQ=; b=JtEYmq/FkqR93/oeFm 90LoplFrYwebjoUWMJzB9ZmYDocDPplo3FBqlySLPiiDtvESuVFPAKAQOsbiXFaS P7tM99kXQghzPaK91qd4UQTyDIT7VxwWivzLaNQ6GxaWaDIM8jgfApKIMZq3DF93 8VgUl8RA4CZnMLkwC2FlRjvag= X-Received: from 4CV529F122.company.local (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wD310ySWtxq_y0rCg--.41124S5; Sat, 24 Oct 2026 15:13:42 +0800 (CST) X-Cc: dinghui@lixiang.com, xiasanbo@lixiang.com, yangchen11@lixiang.com, liuxuanjun@lixiang.com X-Mailer: git-send-email 2.34.1 X-In-Reply-To: <20261024071319.875921-1-dinghui1111@163.com> 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 X-CM-TRANSID: _____wD310ySWtxq_y0rCg--.41124S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxGry7Cr45ur1kZw1kZryUAwb_yoW5uFykpr Wxua98JryDArn3Jws8Ar4UXFyFyaySyF45Gw1xJ3yfAay5WrZIqrWYqryjvF1UCFWFvw1S qrWYyryUC3WDXF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bjQ6XUUUUU= X-CM-SenderInfo: pglqwx1xlriiqr6rljoofrz/xtbC8waRvWrcWqZjZwAA3X