Skip to content

Commit cbedfe1

Browse files
Qian Caitorvalds
authored andcommitted
asm-generic: fix -Wtype-limits compiler warnings
Commit d66acc3 ("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. [akpm@linux-foundation.org: remove __get_order() altogether] [cai@lca.pw: v2] Link: http://lkml.kernel.org/r/1564000166-31428-1-git-send-email-cai@lca.pw Link: http://lkml.kernel.org/r/1563914986-26502-1-git-send-email-cai@lca.pw Fixes: d66acc3 ("bitops: Optimise get_order()") Signed-off-by: Qian Cai <cai@lca.pw> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com> Cc: David S. Miller <davem@davemloft.net> Cc: Arnd Bergmann <arnd@arndb.de> Cc: David Howells <dhowells@redhat.com> Cc: Jakub Jelinek <jakub@redhat.com> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Bill Wendling <morbo@google.com> Cc: James Y Knight <jyknight@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b59b1ba commit cbedfe1

1 file changed

Lines changed: 20 additions & 30 deletions

File tree

‎include/asm-generic/getorder.h‎

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,6 @@
77
#include <linux/compiler.h>
88
#include <linux/log2.h>
99

10-
/*
11-
* Runtime evaluation of get_order()
12-
*/
13-
static inline __attribute_const__
14-
int __get_order(unsigned long size)
15-
{
16-
int order;
17-
18-
size--;
19-
size >>= PAGE_SHIFT;
20-
#if BITS_PER_LONG == 32
21-
order = fls(size);
22-
#else
23-
order = fls64(size);
24-
#endif
25-
return order;
26-
}
27-
2810
/**
2911
* get_order - Determine the allocation order of a memory size
3012
* @size: The size for which to get the order
@@ -43,19 +25,27 @@ int __get_order(unsigned long size)
4325
* to hold an object of the specified size.
4426
*
4527
* The result is undefined if the size is 0.
46-
*
47-
* This function may be used to initialise variables with compile time
48-
* evaluations of constants.
4928
*/
50-
#define get_order(n) \
51-
( \
52-
__builtin_constant_p(n) ? ( \
53-
((n) == 0UL) ? BITS_PER_LONG - PAGE_SHIFT : \
54-
(((n) < (1UL << PAGE_SHIFT)) ? 0 : \
55-
ilog2((n) - 1) - PAGE_SHIFT + 1) \
56-
) : \
57-
__get_order(n) \
58-
)
29+
static inline __attribute_const__ int get_order(unsigned long size)
30+
{
31+
if (__builtin_constant_p(size)) {
32+
if (!size)
33+
return BITS_PER_LONG - PAGE_SHIFT;
34+
35+
if (size < (1UL << PAGE_SHIFT))
36+
return 0;
37+
38+
return ilog2((size) - 1) - PAGE_SHIFT + 1;
39+
}
40+
41+
size--;
42+
size >>= PAGE_SHIFT;
43+
#if BITS_PER_LONG == 32
44+
return fls(size);
45+
#else
46+
return fls64(size);
47+
#endif
48+
}
5949

6050
#endif /* __ASSEMBLY__ */
6151

0 commit comments

Comments
 (0)