* [PATCH] eal / malloc : alignment parameter check failing due to changes in rte_is_power_of_2
@ 2015-01-16 15:10 Declan Doherty
[not found] ` <1421421030-22261-1-git-send-email-declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Declan Doherty @ 2015-01-16 15:10 UTC (permalink / raw)
To: dev-VfR2kkLFssw
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 <declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread[parent not found: <1421421030-22261-1-git-send-email-declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH] eal / malloc : alignment parameter check failing due to changes in rte_is_power_of_2 [not found] ` <1421421030-22261-1-git-send-email-declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> @ 2015-01-16 15:37 ` De Lara Guarch, Pablo 2015-01-16 17:01 ` Thomas Monjalon 1 sibling, 0 replies; 5+ messages in thread From: De Lara Guarch, Pablo @ 2015-01-16 15:37 UTC (permalink / raw) To: Doherty, Declan, dev-VfR2kkLFssw@public.gmane.org > -----Original Message----- > From: dev [mailto:dev-bounces-VfR2kkLFssw@public.gmane.org] On Behalf Of Declan Doherty > Sent: Friday, January 16, 2015 3:11 PM > To: dev-VfR2kkLFssw@public.gmane.org > Subject: [dpdk-dev] [PATCH] eal / malloc : alignment parameter check failing > due to changes in rte_is_power_of_2 > > 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 <declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> Acked-by: Pablo de Lara <pablo.de.lara.guarch-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] eal / malloc : alignment parameter check failing due to changes in rte_is_power_of_2 [not found] ` <1421421030-22261-1-git-send-email-declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> 2015-01-16 15:37 ` De Lara Guarch, Pablo @ 2015-01-16 17:01 ` Thomas Monjalon 2015-01-18 19:26 ` Doherty, Declan 1 sibling, 1 reply; 5+ messages in thread From: Thomas Monjalon @ 2015-01-16 17:01 UTC (permalink / raw) To: Declan Doherty; +Cc: dev-VfR2kkLFssw 2015-01-16 15:10, Declan Doherty: > 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 <declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> [...] > - if (!rte_is_power_of_2(align)) { > + if (align ? !rte_is_power_of_2(align) : 0) { [...] > - if (size == 0 || !rte_is_power_of_2(align)) > + if (size == 0 || align ? !rte_is_power_of_2(align) : 0) I don't understand why you write "align ? !rte_is_power_of_2(align) : 0" instead of the more readable "align && !rte_is_power_of_2(align)" ? Pablo acked it so I guess there is something obvious I'm missing. -- Thomas ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] eal / malloc : alignment parameter check failing due to changes in rte_is_power_of_2 2015-01-16 17:01 ` Thomas Monjalon @ 2015-01-18 19:26 ` Doherty, Declan [not found] ` <345C63BAECC1AD42A2EC8C63AFFC3ADC2747EE3D-kPTMFJFq+rF9qrmMLTLiibfspsVTdybXVpNB7YpNyf8@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Doherty, Declan @ 2015-01-18 19:26 UTC (permalink / raw) To: Thomas Monjalon; +Cc: dev-VfR2kkLFssw@public.gmane.org > -----Original Message----- > From: Thomas Monjalon [mailto:thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org] > Sent: Friday, January 16, 2015 5:02 PM > To: Doherty, Declan > Cc: dev-VfR2kkLFssw@public.gmane.org; De Lara Guarch, Pablo > Subject: Re: [dpdk-dev] [PATCH] eal / malloc : alignment parameter check failing > due to changes in rte_is_power_of_2 > > 2015-01-16 15:10, Declan Doherty: > > 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 <declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> > [...] > > - if (!rte_is_power_of_2(align)) { > > + if (align ? !rte_is_power_of_2(align) : 0) { > [...] > > - if (size == 0 || !rte_is_power_of_2(align)) > > + if (size == 0 || align ? !rte_is_power_of_2(align) : 0) > > I don't understand why you write "align ? !rte_is_power_of_2(align) : 0" > instead of the more readable "align && !rte_is_power_of_2(align)" ? > > Pablo acked it so I guess there is something obvious I'm missing. > > -- > Thomas No there's nothing you're missing, this is just the way I saw the logic, if align is none zero, then test the power of 2 condition otherwise return 0. I have no problem with your suggestion in you prefer that, at the end of the day the logic test works out equivalent. ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <345C63BAECC1AD42A2EC8C63AFFC3ADC2747EE3D-kPTMFJFq+rF9qrmMLTLiibfspsVTdybXVpNB7YpNyf8@public.gmane.org>]
* Re: [PATCH] eal / malloc : alignment parameter check failing due to changes in rte_is_power_of_2 [not found] ` <345C63BAECC1AD42A2EC8C63AFFC3ADC2747EE3D-kPTMFJFq+rF9qrmMLTLiibfspsVTdybXVpNB7YpNyf8@public.gmane.org> @ 2015-01-19 9:00 ` Thomas Monjalon 0 siblings, 0 replies; 5+ messages in thread From: Thomas Monjalon @ 2015-01-19 9:00 UTC (permalink / raw) To: Doherty, Declan; +Cc: dev-VfR2kkLFssw 2015-01-18 19:26, Doherty, Declan: > From: Thomas Monjalon [mailto:thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org] > > 2015-01-16 15:10, Declan Doherty: > > > 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 <declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> > > [...] > > > - if (!rte_is_power_of_2(align)) { > > > + if (align ? !rte_is_power_of_2(align) : 0) { > > [...] > > > - if (size == 0 || !rte_is_power_of_2(align)) > > > + if (size == 0 || align ? !rte_is_power_of_2(align) : 0) There is an operator precedence bug here. Parens are needed after ||. > > I don't understand why you write "align ? !rte_is_power_of_2(align) : 0" > > instead of the more readable "align && !rte_is_power_of_2(align)" ? > > > > Pablo acked it so I guess there is something obvious I'm missing. > > No there's nothing you're missing, this is just the way I saw the logic, if align is none > zero, then test the power of 2 condition otherwise return 0. I have no problem with > your suggestion in you prefer that, at the end of the day the logic test works out equivalent. So I change to the simpler && form and I add parentheses after || to correctly check size==0. Applied with above changes. Thanks -- Thomas ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-01-19 9:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-16 15:10 [PATCH] eal / malloc : alignment parameter check failing due to changes in rte_is_power_of_2 Declan Doherty
[not found] ` <1421421030-22261-1-git-send-email-declan.doherty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-01-16 15:37 ` De Lara Guarch, Pablo
2015-01-16 17:01 ` Thomas Monjalon
2015-01-18 19:26 ` Doherty, Declan
[not found] ` <345C63BAECC1AD42A2EC8C63AFFC3ADC2747EE3D-kPTMFJFq+rF9qrmMLTLiibfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-01-19 9:00 ` Thomas Monjalon
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.