Skip to content

Commit

Permalink
dpaa2-eth: fix memory leak in XDP_REDIRECT
Browse files Browse the repository at this point in the history
[ Upstream commit e12be91 ]

If xdp_do_redirect() fails, the calling driver should handle recycling
or freeing of the page associated with the frame. The dpaa2-eth driver
didn't do either of them and just incremented a counter.
Fix this by trying to DMA map back the page and recycle it or, if the
mapping fails, just free it.

Fixes: d678be1 ("dpaa2-eth: add XDP_REDIRECT support")
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
IoanaCiornei authored and gregkh committed Mar 4, 2021
1 parent 0903d06 commit 7c0425b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
Expand Up @@ -399,10 +399,20 @@ static u32 dpaa2_eth_run_xdp(struct dpaa2_eth_priv *priv,
xdp.frame_sz = DPAA2_ETH_RX_BUF_RAW_SIZE;

err = xdp_do_redirect(priv->net_dev, &xdp, xdp_prog);
if (unlikely(err))
if (unlikely(err)) {
addr = dma_map_page(priv->net_dev->dev.parent,
virt_to_page(vaddr), 0,
priv->rx_buf_size, DMA_BIDIRECTIONAL);
if (unlikely(dma_mapping_error(priv->net_dev->dev.parent, addr))) {
free_pages((unsigned long)vaddr, 0);
} else {
ch->buf_count++;
dpaa2_eth_xdp_release_buf(priv, ch, addr);
}
ch->stats.xdp_drop++;
else
} else {
ch->stats.xdp_redirect++;
}
break;
}

Expand Down

0 comments on commit 7c0425b

Please sign in to comment.