Skip to content

Commit 3fc2579

Browse files
Matthew Wilcoxtorvalds
authored andcommitted
fls: change parameter to unsigned int
When testing in userspace, UBSAN pointed out that shifting into the sign bit is undefined behaviour. It doesn't really make sense to ask for the highest set bit of a negative value, so just turn the argument type into an unsigned int. Some architectures (eg ppc) already had it declared as an unsigned int, so I don't expect too many problems. Link: http://lkml.kernel.org/r/20181105221117.31828-1-willy@infradead.org Signed-off-by: Matthew Wilcox <willy@infradead.org> Acked-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Cc: <linux-arch@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e6310f0 commit 3fc2579

16 files changed

Lines changed: 19 additions & 20 deletions

File tree

‎arch/alpha/include/asm/bitops.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ static inline unsigned long __fls(unsigned long x)
391391
return fls64(x) - 1;
392392
}
393393

394-
static inline int fls(int x)
394+
static inline int fls(unsigned int x)
395395
{
396-
return fls64((unsigned int) x);
396+
return fls64(x);
397397
}
398398

399399
/*

‎arch/arc/include/asm/bitops.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static inline __attribute__ ((const)) int clz(unsigned int x)
278278
return res;
279279
}
280280

281-
static inline int constant_fls(int x)
281+
static inline int constant_fls(unsigned int x)
282282
{
283283
int r = 32;
284284

@@ -312,7 +312,7 @@ static inline int constant_fls(int x)
312312
* @result: [1-32]
313313
* fls(1) = 1, fls(0x80000000) = 32, fls(0) = 0
314314
*/
315-
static inline __attribute__ ((const)) int fls(unsigned long x)
315+
static inline __attribute__ ((const)) int fls(unsigned int x)
316316
{
317317
if (__builtin_constant_p(x))
318318
return constant_fls(x);

‎arch/c6x/include/asm/bitops.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static inline unsigned long __ffs(unsigned long x)
5454
* This is defined the same way as ffs.
5555
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
5656
*/
57-
static inline int fls(int x)
57+
static inline int fls(unsigned int x)
5858
{
5959
if (!x)
6060
return 0;

‎arch/csky/include/asm/bitops.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static __always_inline unsigned long __ffs(unsigned long x)
4040
/*
4141
* asm-generic/bitops/fls.h
4242
*/
43-
static __always_inline int fls(int x)
43+
static __always_inline int fls(unsigned int x)
4444
{
4545
asm volatile(
4646
"ff1 %0\n"

‎arch/hexagon/include/asm/bitops.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static inline long ffz(int x)
211211
* This is defined the same way as ffs.
212212
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
213213
*/
214-
static inline int fls(int x)
214+
static inline int fls(unsigned int x)
215215
{
216216
int r;
217217

‎arch/ia64/include/asm/bitops.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ ia64_fls (unsigned long x)
388388
* Find the last (most significant) bit set. Returns 0 for x==0 and
389389
* bits are numbered from 1..32 (e.g., fls(9) == 4).
390390
*/
391-
static inline int
392-
fls (int t)
391+
static inline int fls(unsigned int t)
393392
{
394393
unsigned long x = t & 0xffffffffu;
395394

‎arch/m68k/include/asm/bitops.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static inline unsigned long __ffs(unsigned long x)
502502
/*
503503
* fls: find last bit set.
504504
*/
505-
static inline int fls(int x)
505+
static inline int fls(unsigned int x)
506506
{
507507
int cnt;
508508

‎arch/mips/include/asm/bitops.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static inline unsigned long __ffs(unsigned long word)
555555
* This is defined the same way as ffs.
556556
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
557557
*/
558-
static inline int fls(int x)
558+
static inline int fls(unsigned int x)
559559
{
560560
int r;
561561

‎arch/openrisc/include/asm/bitops/fls.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#ifdef CONFIG_OPENRISC_HAVE_INST_FL1
1717

18-
static inline int fls(int x)
18+
static inline int fls(unsigned int x)
1919
{
2020
int ret;
2121

‎arch/parisc/include/asm/bitops.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static __inline__ int ffs(int x)
188188
* fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
189189
*/
190190

191-
static __inline__ int fls(int x)
191+
static __inline__ int fls(unsigned int x)
192192
{
193193
int ret;
194194
if (!x)

0 commit comments

Comments
 (0)