[dpdk-dev] [PATCH] eal / malloc : alignment parameter check failing due to changes in rte_is_power_of_2

Thomas Monjalon thomas.monjalon at 6wind.com
Mon Jan 19 10:00:43 CET 2015


2015-01-18 19:26, Doherty, Declan:
> From: Thomas Monjalon [mailto:thomas.monjalon at 6wind.com]
> > 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 at intel.com>
> > [...]
> > > -	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


More information about the dev mailing list