[v2] mempool: check for invalid args on creation

Message ID 20180802003504.30679-1-pablo.de.lara.guarch@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] mempool: check for invalid args on creation |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

De Lara Guarch, Pablo Aug. 2, 2018, 12:35 a.m. UTC
  Currently, a mempool can be created if the number of
objects is zero. However, in this scenario,
rte_mempool_create should return NULL,
as the mempool created is useless otherwise.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 lib/librte_mempool/rte_mempool.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Andrew Rybchenko Aug. 2, 2018, 11:10 a.m. UTC | #1
On 02.08.2018 03:35, Pablo de Lara wrote:
> Currently, a mempool can be created if the number of
> objects is zero. However, in this scenario,
> rte_mempool_create should return NULL,
> as the mempool created is useless otherwise.
>
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>

Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
  
Thomas Monjalon Aug. 5, 2018, 1:35 p.m. UTC | #2
02/08/2018 13:10, Andrew Rybchenko:
> On 02.08.2018 03:35, Pablo de Lara wrote:
> > Currently, a mempool can be created if the number of
> > objects is zero. However, in this scenario,
> > rte_mempool_create should return NULL,
> > as the mempool created is useless otherwise.
> >
> > Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> 
> Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index 8c8b9f809..a24a14887 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -916,6 +916,12 @@  rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 
 	mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list);
 
+	/* asked for zero items */
+	if (n == 0) {
+		rte_errno = EINVAL;
+		return NULL;
+	}
+
 	/* asked cache too big */
 	if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE ||
 	    CALC_CACHE_FLUSHTHRESH(cache_size) > n) {