diff mbox

[dpdk-dev,1/7] Fix rte_is_power_of_2

Message ID 1419521597-31978-2-git-send-email-rkerur@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Ravi Kerur Dec. 25, 2014, 3:33 p.m. UTC
rte_is_power_of_2 returns true for 0 and 0 is not power_of_2. Fix
by checking for n.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/common/include/rte_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Neil Horman Dec. 25, 2014, 5:21 p.m. UTC | #1
On Thu, Dec 25, 2014 at 10:33:11AM -0500, Ravi Kerur wrote:
> rte_is_power_of_2 returns true for 0 and 0 is not power_of_2. Fix
> by checking for n.
> 
> Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> ---
>  lib/librte_eal/common/include/rte_common.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> index 921b91f..8ac940c 100644
> --- a/lib/librte_eal/common/include/rte_common.h
> +++ b/lib/librte_eal/common/include/rte_common.h
> @@ -203,7 +203,7 @@ extern int RTE_BUILD_BUG_ON_detected_error;
>  static inline int
>  rte_is_power_of_2(uint32_t n)
>  {
> -	return ((n-1) & n) == 0;
> +	return n && !(n & (n - 1));
>  }
>  
>  /**
> -- 
> 1.9.1
> 
> 

This is the third time you've tried to slip this change in with some larger
changeset.  I'm in favor of it, but please, stop trying to bury stuff in other,
larger changesets.  Its a legitimate bug, you can just post this on its own.

Neil
Ravi Kerur Dec. 25, 2014, 6:54 p.m. UTC | #2
Sure, will post it separately.

Thanks.

On Thu, Dec 25, 2014 at 9:21 AM, Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, Dec 25, 2014 at 10:33:11AM -0500, Ravi Kerur wrote:
> > rte_is_power_of_2 returns true for 0 and 0 is not power_of_2. Fix
> > by checking for n.
> >
> > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > ---
> >  lib/librte_eal/common/include/rte_common.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_eal/common/include/rte_common.h
> b/lib/librte_eal/common/include/rte_common.h
> > index 921b91f..8ac940c 100644
> > --- a/lib/librte_eal/common/include/rte_common.h
> > +++ b/lib/librte_eal/common/include/rte_common.h
> > @@ -203,7 +203,7 @@ extern int RTE_BUILD_BUG_ON_detected_error;
> >  static inline int
> >  rte_is_power_of_2(uint32_t n)
> >  {
> > -     return ((n-1) & n) == 0;
> > +     return n && !(n & (n - 1));
> >  }
> >
> >  /**
> > --
> > 1.9.1
> >
> >
>
> This is the third time you've tried to slip this change in with some larger
> changeset.  I'm in favor of it, but please, stop trying to bury stuff in
> other,
> larger changesets.  Its a legitimate bug, you can just post this on its
> own.
>
> Neil
>
>
diff mbox

Patch

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 921b91f..8ac940c 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -203,7 +203,7 @@  extern int RTE_BUILD_BUG_ON_detected_error;
 static inline int
 rte_is_power_of_2(uint32_t n)
 {
-	return ((n-1) & n) == 0;
+	return n && !(n & (n - 1));
 }
 
 /**