* [PATCH 0/2] mempool: add rte_errno, and turn functions into single-exit ones @ 2025-01-19 17:46 Ariel Otilibili 2025-01-19 17:46 ` [PATCH 1/2] mempool: add rte_errno in rte_mempool_set_ops_byname Ariel Otilibili ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Ariel Otilibili @ 2025-01-19 17:46 UTC (permalink / raw) To: dev Cc: stable, Thomas Monjalon, David Marchand, Ariel Otilibili, Andrew Rybchenko, Morten Brørup Hello, This series is for BugZilla ID 1559. rte_mempool_set_ops_byname() did not set rte_errno for error exit. As well, other functions did not consistently set the variable. For avoiding that, they are turned into single-exit functions. Thank you, Ariel Otilibili (2): mempool: add rte_errno in rte_mempool_set_ops_byname mempool: turn functions into single-exit ones lib/mempool/rte_mempool_ops.c | 44 ++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) -- 2.30.2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] mempool: add rte_errno in rte_mempool_set_ops_byname 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 ` Ariel Otilibili 2025-01-19 17:46 ` [PATCH 2/2] mempool: turn functions into single-exit ones Ariel Otilibili 2025-01-20 12:21 ` [PATCH v2 0/2] add rte_errno to rte_mempool_create_empty, and refactor Ariel Otilibili 2 siblings, 0 replies; 8+ messages in thread From: Ariel Otilibili @ 2025-01-19 17:46 UTC (permalink / raw) To: dev Cc: stable, Thomas Monjalon, David Marchand, Ariel Otilibili, Andrew Rybchenko, Morten Brørup 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(-) 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; -- 2.30.2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] mempool: turn functions into single-exit ones 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 ` Ariel Otilibili 2025-01-19 23:44 ` Konstantin Ananyev 2025-01-20 12:21 ` [PATCH v2 0/2] add rte_errno to rte_mempool_create_empty, and refactor Ariel Otilibili 2 siblings, 1 reply; 8+ messages in thread From: Ariel Otilibili @ 2025-01-19 17:46 UTC (permalink / raw) To: dev Cc: stable, Thomas Monjalon, David Marchand, Ariel Otilibili, Andrew Rybchenko, Morten Brørup 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(-) 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH 2/2] mempool: turn functions into single-exit ones 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 0 siblings, 1 reply; 8+ messages in thread From: Konstantin Ananyev @ 2025-01-19 23:44 UTC (permalink / raw) To: Ariel Otilibili, dev Cc: stable, Thomas Monjalon, David Marchand, Andrew Rybchenko, Morten Brørup > 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] mempool: turn functions into single-exit ones 2025-01-19 23:44 ` Konstantin Ananyev @ 2025-01-20 10:05 ` Ariel Otilibili 0 siblings, 0 replies; 8+ messages in thread From: Ariel Otilibili @ 2025-01-20 10:05 UTC (permalink / raw) To: Konstantin Ananyev Cc: dev, stable, Thomas Monjalon, David Marchand, Andrew Rybchenko, Morten Brørup [-- Attachment #1: Type: text/plain, Size: 804 bytes --] 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 [-- Attachment #2: Type: text/html, Size: 1405 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 0/2] add rte_errno to rte_mempool_create_empty, and refactor 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-20 12:21 ` 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 ` [PATCH v2 2/2] mempool: make rte_mempool_create_empty a single-exit Ariel Otilibili 2 siblings, 2 replies; 8+ messages in thread From: Ariel Otilibili @ 2025-01-20 12:21 UTC (permalink / raw) To: dev Cc: stable, Thomas Monjalon, David Marchand, Andrew Rybchenko, Morten Brørup, Konstantin Ananyev, Ariel Otilibili From: Ariel Otilibili <ariel.otilibili@6wind.com Hello, This series is for BugZilla ID 1559. After calling rte_mempool_set_ops_byname(), rte_mempool_create_empty() does not set rte_errno. The API expects rte_errno to bet set in that case. Thank you, --- v2 * reworded cover letter and commit messages * addressed feedback from Konstantin Ananyev v1 (https://inbox.dpdk.org/dev/20250119174643.2162110-1-ariel.otilibili@6wind.com/) Ariel Otilibili (2): mempool: fix rte_errno in rte_mempool_create_empty mempool: make rte_mempool_create_empty a single-exit lib/mempool/rte_mempool.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) -- 2.30.2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] mempool: fix rte_errno in rte_mempool_create_empty 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 ` Ariel Otilibili 2025-01-20 12:21 ` [PATCH v2 2/2] mempool: make rte_mempool_create_empty a single-exit Ariel Otilibili 1 sibling, 0 replies; 8+ messages in thread From: Ariel Otilibili @ 2025-01-20 12:21 UTC (permalink / raw) To: dev Cc: stable, Thomas Monjalon, David Marchand, Ariel Otilibili, Andrew Rybchenko, Morten Brørup, Konstantin Ananyev When returning from rte_mempool_set_ops_byname(), rte_errno is not set for error exits. The API requires rte_errno to be set in that case. Bugzilla ID: 1559 Fixes: c2c6b2f41305 ("mempool: fix default ops for an empty mempool") Link: https://doc.dpdk.org/api/rte__mempool_8h.html#a82e301ee33ed7a263ceb4582655dc3ea Signed-off-by: Ariel Otilibili <ariel.otilibili@6wind.com> --- lib/mempool/rte_mempool.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c index d8e39e5c2072..1e4f24783c0b 100644 --- a/lib/mempool/rte_mempool.c +++ b/lib/mempool/rte_mempool.c @@ -928,8 +928,10 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, else ret = rte_mempool_set_ops_byname(mp, "ring_mp_mc", NULL); - if (ret) + if (ret) { + rte_errno = -ret; goto exit_unlock; + } /* * local_cache pointer is set even if cache_size is zero. -- 2.30.2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] mempool: make rte_mempool_create_empty a single-exit 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 1 sibling, 0 replies; 8+ messages in thread From: Ariel Otilibili @ 2025-01-20 12:21 UTC (permalink / raw) To: dev Cc: stable, Thomas Monjalon, David Marchand, Ariel Otilibili, Andrew Rybchenko, Morten Brørup, Konstantin Ananyev 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 < ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-01-20 12:22 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 ` [PATCH v2 2/2] mempool: make rte_mempool_create_empty a single-exit Ariel Otilibili
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).