[2/2] mempool: turn functions into single-exit ones

Message ID 20250119174643.2162110-3-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
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS

Commit Message

Ariel Otilibili Jan. 19, 2025, 5:46 p.m. UTC
Some functions did not set rte_errno; for avoiding that, they are turned
into single-exit ones.

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

Comments

Konstantin Ananyev Jan. 19, 2025, 11:44 p.m. UTC | #1
> Some functions did not set rte_errno; for avoiding that, they are turned
> into single-exit ones.
> 
> Bugzilla ID: 1559
> Signed-off-by: Ariel Otilibili <ariel.otilibili@6wind.com>

But reading through public API comments none of these functions are 
expected to set rte_errno value.
If rte_mempool_create_empty() forgets to set rte_errno, why it is not
enough just to add missing one in rte_mempool_create_empty()?
 

> ---
>  lib/mempool/rte_mempool_ops.c | 38 ++++++++++++++++++++++++++---------
>  1 file changed, 28 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/mempool/rte_mempool_ops.c b/lib/mempool/rte_mempool_ops.c
> index b5c68ac61b67..bf4328645196 100644
> --- a/lib/mempool/rte_mempool_ops.c
> +++ b/lib/mempool/rte_mempool_ops.c
> @@ -33,7 +33,9 @@ rte_mempool_register_ops(const struct rte_mempool_ops *h)
>  		rte_spinlock_unlock(&rte_mempool_ops_table.sl);
>  		RTE_MEMPOOL_LOG(ERR,
>  			"Maximum number of mempool ops structs exceeded");
> -		return -ENOSPC;
> +		rte_errno = ENOSPC;
> +		ops_index = -rte_errno;
> +		goto out;
>  	}
> 
>  	if (h->alloc == NULL || h->enqueue == NULL ||
> @@ -41,7 +43,9 @@ rte_mempool_register_ops(const struct rte_mempool_ops *h)
>  		rte_spinlock_unlock(&rte_mempool_ops_table.sl);
>  		RTE_MEMPOOL_LOG(ERR,
>  			"Missing callback while registering mempool ops");
> -		return -EINVAL;
> +		rte_errno = -EINVAL;
> +		ops_index = -rte_errno;
> +		goto out;
>  	}
> 
>  	if (strlen(h->name) >= sizeof(ops->name) - 1) {
> @@ -49,7 +53,8 @@ rte_mempool_register_ops(const struct rte_mempool_ops *h)
>  		RTE_MEMPOOL_LOG(DEBUG, "%s(): mempool_ops <%s>: name too long",
>  				__func__, h->name);
>  		rte_errno = EEXIST;
> -		return -EEXIST;
> +		ops_index = -rte_errno;
> +		goto out;
>  	}
> 
>  	ops_index = rte_mempool_ops_table.num_ops++;
> @@ -67,6 +72,7 @@ rte_mempool_register_ops(const struct rte_mempool_ops *h)
> 
>  	rte_spinlock_unlock(&rte_mempool_ops_table.sl);
> 
> +out:
>  	return ops_index;
>  }
> 
> @@ -151,12 +157,19 @@ rte_mempool_ops_get_info(const struct rte_mempool *mp,
>  			 struct rte_mempool_info *info)
>  {
>  	struct rte_mempool_ops *ops;
> +	int ret;
> 
>  	ops = rte_mempool_get_ops(mp->ops_index);
> 
> -	if (ops->get_info == NULL)
> -		return -ENOTSUP;
> -	return ops->get_info(mp, info);
> +	if (ops->get_info == NULL) {
> +		rte_errno = ENOTSUP;
> +		ret = -rte_errno;
> +		goto out;
> +	}
> +	ret = ops->get_info(mp, info);
> +
> +out:
> +	return ret;
>  }
> 
> 
> @@ -166,12 +179,14 @@ rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
>  	void *pool_config)
>  {
>  	struct rte_mempool_ops *ops = NULL;
> +	int ret = 0;
>  	unsigned i;
> 
>  	/* too late, the mempool is already populated. */
>  	if (mp->flags & RTE_MEMPOOL_F_POOL_CREATED) {
>  		rte_errno = EEXIST;
> -		return -rte_errno;
> +		ret = -rte_errno;
> +		goto out;
>  	}
> 
>  	for (i = 0; i < rte_mempool_ops_table.num_ops; i++) {
> @@ -182,13 +197,16 @@ rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
>  		}
>  	}
> 
> -	if (ops == NULL) {
> +	if (!ops) {
>  		rte_errno = EINVAL;
> -		return -rte_errno;
> +		ret = -rte_errno;
> +		goto out;
>  	}
> 
>  	mp->ops_index = i;
>  	mp->pool_config = pool_config;
>  	rte_mempool_trace_set_ops_byname(mp, name, pool_config);
> -	return 0;
> +
> +out:
> +	return ret;
>  }
> --
> 2.30.2
  
Ariel Otilibili Jan. 20, 2025, 10:05 a.m. UTC | #2
Hi Konstantin,

On Mon, Jan 20, 2025 at 12:44 AM Konstantin Ananyev <
konstantin.ananyev@huawei.com> wrote:

>
>
> > Some functions did not set rte_errno; for avoiding that, they are turned
> > into single-exit ones.
> >
> > Bugzilla ID: 1559
> > Signed-off-by: Ariel Otilibili <ariel.otilibili@6wind.com>
>
> But reading through public API comments none of these functions are
> expected to set rte_errno value.
> If rte_mempool_create_empty() forgets to set rte_errno, why it is not
> enough just to add missing one in rte_mempool_create_empty()?
>
Thanks for your feedback. Indeed, only  rte_mempool_create_empty() returns
a rte_errno
https://doc.dpdk.org/api/rte__mempool_8h.html#a82e301ee33ed7a263ceb4582655dc3ea

I'll push a new series with this change.

Regards,
Ariel
  

Patch

diff --git a/lib/mempool/rte_mempool_ops.c b/lib/mempool/rte_mempool_ops.c
index b5c68ac61b67..bf4328645196 100644
--- a/lib/mempool/rte_mempool_ops.c
+++ b/lib/mempool/rte_mempool_ops.c
@@ -33,7 +33,9 @@  rte_mempool_register_ops(const struct rte_mempool_ops *h)
 		rte_spinlock_unlock(&rte_mempool_ops_table.sl);
 		RTE_MEMPOOL_LOG(ERR,
 			"Maximum number of mempool ops structs exceeded");
-		return -ENOSPC;
+		rte_errno = ENOSPC;
+		ops_index = -rte_errno;
+		goto out;
 	}
 
 	if (h->alloc == NULL || h->enqueue == NULL ||
@@ -41,7 +43,9 @@  rte_mempool_register_ops(const struct rte_mempool_ops *h)
 		rte_spinlock_unlock(&rte_mempool_ops_table.sl);
 		RTE_MEMPOOL_LOG(ERR,
 			"Missing callback while registering mempool ops");
-		return -EINVAL;
+		rte_errno = -EINVAL;
+		ops_index = -rte_errno;
+		goto out;
 	}
 
 	if (strlen(h->name) >= sizeof(ops->name) - 1) {
@@ -49,7 +53,8 @@  rte_mempool_register_ops(const struct rte_mempool_ops *h)
 		RTE_MEMPOOL_LOG(DEBUG, "%s(): mempool_ops <%s>: name too long",
 				__func__, h->name);
 		rte_errno = EEXIST;
-		return -EEXIST;
+		ops_index = -rte_errno;
+		goto out;
 	}
 
 	ops_index = rte_mempool_ops_table.num_ops++;
@@ -67,6 +72,7 @@  rte_mempool_register_ops(const struct rte_mempool_ops *h)
 
 	rte_spinlock_unlock(&rte_mempool_ops_table.sl);
 
+out:
 	return ops_index;
 }
 
@@ -151,12 +157,19 @@  rte_mempool_ops_get_info(const struct rte_mempool *mp,
 			 struct rte_mempool_info *info)
 {
 	struct rte_mempool_ops *ops;
+	int ret;
 
 	ops = rte_mempool_get_ops(mp->ops_index);
 
-	if (ops->get_info == NULL)
-		return -ENOTSUP;
-	return ops->get_info(mp, info);
+	if (ops->get_info == NULL) {
+		rte_errno = ENOTSUP;
+		ret = -rte_errno;
+		goto out;
+	}
+	ret = ops->get_info(mp, info);
+
+out:
+	return ret;
 }
 
 
@@ -166,12 +179,14 @@  rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
 	void *pool_config)
 {
 	struct rte_mempool_ops *ops = NULL;
+	int ret = 0;
 	unsigned i;
 
 	/* too late, the mempool is already populated. */
 	if (mp->flags & RTE_MEMPOOL_F_POOL_CREATED) {
 		rte_errno = EEXIST;
-		return -rte_errno;
+		ret = -rte_errno;
+		goto out;
 	}
 
 	for (i = 0; i < rte_mempool_ops_table.num_ops; i++) {
@@ -182,13 +197,16 @@  rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
 		}
 	}
 
-	if (ops == NULL) {
+	if (!ops) {
 		rte_errno = EINVAL;
-		return -rte_errno;
+		ret = -rte_errno;
+		goto out;
 	}
 
 	mp->ops_index = i;
 	mp->pool_config = pool_config;
 	rte_mempool_trace_set_ops_byname(mp, name, pool_config);
-	return 0;
+
+out:
+	return ret;
 }