From: Declan Doherty Date: Fri, 16 Jan 2015 15:10:30 +0000 (+0000) Subject: mem: fix alignment parameter check X-Git-Tag: spdx-start~9841 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=8e3e06501660d09103bdbdff61c55d2f5ffdf433;p=dpdk.git mem: fix alignment parameter check 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 Acked-by: Pablo de Lara [Thomas: use && operator instead of ternary ?: and fix precedence with parens] Acked-by: Thomas Monjalon --- diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index b5a5d7274f..a588012465 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)) { 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 b966fc7d0c..8811718d1f 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))) return NULL; if (socket_arg == SOCKET_ID_ANY)