diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c index 1891dbeeb8e9deb7ac88718fbb4680f54b579558..bd02272bcb0fee3dcdcfcc507c725b7d23bd8404 100644 --- a/arch/powerpc/mm/pgtable_32.c +++ b/arch/powerpc/mm/pgtable_32.c @@ -294,11 +294,8 @@ void __init mapin_ram(void) } } -/* is x a power of 2? */ -#define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) - /* is x a power of 4? */ -#define is_power_of_4(x) ((x) != 0 && (((x) & (x-1)) == 0) && (ffs(x) & 1)) +#define is_power_of_4(x) is_power_of_2(x) && (ffs(x) & 1)) /* * Set up a mapping for a block of I/O. diff --git a/arch/ppc/mm/pgtable.c b/arch/ppc/mm/pgtable.c index 354a9408f02436b83ac8204d8a854686c675e264..82b06a1ef95d6e532415bfb238d43311e5778e28 100644 --- a/arch/ppc/mm/pgtable.c +++ b/arch/ppc/mm/pgtable.c @@ -313,11 +313,8 @@ void __init mapin_ram(void) } } -/* is x a power of 2? */ -#define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) - /* is x a power of 4? */ -#define is_power_of_4(x) ((x) != 0 && (((x) & (x-1)) == 0) && (ffs(x) & 1)) +#define is_power_of_4(x) is_power_of_2(x) && (ffs(x) & 1)) /* * Set up a mapping for a block of I/O. diff --git a/arch/ppc/syslib/ppc85xx_rio.c b/arch/ppc/syslib/ppc85xx_rio.c index 05b0e94150852e0d8189adf0d529a6667c48fac8..2b097800cdd971945a883d80d5a0567649e3ca15 100644 --- a/arch/ppc/syslib/ppc85xx_rio.c +++ b/arch/ppc/syslib/ppc85xx_rio.c @@ -59,8 +59,6 @@ #define DBELL_TID(x) (*(u8 *)(x + DOORBELL_TID_OFFSET)) #define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET)) -#define is_power_of_2(x) (((x) & ((x) - 1)) == 0) - struct rio_atmu_regs { u32 rowtar; u32 pad1; diff --git a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c index 6d71bea5e9003cd41549d3be8bd177311b080021..0d6943d6709638764e885400be50db4b283f1b49 100644 --- a/drivers/net/gianfar_ethtool.c +++ b/drivers/net/gianfar_ethtool.c @@ -42,8 +42,6 @@ #include "gianfar.h" -#define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) - extern void gfar_start(struct net_device *dev); extern int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit); diff --git a/include/linux/log2.h b/include/linux/log2.h index d02e1a547a7e9deb1e8bc21857780bdc2c7693c0..99922bedfcc90acaef644369aee3d5e126b7d46d 100644 --- a/include/linux/log2.h +++ b/include/linux/log2.h @@ -43,6 +43,17 @@ int __ilog2_u64(u64 n) } #endif +/* + * Determine whether some value is a power of two, where zero is + * *not* considered a power of two. + */ + +static inline __attribute__((const)) +bool is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n & (n - 1)) == 0)); +} + /* * round up to nearest power of two */