mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-31 22:34:33 +01:00
Commitd66acc39c7("bitops: Optimise get_order()") introduced a compilation warning because "rx_frag_size" is an "ushort" while PAGE_SHIFT here is 16. The commit changed the get_order() to be a multi-line macro where compilers insist to check all statements in the macro even when __builtin_constant_p(rx_frag_size) will return false as "rx_frag_size" is a module parameter. In file included from ./arch/powerpc/include/asm/page_64.h:107, from ./arch/powerpc/include/asm/page.h:242, from ./arch/powerpc/include/asm/mmu.h:132, from ./arch/powerpc/include/asm/lppaca.h:47, from ./arch/powerpc/include/asm/paca.h:17, from ./arch/powerpc/include/asm/current.h:13, from ./include/linux/thread_info.h:21, from ./arch/powerpc/include/asm/processor.h:39, from ./include/linux/prefetch.h:15, from drivers/net/ethernet/emulex/benet/be_main.c:14: drivers/net/ethernet/emulex/benet/be_main.c: In function 'be_rx_cqs_create': ./include/asm-generic/getorder.h:54:9: warning: comparison is always true due to limited range of data type [-Wtype-limits] (((n) < (1UL << PAGE_SHIFT)) ? 0 : \ ^ drivers/net/ethernet/emulex/benet/be_main.c:3138:33: note: in expansion of macro 'get_order' adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE; ^~~~~~~~~ Fix it by moving all of this multi-line macro into a proper function, and killing __get_order() off. [[email protected]: remove __get_order() altogether] [[email protected]: v2] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Fixes:d66acc39c7("bitops: Optimise get_order()") Signed-off-by: Qian Cai <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Cc: David S. Miller <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: David Howells <[email protected]> Cc: Jakub Jelinek <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Bill Wendling <[email protected]> Cc: James Y Knight <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __ASM_GENERIC_GETORDER_H
|
|
#define __ASM_GENERIC_GETORDER_H
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
#include <linux/compiler.h>
|
|
#include <linux/log2.h>
|
|
|
|
/**
|
|
* get_order - Determine the allocation order of a memory size
|
|
* @size: The size for which to get the order
|
|
*
|
|
* Determine the allocation order of a particular sized block of memory. This
|
|
* is on a logarithmic scale, where:
|
|
*
|
|
* 0 -> 2^0 * PAGE_SIZE and below
|
|
* 1 -> 2^1 * PAGE_SIZE to 2^0 * PAGE_SIZE + 1
|
|
* 2 -> 2^2 * PAGE_SIZE to 2^1 * PAGE_SIZE + 1
|
|
* 3 -> 2^3 * PAGE_SIZE to 2^2 * PAGE_SIZE + 1
|
|
* 4 -> 2^4 * PAGE_SIZE to 2^3 * PAGE_SIZE + 1
|
|
* ...
|
|
*
|
|
* The order returned is used to find the smallest allocation granule required
|
|
* to hold an object of the specified size.
|
|
*
|
|
* The result is undefined if the size is 0.
|
|
*/
|
|
static inline __attribute_const__ int get_order(unsigned long size)
|
|
{
|
|
if (__builtin_constant_p(size)) {
|
|
if (!size)
|
|
return BITS_PER_LONG - PAGE_SHIFT;
|
|
|
|
if (size < (1UL << PAGE_SHIFT))
|
|
return 0;
|
|
|
|
return ilog2((size) - 1) - PAGE_SHIFT + 1;
|
|
}
|
|
|
|
size--;
|
|
size >>= PAGE_SHIFT;
|
|
#if BITS_PER_LONG == 32
|
|
return fls(size);
|
|
#else
|
|
return fls64(size);
|
|
#endif
|
|
}
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* __ASM_GENERIC_GETORDER_H */
|