From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) (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 6A7F01EBFE0 for ; Thu, 8 Jan 2026 17:36:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.32.30.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767893795; cv=none; b=lHEzWr3RhoUzAv2mIRGBZMUdUbWHDBk+/zczRK3Hq5hCr0BP9o6wl8BsRwa6bHkyxyvGM1F6Ry9aG68DSftTbxgJXTgbiPOmdFK53ztbZFAPlXJYMnFhbrWimOO5SDSmtXaWJrXINrkfDcB9bV3MeUhmFRSEaFyo2ChF7kKdY0Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767893795; c=relaxed/simple; bh=SwdIP8a7Py0gopqvMmqHHjQ65bTlUgInqqGFa4BbWsE=; h=In-Reply-To:References:From:To:Cc:Subject:MIME-Version: Content-Disposition:Content-Type:Message-Id:Date; b=HkhSq96LE8VM9QaDr+wiEDWKwwcpmmXMRY3RewZFxmxGoQp6SMs2WS75LuTLYnx/SLxeGxXK+R2JaSMCyR+gI0yqhFarhP1yZdqtqpps64pFY3yyf+9QG8QuQ9ECrp4GalnwasGE7fxtYBQk2UK6YjWQFv8e1OAa3H8KdufHiFI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk; spf=none smtp.mailfrom=armlinux.org.uk; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b=sAlyu0tl; arc=none smtp.client-ip=78.32.30.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="sAlyu0tl" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ol51REnBkcONdR3lXu77UErJ4M8e9HJNZBUczbA3AZQ=; b=sAlyu0tl1zdKYunzeoFuRL3z6B Q+77jMCKsB/A+S5QG7PTxvpJsBGckuSZ203KQ0GZnwBB9t7+cInH9DF8lRK9y0Rxkc+kZ/JP19JfA NZpDMjtaEBYvXTf350UlRNZmwbksKHo3JSzQvjGtgU3N8T6ogfa/bc9rlB0f7FkHmZpr2B9HpP8f3 yNcplUrBJJ1HHU1xXNawMfUxcArlWK1KCHrVj+9DJSWzc5tXnxPrVrEAw3QVqeLmEdlO2l7XWhlLR EvolKxEMaWiWV5Tqx4dCr35QRdYZlPcOcWjsTxUqTiVO6swrn5HVW3OWZ80p1201Wzf1zLauyE/70 Ald2jTNg==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:42950 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vdtvt-000000002zQ-2aJ5; Thu, 08 Jan 2026 17:36:25 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.98.2) (envelope-from ) id 1vdtvs-00000002Gtb-2U9G; Thu, 08 Jan 2026 17:36:24 +0000 In-Reply-To: References: From: "Russell King (Oracle)" To: Andrew Lunn , Heiner Kallweit Cc: Alexandre Torgue , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Maxime Chevallier , Maxime Coquelin , netdev@vger.kernel.org, Paolo Abeni Subject: [PATCH net-next v2 4/9] net: stmmac: descs: fix buffer 1 off-by-one error Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Thu, 08 Jan 2026 17:36:24 +0000 norm_set_tx_desc_len_on_ring() incorrectly tests the buffer length, leading to a length of 2048 being squeezed into a bitfield covering bits 10:0 - which results in the buffer 1 size being zero. If this field is zero, buffer 1 is ignored, and thus is equivalent to transmitting a zero length buffer. The path to norm_set_tx_desc_len_on_ring() is only possible when the hardware does not support enhanced descriptors (plat->enh_desc clear) which is dependent on the hardware. Reviewed-by: Maxime Chevallier Signed-off-by: Russell King (Oracle) --- .../net/ethernet/stmicro/stmmac/descs_com.h | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/descs_com.h b/drivers/net/ethernet/stmicro/stmmac/descs_com.h index 40f7f2da9c5e..cb3bfc1571f9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/descs_com.h +++ b/drivers/net/ethernet/stmicro/stmmac/descs_com.h @@ -39,15 +39,19 @@ static inline void enh_desc_end_tx_desc_on_ring(struct dma_desc *p, int end) p->des0 &= cpu_to_le32(~ETDES0_END_RING); } +/* The maximum buffer 1 size is 8KiB - 1. However, we limit to 4KiB. */ static inline void enh_set_tx_desc_len_on_ring(struct dma_desc *p, int len) { - if (unlikely(len > BUF_SIZE_4KiB)) { - p->des1 |= cpu_to_le32((((len - BUF_SIZE_4KiB) + unsigned int buffer1_max_length = BUF_SIZE_4KiB; + + if (unlikely(len > buffer1_max_length)) { + p->des1 |= cpu_to_le32((((len - buffer1_max_length) << ETDES1_BUFFER2_SIZE_SHIFT) - & ETDES1_BUFFER2_SIZE_MASK) | (BUF_SIZE_4KiB + & ETDES1_BUFFER2_SIZE_MASK) | (buffer1_max_length & ETDES1_BUFFER1_SIZE_MASK)); - } else + } else { p->des1 |= cpu_to_le32((len & ETDES1_BUFFER1_SIZE_MASK)); + } } /* Normal descriptors */ @@ -73,16 +77,20 @@ static inline void ndesc_end_tx_desc_on_ring(struct dma_desc *p, int end) p->des1 &= cpu_to_le32(~TDES1_END_RING); } +/* The maximum buffer 1 size is 2KiB - 1, limited by the mask width */ static inline void norm_set_tx_desc_len_on_ring(struct dma_desc *p, int len) { - if (unlikely(len > BUF_SIZE_2KiB)) { - unsigned int buffer1 = (BUF_SIZE_2KiB - 1) - & TDES1_BUFFER1_SIZE_MASK; - p->des1 |= cpu_to_le32((((len - buffer1) + unsigned int buffer1_max_length = BUF_SIZE_2KiB - 1; + + if (unlikely(len > buffer1_max_length)) { + unsigned int buffer1 = buffer1_max_length & + TDES1_BUFFER1_SIZE_MASK; + p->des1 |= cpu_to_le32((((len - buffer1_max_length) << TDES1_BUFFER2_SIZE_SHIFT) & TDES1_BUFFER2_SIZE_MASK) | buffer1); - } else + } else { p->des1 |= cpu_to_le32((len & TDES1_BUFFER1_SIZE_MASK)); + } } /* Specific functions used for Chain mode */ -- 2.47.3