From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6A5BE1A5BB7; Wed, 5 Mar 2025 18:11:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741198260; cv=none; b=klTcuunqAceNw2SjjLG1P1/N+LahTq24AXpjBP3tbnr/jtA+XMb3k/GBmg5CP34ieP9nvIyHwVa5zVcOPx6kk4Wm7V/JxWGVXVGb6p39pgugjYbQp3JWCbzFiEN2G3Fzy1sgNUbNlTORrlwcwDrufrZTJJyiHpVMAFFOf640xzA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741198260; c=relaxed/simple; bh=N4eCURzchOLq7p9MRWji8wnEYKkRn0I338IXUyIapfA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OkPzR/+vSGTzkcLJQdPETDXFsr6pjMldAopnjyci585oZMwhlIUmTQkAUVRgWTgA6RKSL4SojUMfDWZVASDsgP3JonBB2Owuby+pL8LRojJw2eqMuz19yCNo3nInpSkuweOKqgH1kV+yYfzcUf2E/64/gup1A9WEseq96Yf1FC0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eKOhrPDb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="eKOhrPDb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3943C4CEE0; Wed, 5 Mar 2025 18:10:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741198260; bh=N4eCURzchOLq7p9MRWji8wnEYKkRn0I338IXUyIapfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eKOhrPDbLHfAMo//aZzK4Wru8UnoNhK6OXbql/2TZjLqmKEIdeCxC4DV8hpavhUxj nM8RctWjTBbIKlB/rx5w1FsWWjzTfDWr3zihmr66J8KCYQtBGIkdJ2dFjf1SIbypXO WEdABT7uX2AgljZxmZkbRWTgEZPjY9D/P/dcj80Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vladimir Oltean , Michal Swiatkowski , Wei Fang , Claudiu Manoil , Jakub Kicinski Subject: [PATCH 6.12 111/150] net: enetc: fix the off-by-one issue in enetc_map_tx_buffs() Date: Wed, 5 Mar 2025 18:49:00 +0100 Message-ID: <20250305174508.274644768@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250305174503.801402104@linuxfoundation.org> References: <20250305174503.801402104@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wei Fang commit 39ab773e4c120f7f98d759415ccc2aca706bbc10 upstream. When a DMA mapping error occurs while processing skb frags, it will free one more tx_swbd than expected, so fix this off-by-one issue. Fixes: d4fd0404c1c9 ("enetc: Introduce basic PF and VF ENETC ethernet drivers") Cc: stable@vger.kernel.org Suggested-by: Vladimir Oltean Suggested-by: Michal Swiatkowski Signed-off-by: Wei Fang Reviewed-by: Vladimir Oltean Reviewed-by: Claudiu Manoil Link: https://patch.msgid.link/20250224111251.1061098-2-wei.fang@nxp.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/freescale/enetc/enetc.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -145,6 +145,24 @@ static int enetc_ptp_parse(struct sk_buf return 0; } +/** + * enetc_unwind_tx_frame() - Unwind the DMA mappings of a multi-buffer Tx frame + * @tx_ring: Pointer to the Tx ring on which the buffer descriptors are located + * @count: Number of Tx buffer descriptors which need to be unmapped + * @i: Index of the last successfully mapped Tx buffer descriptor + */ +static void enetc_unwind_tx_frame(struct enetc_bdr *tx_ring, int count, int i) +{ + while (count--) { + struct enetc_tx_swbd *tx_swbd = &tx_ring->tx_swbd[i]; + + enetc_free_tx_frame(tx_ring, tx_swbd); + if (i == 0) + i = tx_ring->bd_count; + i--; + } +} + static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb) { bool do_vlan, do_onestep_tstamp = false, do_twostep_tstamp = false; @@ -328,13 +346,7 @@ static int enetc_map_tx_buffs(struct ene dma_err: dev_err(tx_ring->dev, "DMA map error"); - do { - tx_swbd = &tx_ring->tx_swbd[i]; - enetc_free_tx_frame(tx_ring, tx_swbd); - if (i == 0) - i = tx_ring->bd_count; - i--; - } while (count--); + enetc_unwind_tx_frame(tx_ring, count, i); return 0; }