patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH 19.11] net/nfp: fix memory leak in Rx
@ 2022-11-17 14:27 Niklas Söderlund
  2022-11-18  7:01 ` Christian Ehrhardt
  0 siblings, 1 reply; 2+ messages in thread
From: Niklas Söderlund @ 2022-11-17 14:27 UTC (permalink / raw)
  To: stable; +Cc: oss-drivers, Long Wu, Chaoyong He, Niklas Söderlund

From: Long Wu <long.wu@corigine.com>

[ 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: b812daadad0d ("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>
---
 drivers/net/nfp/nfp_net.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 76222ca5affd..f2fdff56636c 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -2035,8 +2035,9 @@ 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)) {
 		/*
@@ -2044,11 +2045,10 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 		 * 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) {
@@ -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 */
-- 
2.38.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 19.11] net/nfp: fix memory leak in Rx
  2022-11-17 14:27 [PATCH 19.11] net/nfp: fix memory leak in Rx Niklas Söderlund
@ 2022-11-18  7:01 ` Christian Ehrhardt
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Ehrhardt @ 2022-11-18  7:01 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: stable, oss-drivers, Long Wu, Chaoyong He

On Thu, Nov 17, 2022 at 3:27 PM Niklas Söderlund
<niklas.soderlund@corigine.com> wrote:
>
> From: Long Wu <long.wu@corigine.com>
>
> [ upstream commit bb340f56fcb7bac9ec04c1c1ca7a2a4f3012c848 ]

Thanks, applied.

>
> 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: b812daadad0d ("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>
> ---
>  drivers/net/nfp/nfp_net.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
> index 76222ca5affd..f2fdff56636c 100644
> --- a/drivers/net/nfp/nfp_net.c
> +++ b/drivers/net/nfp/nfp_net.c
> @@ -2035,8 +2035,9 @@ 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)) {
>                 /*
> @@ -2044,11 +2045,10 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
>                  * 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) {
> @@ -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 */
> --
> 2.38.1
>


-- 
Christian Ehrhardt
Senior Staff Engineer, Ubuntu Server
Canonical Ltd

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-18  7:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 14:27 [PATCH 19.11] net/nfp: fix memory leak in Rx Niklas Söderlund
2022-11-18  7:01 ` Christian Ehrhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).