From mboxrd@z Thu Jan 1 00:00:00 1970 From: Declan Doherty Subject: [PATCH] eal / malloc : alignment parameter check failing due to changes in rte_is_power_of_2 Date: Fri, 16 Jan 2015 15:10:30 +0000 Message-ID: <1421421030-22261-1-git-send-email-declan.doherty@intel.com> To: dev-VfR2kkLFssw@public.gmane.org Return-path: List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" In commit 2fc8d6d the behaviour of function rte_is_power_of_2 was changed to not return true for 0. memzone_reserve_aligned_thread_unsafe and rte_malloc_socket both make the assumption that for align = 0 !rte_is_power_of_2(align) will return false. This patch adds a check that align parameter is non-zero before doing the power of 2 check Signed-off-by: Declan Doherty --- lib/librte_eal/common/eal_common_memzone.c | 2 +- lib/librte_malloc/rte_malloc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index b5a5d72..3f09338 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -156,7 +156,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, } /* if alignment is not a power of two */ - if (!rte_is_power_of_2(align)) { + if (align ? !rte_is_power_of_2(align) : 0) { RTE_LOG(ERR, EAL, "%s(): Invalid alignment: %u\n", __func__, align); rte_errno = EINVAL; diff --git a/lib/librte_malloc/rte_malloc.c b/lib/librte_malloc/rte_malloc.c index b966fc7..15c7e20 100644 --- a/lib/librte_malloc/rte_malloc.c +++ b/lib/librte_malloc/rte_malloc.c @@ -75,7 +75,7 @@ rte_malloc_socket(const char *type, size_t size, unsigned align, int socket_arg) void *ret; /* return NULL if size is 0 or alignment is not power-of-2 */ - if (size == 0 || !rte_is_power_of_2(align)) + if (size == 0 || align ? !rte_is_power_of_2(align) : 0) return NULL; if (socket_arg == SOCKET_ID_ANY) -- 1.7.12.2