Re: [PATCH] Fix get_order()

From: H. Peter Anvin
Date: Tue Mar 06 2007 - 13:00:48 EST


David Howells wrote:
From: David Howells <dhowells@xxxxxxxxxx>

Fix get_order() to use ilog2() properly.

Signed-Off-By: David Howells <dhowells@xxxxxxxxxx>
---

include/asm-generic/page.h | 14 +++++++++++---
include/linux/log2.h | 20 ++++++++++++++++++--
2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/include/asm-generic/page.h b/include/asm-generic/page.h
index b55052c..c37571d 100644
--- a/include/asm-generic/page.h
+++ b/include/asm-generic/page.h
@@ -17,10 +17,18 @@ static inline __attribute__((const))
int __get_order(unsigned long size, int page_shift)
{
#if BITS_PER_LONG == 32 && defined(ARCH_HAS_ILOG2_U32)
- int order = __ilog2_u32(size) - page_shift;
+ int order;
+ if (size <= 1)
+ order = 0;
+ else
+ order = __ilog2_u32(size - 1) + 1 - page_shift;
return order >= 0 ? order : 0;

This seems a lot more complex than it should be.

Assuming page_shift is usually constant, it would seem to make more sense to do:

if (size <= (1UL << page_shift))
return 0;
else
return __ilog2_u32(size-1)+1-page_shift;

... instead of having *two* conditionals...

-hpa
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/