Re: [PATCH] Fix get_order() [try #2]

From: Alexey Dobriyan
Date: Tue Mar 06 2007 - 14:43:17 EST


On Tue, Mar 06, 2007 at 06:34:26PM +0000, David Howells wrote:
> Provide an ilog2_up() that rounds its result up (ilog2() rounds down).
>
> Fix get_order() to use ilog2_up() not ilog2() to get the correct rounding.
>
> Adjust the documentation surrounding ilog2() and co. to indicate what rounding
> they perform.
>
> Fix roundup_pow_of_two(1) to give 1, not 0.

> --- a/include/asm-generic/page.h
> +++ b/include/asm-generic/page.h
> @@ -17,11 +17,15 @@ static inline __attribute__((const))
> int __get_order(unsigned long size, int page_shift)
> {
> #if BITS_PER_LONG == 32 && defined(ARCH_HAS_ILOG2_U32)

There is no such thing except on FRV, where it's redundant.

CONFIG_ARCH_HAS_ILOG2_U32
^^^^^^

> - int order = __ilog2_u32(size) - page_shift;
> - return order >= 0 ? order : 0;
> + if (size <= (1UL << page_shift))
> + return 0;
> + else
> + return __ilog2_u32(size - 1) + 1 - page_shift;
> #elif BITS_PER_LONG == 64 && defined(ARCH_HAS_ILOG2_U64)

ditto

> - int order = __ilog2_u64(size) - page_shift;
> - return order >= 0 ? order : 0;
> + if (size <= (1UL << page_shift))
> + return 0;
> + else
> + return __ilog2_u64(size - 1) + 1 - page_shift;
> #else
> int order;

-
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/