[PATCH] POWERPC: Use "is_power_of_2" macro for simplicity.

Robert P. J. Day rpjday at crashcourse.ca
Wed Nov 7 04:11:42 EST 2007


Signed-off-by: Robert P. J. Day <rpjday at crashcourse.ca>

---

diff --git a/arch/powerpc/lib/rheap.c b/arch/powerpc/lib/rheap.c
index 22c3b4f..53b4e91 100644
--- a/arch/powerpc/lib/rheap.c
+++ b/arch/powerpc/lib/rheap.c
@@ -19,6 +19,7 @@
 #include <linux/mm.h>
 #include <linux/err.h>
 #include <linux/slab.h>
+#include <linux/log2.h>

 #include <asm/rheap.h>

@@ -254,8 +255,7 @@ rh_info_t *rh_create(unsigned int alignment)
 {
 	rh_info_t *info;

-	/* Alignment must be a power of two */
-	if ((alignment & (alignment - 1)) != 0)
+	if (!is_power_of_2(alignment))
 		return ERR_PTR(-EINVAL);

 	info = kmalloc(sizeof(*info), GFP_KERNEL);
@@ -303,8 +303,7 @@ void rh_init(rh_info_t * info, unsigned int alignment, int max_blocks,
 	int i;
 	rh_block_t *blk;

-	/* Alignment must be a power of two */
-	if ((alignment & (alignment - 1)) != 0)
+	if (!is_power_of_2(alignment))
 		return;

 	info->alignment = alignment;
@@ -446,8 +445,7 @@ unsigned long rh_alloc_align(rh_info_t * info, int size, int alignment, const ch
 	rh_block_t *newblk;
 	unsigned long start, sp_size;

-	/* Validate size, and alignment must be power of two */
-	if (size <= 0 || (alignment & (alignment - 1)) != 0)
+	if (size <= 0 || !is_power_of_2(alignment))
 		return (unsigned long) -EINVAL;

 	/* Align to configured alignment */
-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================



More information about the Linuxppc-dev mailing list