Skip to content

Commit

Permalink
net/nfp: fix memory leak in Rx
Browse files Browse the repository at this point in the history
[ upstream commit bb340f56fcb7bac9ec04c1c1ca7a2a4f3012c848 ]

nfp_net_recv_pkts() should not return a value that less than 0 and the
inappropriate return value in receive loop also causes the memory leak.
Modify code to avoid return a value less than 0. Furthermore, When
nfp_net_recv_pkts() break out from the receive loop because of packet
problems, a rte_mbuf will not be freed and it will cause memory leak.
Free the rte_mbuf before break out.

Fixes: b812daa ("nfp: add Rx and Tx")

Signed-off-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@corigine.com>
  • Loading branch information
wulong2022 authored and cpaelzer committed Nov 18, 2022
1 parent 1523efa commit ad41d00
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/net/nfp/nfp_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -2035,20 +2035,20 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
struct rte_mbuf *new_mb;
uint16_t nb_hold;
uint64_t dma_addr;
int avail;
uint16_t avail;

avail = 0;
rxq = rx_queue;
if (unlikely(rxq == NULL)) {
/*
* DPDK just checks the queue is lower than max queues
* enabled. But the queue needs to be configured
*/
RTE_LOG_DP(ERR, PMD, "RX Bad queue\n");
return -EINVAL;
return avail;
}

hw = rxq->hw;
avail = 0;
nb_hold = 0;

while (avail < nb_pkts) {
Expand Down Expand Up @@ -2114,7 +2114,8 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
hw->rx_offset,
rxq->mbuf_size - hw->rx_offset,
mb->data_len);
return -EINVAL;
rte_pktmbuf_free(mb);
break;
}

/* Filling the received mbuf with packet info */
Expand Down

0 comments on commit ad41d00

Please sign in to comment.