[2/5] mbuf: fix missing errno for dyn field/flag registration

Message ID 20200613154922.42379-3-xiaolong.ye@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series small fixes for mbuf's dynamic field/flag feature |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Xiaolong Ye June 13, 2020, 3:49 p.m. UTC
  Set rte_errno as ENOMEM when allocation failure.

Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags")
Cc: stable@dpdk.org

Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
---
 lib/librte_mbuf/rte_mbuf_dyn.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Comments

Olivier Matz June 25, 2020, 3:31 p.m. UTC | #1
On Sat, Jun 13, 2020 at 11:49:18PM +0800, Xiaolong Ye wrote:
> Set rte_errno as ENOMEM when allocation failure.
> 
> Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>

Good catch, I was wrongly expecting that rte_malloc() functions sets
rte_errno on error.

I wonder if the malloc API shouldn't be modified, because I can see
several places where the same kind of fix would be needed: rte_efd,
rte_cuckoo_hash, rte_fbk_hash, rte_member, ...

Anatoly, what do you think?

Acked-by: Olivier Matz <olivier.matz@6wind.com>
  

Patch

diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c
index 13d6da6d16..de7d2eb9a5 100644
--- a/lib/librte_mbuf/rte_mbuf_dyn.c
+++ b/lib/librte_mbuf/rte_mbuf_dyn.c
@@ -278,12 +278,15 @@  __rte_mbuf_dynfield_register_offset(const struct rte_mbuf_dynfield *params,
 		mbuf_dynfield_tailq.head, mbuf_dynfield_list);
 
 	te = rte_zmalloc("MBUF_DYNFIELD_TAILQ_ENTRY", sizeof(*te), 0);
-	if (te == NULL)
+	if (te == NULL) {
+		rte_errno = ENOMEM;
 		return -1;
+	}
 
 	mbuf_dynfield = rte_zmalloc("mbuf_dynfield", sizeof(*mbuf_dynfield), 0);
 	if (mbuf_dynfield == NULL) {
 		rte_free(te);
+		rte_errno = ENOMEM;
 		return -1;
 	}
 
@@ -456,12 +459,15 @@  __rte_mbuf_dynflag_register_bitnum(const struct rte_mbuf_dynflag *params,
 		mbuf_dynflag_tailq.head, mbuf_dynflag_list);
 
 	te = rte_zmalloc("MBUF_DYNFLAG_TAILQ_ENTRY", sizeof(*te), 0);
-	if (te == NULL)
+	if (te == NULL) {
+		rte_errno = ENOMEM;
 		return -1;
+	}
 
 	mbuf_dynflag = rte_zmalloc("mbuf_dynflag", sizeof(*mbuf_dynflag), 0);
 	if (mbuf_dynflag == NULL) {
 		rte_free(te);
+		rte_errno = ENOMEM;
 		return -1;
 	}