[1/2] mempool: add rte_errno in rte_mempool_set_ops_byname

Message ID 20250119174643.2162110-2-ariel.otilibili@6wind.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers
Series mempool: add rte_errno, and turn functions into single-exit ones |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ariel Otilibili Jan. 19, 2025, 5:46 p.m. UTC
rte_errno is not set for error exits. For the scenario described in
BugZilla ID 1559, rte_mempool_create_empty() calls
rte_mempool_set_ops_byname(), but does not set as well the proper
rte_errno.

rte_errno is now set in rte_mempool_set_ops_byname(); from there it
cascades down to the calling function.

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

Patch

diff --git a/lib/mempool/rte_mempool_ops.c b/lib/mempool/rte_mempool_ops.c
index 1b33380259b3..b5c68ac61b67 100644
--- a/lib/mempool/rte_mempool_ops.c
+++ b/lib/mempool/rte_mempool_ops.c
@@ -169,8 +169,10 @@  rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
 	unsigned i;
 
 	/* too late, the mempool is already populated. */
-	if (mp->flags & RTE_MEMPOOL_F_POOL_CREATED)
-		return -EEXIST;
+	if (mp->flags & RTE_MEMPOOL_F_POOL_CREATED) {
+		rte_errno = EEXIST;
+		return -rte_errno;
+	}
 
 	for (i = 0; i < rte_mempool_ops_table.num_ops; i++) {
 		if (!strcmp(name,
@@ -180,8 +182,10 @@  rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
 		}
 	}
 
-	if (ops == NULL)
-		return -EINVAL;
+	if (ops == NULL) {
+		rte_errno = EINVAL;
+		return -rte_errno;
+	}
 
 	mp->ops_index = i;
 	mp->pool_config = pool_config;