From 32e17fd571e0139c140674f94a0c3823129af551 Mon Sep 17 00:00:00 2001 From: Zoltan Kiss Date: Wed, 20 Jul 2016 18:16:39 +0100 Subject: [PATCH] mem: allow full length name (strlen(name) == sizeof(mz->name) - 1) is a valid case, change the condition to reflect that. Move it earlier to avoid lookup with invalid name. Change errno to ENAMETOOLONG. Fixes: 85cf0079 ("mem: avoid memzone/mempool/ring name truncation") Signed-off-by: Zoltan Kiss Acked-by: Olivier Matz --- lib/librte_eal/common/eal_common_memzone.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 5d28341f7e..1bd0a33d1d 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -144,16 +144,16 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, return NULL; } - /* zone already exist */ - if ((memzone_lookup_thread_unsafe(name)) != NULL) { - RTE_LOG(DEBUG, EAL, "%s(): memzone <%s> already exists\n", + if (strlen(name) > sizeof(mz->name) - 1) { + RTE_LOG(DEBUG, EAL, "%s(): memzone <%s>: name too long\n", __func__, name); - rte_errno = EEXIST; + rte_errno = ENAMETOOLONG; return NULL; } - if (strlen(name) >= sizeof(mz->name) - 1) { - RTE_LOG(DEBUG, EAL, "%s(): memzone <%s>: name too long\n", + /* zone already exist */ + if ((memzone_lookup_thread_unsafe(name)) != NULL) { + RTE_LOG(DEBUG, EAL, "%s(): memzone <%s> already exists\n", __func__, name); rte_errno = EEXIST; return NULL; -- 2.20.1