[dpdk-dev,v3] testpmd: fix crash when mempool allocation fails

Message ID 1473414128-10996-1-git-send-email-olivier.matz@6wind.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

Olivier Matz Sept. 9, 2016, 9:42 a.m. UTC
  Avoid access to mempool pointer if it is NULL.

Fixes: b19a0c75a0d4 ("app/testpmd: remove anonymous mempool code")
Coverity issue: 127553

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 app/test-pmd/testpmd.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

De Lara Guarch, Pablo Sept. 21, 2016, 11:02 p.m. UTC | #1
> -----Original Message-----
> From: Olivier Matz [mailto:olivier.matz@6wind.com]
> Sent: Friday, September 09, 2016 2:42 AM
> To: dev@dpdk.org; De Lara Guarch, Pablo
> Cc: stable@dpdk.org
> Subject: [PATCH v3] testpmd: fix crash when mempool allocation fails
> 
> Avoid access to mempool pointer if it is NULL.
> 
> Fixes: b19a0c75a0d4 ("app/testpmd: remove anonymous mempool code")
> Coverity issue: 127553
> 
> Signed-off-by: Olivier Matz <olivier.matz@6wind.com>

Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
  
Thomas Monjalon Sept. 23, 2016, 6:17 p.m. UTC | #2
> > Avoid access to mempool pointer if it is NULL.
> > 
> > Fixes: b19a0c75a0d4 ("app/testpmd: remove anonymous mempool code")
> > Coverity issue: 127553
> > 
> > Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
> 
> Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>

Applied, thanks
  

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 1428974..e5f5986 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -444,10 +444,13 @@  mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
 				mb_size, (unsigned) mb_mempool_cache,
 				sizeof(struct rte_pktmbuf_pool_private),
 				socket_id, 0);
+			if (rte_mp == NULL)
+				goto err;
 
 			if (rte_mempool_populate_anon(rte_mp) == 0) {
 				rte_mempool_free(rte_mp);
 				rte_mp = NULL;
+				goto err;
 			}
 			rte_pktmbuf_pool_init(rte_mp, NULL);
 			rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL);
@@ -458,6 +461,7 @@  mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
 		}
 	}
 
+err:
 	if (rte_mp == NULL) {
 		rte_exit(EXIT_FAILURE,
 			"Creation of mbuf pool for socket %u failed: %s\n",