]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
stmmac: xsk: fix negative overflow of budget in zerocopy mode
authorJason Xing <kernelxing@tencent.com>
Wed, 23 Jul 2025 14:23:26 +0000 (22:23 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 26 Jul 2025 18:23:08 +0000 (11:23 -0700)
A negative overflow can happen when the budget number of descs are
consumed. as long as the budget is decreased to zero, it will again go
into while (budget-- > 0) statement and get decreased by one, so the
overflow issue can happen. It will lead to returning true whereas the
expected value should be false.

In this case where all the budget is used up, it means zc function
should return false to let the poll run again because normally we
might have more data to process. Without this patch, zc function would
return true instead.

Fixes: 132c32ee5bc0 ("net: stmmac: Add TX via XDP zero-copy socket")
Signed-off-by: Jason Xing <kernelxing@tencent.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Link: https://patch.msgid.link/20250723142327.85187-2-kerneljasonxing@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index b948df1bff9a84966e6e7a43831585b81ca3748a..e0fb06af1f940d07d468f1bab591dea44faf143a 100644 (file)
@@ -2596,7 +2596,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
 
        budget = min(budget, stmmac_tx_avail(priv, queue));
 
-       while (budget-- > 0) {
+       for (; budget > 0; budget--) {
                struct stmmac_metadata_request meta_req;
                struct xsk_tx_metadata *meta = NULL;
                dma_addr_t dma_addr;