From nobody Thu Apr 2 14:07:33 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 770E8374171 for ; Sat, 28 Mar 2026 09:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774689880; cv=none; b=shcRrhNKVLMJ6OGcxxpbaaKZI/3RRoLgdwwqIwSe1GD0vavpvGtqm83aW5Rv6TAv8+BadIKFXY42q2hbYGYfqp57JwjT/Tiv78e+VVK3+KBntkni2ODHQ9k1pk7tCYQYkQJ3GCLEZszDyMsUc3oLMeOO2ziL+A7W1K4wBx4PhoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774689880; c=relaxed/simple; bh=NzyrU5zPm0aE7B5Xv/X9tBXqZrUh/Ux/aTbQVo2C6kI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QjCCN38xbEjo82QmGFtj/ahlrwJigVD41kM8tKL8QzNJOf4Lot9WyHFZCAdo7dr83yZ04+abY/tCVjwCXBZ7rNMWMQowgBmtuBhRP1cFcYcsvml+QwaHjEl3XBOteJlHvCgKq9GkjIRWi3A32CcS5szTMM0aCcM+Jzg0Bh03fJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=OmM2nbuG; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="OmM2nbuG" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1774689877; 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; bh=1cmrkz5W6UykUZpniAtrjuFU7d70RC0nIF5M0anlmZQ=; b=OmM2nbuGpixhtFvCZ4RytYBhDEgmm1oxpd+WnC4RS6xOPA0/+4ZCII/P0axwaARlXJsPDc wRMsiLwoCGDFokdEc5/PPsW7Fbl28kFx0v4e5qzZpqsyFfngQ8J900Fom0QUBa73Y9SU1L Sr5bNojQucHT/eiDGEkkSScAr4dyBdU= From: Yufan Chen To: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yufan.chen@linux.dev, Yufan Chen Subject: [PATCH] net/ftgmac100: fix ring allocation unwind leaks on open failure Date: Sat, 28 Mar 2026 17:24:28 +0800 Message-ID: <20260328092428.75430-1-yufan.chen@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2882; i=ericterminal@gmail.com; h=from:subject; bh=U/Fkrvdf6DiDU9bwx1OrsOmxztxIWo5PjRRPWmVxAlk=; b=owGbwMvMwCXWM/dCzeS3H+sZT6slMWQen8Pk+CesaLntKVc1/xlfphsybC2+2y50rXHn5ZPv2 DQT1Q986pjIwiDGxWAppshy9/++ublet+Zc5z6cCzOHlQlkiLRIAwMQsDDw5SbmlRrpGOmZahvq GRrpGOgYM3BxCsBUv9rJ8FcwzmSXh/CT5C7GJ9uLdF/Jp+nH7Kgy89qZKlQStz/s+nRGhokS+k2 pJmf4Q+2P3wnXvmBSZ3R/fZ6fw/oFJrJSb1lyeQA= X-Developer-Key: i=ericterminal@gmail.com; a=openpgp; fpr=DDFFBE9D6D4ADA9CD70BC36D8C9DD07C93EDF17F Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Yufan Chen ftgmac100_alloc_rings() allocated rx_skbs, tx_skbs, rxdes, txdes, and rx_sc= ratch in stages but returned directly on any intermediate allocation failur= e. This left previously allocated objects unreleased and could accumulate l= eaks across repeated ifup retries under memory pressure. Switch ftgmac100_alloc_rings() to a centralized goto-based unwind path that= calls ftgmac100_free_rings() on failure so partially allocated ring resour= ces are always released before returning -ENOMEM. Also clear rx_skbs, tx_skbs, and rx_scratch pointers in ftgmac100_free_ring= s() after freeing. This prevents stale pointers from being reused during la= ter retry failures and keeps ring teardown idempotent. Signed-off-by: Yufan Chen --- drivers/net/ethernet/faraday/ftgmac100.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/etherne= t/faraday/ftgmac100.c index 1e91e79c8..147300e60 100644 --- a/drivers/net/ethernet/faraday/ftgmac100.c +++ b/drivers/net/ethernet/faraday/ftgmac100.c @@ -946,7 +946,9 @@ static void ftgmac100_free_rings(struct ftgmac100 *priv) { /* Free skb arrays */ kfree(priv->rx_skbs); + priv->rx_skbs =3D NULL; kfree(priv->tx_skbs); + priv->tx_skbs =3D NULL; =20 /* Free descriptors */ if (priv->rxdes) @@ -965,31 +967,34 @@ static void ftgmac100_free_rings(struct ftgmac100 *pr= iv) if (priv->rx_scratch) dma_free_coherent(priv->dev, RX_BUF_SIZE, priv->rx_scratch, priv->rx_scratch_dma); + priv->rx_scratch =3D NULL; } =20 static int ftgmac100_alloc_rings(struct ftgmac100 *priv) { + int err =3D -ENOMEM; + /* Allocate skb arrays */ priv->rx_skbs =3D kcalloc(MAX_RX_QUEUE_ENTRIES, sizeof(void *), GFP_KERNEL); if (!priv->rx_skbs) - return -ENOMEM; + goto out; priv->tx_skbs =3D kcalloc(MAX_TX_QUEUE_ENTRIES, sizeof(void *), GFP_KERNEL); if (!priv->tx_skbs) - return -ENOMEM; + goto out; =20 /* Allocate descriptors */ priv->rxdes =3D dma_alloc_coherent(priv->dev, MAX_RX_QUEUE_ENTRIES * sizeof(struct ftgmac100_rxdes), &priv->rxdes_dma, GFP_KERNEL); if (!priv->rxdes) - return -ENOMEM; + goto out; priv->txdes =3D dma_alloc_coherent(priv->dev, MAX_TX_QUEUE_ENTRIES * sizeof(struct ftgmac100_txdes), &priv->txdes_dma, GFP_KERNEL); if (!priv->txdes) - return -ENOMEM; + goto out; =20 /* Allocate scratch packet buffer */ priv->rx_scratch =3D dma_alloc_coherent(priv->dev, @@ -997,9 +1002,13 @@ static int ftgmac100_alloc_rings(struct ftgmac100 *pr= iv) &priv->rx_scratch_dma, GFP_KERNEL); if (!priv->rx_scratch) - return -ENOMEM; + goto out; =20 return 0; + +out: + ftgmac100_free_rings(priv); + return err; } =20 static void ftgmac100_init_rings(struct ftgmac100 *priv) --=20 2.47.3