[PATCH 1/4] net/gve: free Rx mbufs if allocation fails on ring setup

Joshua Washington joshwash at google.com
Tue Aug 26 02:03:34 CEST 2025


When creating new RX rings, one less than the number of buffers in the
ring need to be allocated. It is possible that only a part of the
allocation is successful, resulting in a failure to create the rings.
In this case, the driver should free the buffers which were successfully
allocated to avoid a memory leak in case the application does not
automatically exit.

Fixes: 265daac8a53a ("net/gve: fix mbuf allocation memory leak for DQ Rx")
Cc: stable at dpdk.org
Signed-off-by: Joshua Washington <joshwash at google.com>
Reviewed-by: Ankit Garg <nktgrg at google.com>
Reviewed-by: Ziwei Xiao <ziweixiao at google.com>
---
 drivers/net/gve/gve_rx_dqo.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/net/gve/gve_rx_dqo.c b/drivers/net/gve/gve_rx_dqo.c
index 0103add985..cd85d90bb6 100644
--- a/drivers/net/gve/gve_rx_dqo.c
+++ b/drivers/net/gve/gve_rx_dqo.c
@@ -376,14 +376,13 @@ gve_rxq_mbufs_alloc_dqo(struct gve_rx_queue *rxq)
 		rxq->stats.no_mbufs_bulk++;
 		for (i = 0; i < rx_mask; i++) {
 			nmb = rte_pktmbuf_alloc(rxq->mpool);
-			if (!nmb)
-				break;
+			if (!nmb) {
+				rxq->stats.no_mbufs++;
+				gve_release_rxq_mbufs_dqo(rxq);
+				return -ENOMEM;
+			}
 			rxq->sw_ring[i] = nmb;
 		}
-		if (i < rxq->nb_rx_desc - 1) {
-			rxq->stats.no_mbufs += rx_mask - i;
-			return -ENOMEM;
-		}
 	}
 
 	for (i = 0; i < rx_mask; i++) {
-- 
2.51.0.rc1.167.g924127e9c0-goog



More information about the stable mailing list