lan966x_xdp_xmit() counts a frame as transmitted when lan966x_fdma_xmit_xdpf() returns 0, and its caller only returns the frames that were not counted. Before this patch, lan966x_fdma_xmit_xdpf() returns NETDEV_TX_OK, which is 0, when an xdp_frame has less headroom than the IFH or when its DMA mapping fails, without queueing the frame. The frame is then counted as transmitted and never freed. An xdp_frame can have less headroom than the IFH when an XDP program grows the head of a frame with bpf_xdp_adjust_head() before redirecting it to a lan966x port. Return -EINVAL and -ENOMEM in these cases, so that lan966x_xdp_xmit() stops and the frames that were not queued are returned to the caller. Found by an AI code review agent. Reproduced on a lan9668 board with an XDP program that grows the head of each frame and redirects it to another lan966x port. With the fix the frames are returned to the caller. Fixes: a825b611c7c1 ("net: lan966x: Add support for XDP_REDIRECT") Signed-off-by: Daniel Machon --- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c index 1fbe910c5ec38..f1b6638d5668d 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -636,7 +636,7 @@ int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len) xdpf = ptr; if (xdpf->headroom < IFH_LEN_BYTES) { - ret = NETDEV_TX_OK; + ret = -EINVAL; goto out; } @@ -650,7 +650,7 @@ int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len) xdpf->len + IFH_LEN_BYTES, DMA_TO_DEVICE); if (dma_mapping_error(lan966x->dma_dev, dma_addr)) { - ret = NETDEV_TX_OK; + ret = -ENOMEM; goto out; } --- base-commit: af6737b9066832a2017c281159950ba92385ce00 change-id: 20261123-lan966x-xdp-xmit-errors-ed70befc70de Best regards, -- Daniel Machon