From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id CE67B2BC9 for ; Tue, 17 Jul 2018 20:43:31 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 11:43:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,366,1526367600"; d="scan'208";a="67684935" Received: from silpixa00399466.ir.intel.com (HELO silpixa00399466.ger.corp.intel.com) ([10.237.223.220]) by orsmga003.jf.intel.com with ESMTP; 17 Jul 2018 11:43:29 -0700 From: Pablo de Lara To: olivier.matz@6wind.com, arybchenko@solarflare.com Cc: dev@dpdk.org, Pablo de Lara Date: Tue, 17 Jul 2018 11:37:20 +0100 Message-Id: <20180717103720.26783-1-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 2.14.4 Subject: [dpdk-dev] [PATCH] mempool: check for invalid args on creation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jul 2018 18:43:32 -0000 Currently, a mempool can be created if the number of objects is zero or the size of these is zero. In these scenarios, rte_mempool_create should return NULL, as the mempool created is useless. Signed-off-by: Pablo de Lara --- lib/librte_mempool/rte_mempool.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 8c8b9f809..8c9573f1a 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -916,6 +916,18 @@ 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 for zero-sized elements */ + if (elt_size == 0) { + rte_errno = EINVAL; + return NULL; + } + /* asked cache too big */ if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE || CALC_CACHE_FLUSHTHRESH(cache_size) > n) { -- 2.14.4