DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ariel Otilibili <ariel.otilibili@6wind.com>
To: dev@dpdk.org
Cc: stable@dpdk.org, "Thomas Monjalon" <thomas@monjalon.net>,
	"David Marchand" <david.marchand@redhat.com>,
	"Ariel Otilibili" <ariel.otilibili@6wind.com>,
	"Andrew Rybchenko" <andrew.rybchenko@oktetlabs.ru>,
	"Morten Brørup" <mb@smartsharesystems.com>,
	"Konstantin Ananyev" <konstantin.ananyev@huawei.com>
Subject: [PATCH v2 2/2] mempool: make rte_mempool_create_empty a single-exit
Date: Mon, 20 Jan 2025 13:21:56 +0100	[thread overview]
Message-ID: <20250120122156.2480524-3-ariel.otilibili@6wind.com> (raw)
In-Reply-To: <20250120122156.2480524-1-ariel.otilibili@6wind.com>

For properly setting rte_errno, and exiting rte_mempool_create_empty()
from a single place.

Bugzilla ID: 1559
Signed-off-by: Ariel Otilibili <ariel.otilibili@6wind.com>
---
 lib/mempool/rte_mempool.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
index 1e4f24783c0b..3f9a4a1771d3 100644
--- a/lib/mempool/rte_mempool.c
+++ b/lib/mempool/rte_mempool.c
@@ -831,20 +831,20 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 	/* asked for zero items */
 	if (n == 0) {
 		rte_errno = EINVAL;
-		return NULL;
+		goto exit;
 	}
 
 	/* asked cache too big */
 	if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE ||
 	    CALC_CACHE_FLUSHTHRESH(cache_size) > n) {
 		rte_errno = EINVAL;
-		return NULL;
+		goto exit;
 	}
 
 	/* enforce only user flags are passed by the application */
 	if ((flags & ~RTE_MEMPOOL_VALID_USER_FLAGS) != 0) {
 		rte_errno = EINVAL;
-		return NULL;
+		goto exit;
 	}
 
 	/*
@@ -860,7 +860,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 	/* calculate mempool object sizes. */
 	if (!rte_mempool_calc_obj_size(elt_size, flags, &objsz)) {
 		rte_errno = EINVAL;
-		return NULL;
+		goto exit;
 	}
 
 	rte_mcfg_mempool_write_lock();
@@ -877,7 +877,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 	te = rte_zmalloc("MEMPOOL_TAILQ_ENTRY", sizeof(*te), 0);
 	if (te == NULL) {
 		RTE_MEMPOOL_LOG(ERR, "Cannot allocate tailq entry!");
-		goto exit_unlock;
+		goto unlock;
 	}
 
 	mempool_size = RTE_MEMPOOL_HEADER_SIZE(mp, cache_size);
@@ -887,12 +887,12 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 	ret = snprintf(mz_name, sizeof(mz_name), RTE_MEMPOOL_MZ_FORMAT, name);
 	if (ret < 0 || ret >= (int)sizeof(mz_name)) {
 		rte_errno = ENAMETOOLONG;
-		goto exit_unlock;
+		goto unlock;
 	}
 
 	mz = rte_memzone_reserve(mz_name, mempool_size, socket_id, mz_flags);
 	if (mz == NULL)
-		goto exit_unlock;
+		goto unlock;
 
 	/* init the mempool structure */
 	mp = mz->addr;
@@ -900,7 +900,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 	ret = strlcpy(mp->name, name, sizeof(mp->name));
 	if (ret < 0 || ret >= (int)sizeof(mp->name)) {
 		rte_errno = ENAMETOOLONG;
-		goto exit_unlock;
+		goto unlock;
 	}
 	mp->mz = mz;
 	mp->size = n;
@@ -930,7 +930,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 
 	if (ret) {
 		rte_errno = -ret;
-		goto exit_unlock;
+		goto unlock;
 	}
 
 	/*
@@ -956,13 +956,16 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
 
 	rte_mempool_trace_create_empty(name, n, elt_size, cache_size,
 		private_data_size, flags, mp);
-	return mp;
+	goto exit;
 
-exit_unlock:
+unlock:
 	rte_mcfg_mempool_write_unlock();
 	rte_free(te);
 	rte_mempool_free(mp);
-	return NULL;
+	mp = NULL;
+
+exit:
+	return mp;
 }
 
 /* create the mempool */
-- 
2.30.2
<

      parent reply	other threads:[~2025-01-20 12:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-19 17:46 [PATCH 0/2] mempool: add rte_errno, and turn functions into single-exit ones Ariel Otilibili
2025-01-19 17:46 ` [PATCH 1/2] mempool: add rte_errno in rte_mempool_set_ops_byname Ariel Otilibili
2025-01-19 17:46 ` [PATCH 2/2] mempool: turn functions into single-exit ones Ariel Otilibili
2025-01-19 23:44   ` Konstantin Ananyev
2025-01-20 10:05     ` Ariel Otilibili
2025-01-20 12:21 ` [PATCH v2 0/2] add rte_errno to rte_mempool_create_empty, and refactor Ariel Otilibili
2025-01-20 12:21   ` [PATCH v2 1/2] mempool: fix rte_errno in rte_mempool_create_empty Ariel Otilibili
2025-01-20 12:21   ` Ariel Otilibili [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250120122156.2480524-3-ariel.otilibili@6wind.com \
    --to=ariel.otilibili@6wind.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@huawei.com \
    --cc=mb@smartsharesystems.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).