[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <45EDABC8.8040901@zytor.com>
Date: Tue, 06 Mar 2007 09:58:32 -0800
From: "H. Peter Anvin" <hpa@...or.com>
To: David Howells <dhowells@...hat.com>
CC: torvalds@...l.org, akpm@...l.org, benh@...nel.crashing.org,
linux-kernel@...r.kernel.org, johannes@...solutions.net
Subject: Re: [PATCH] Fix get_order()
David Howells wrote:
> From: David Howells <dhowells@...hat.com>
>
> Fix get_order() to use ilog2() properly.
>
> Signed-Off-By: David Howells <dhowells@...hat.com>
> ---
>
> 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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists