lkml.org 
[lkml]   [2007]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Fix get_order()
David Howells wrote:
> From: David Howells <dhowells@redhat.com>
>
> Fix get_order() to use ilog2() properly.
>
> Signed-Off-By: David Howells <dhowells@redhat.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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-03-06 19:03    [W:0.114 / U:0.128 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site