Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3fc2579e authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds
Browse files

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: default avatarMatthew Wilcox <willy@infradead.org>
Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e6310f0f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -391,9 +391,9 @@ static inline unsigned long __fls(unsigned long x)
	return fls64(x) - 1;
}

static inline int fls(int x)
static inline int fls(unsigned int x)
{
	return fls64((unsigned int) x);
	return fls64(x);
}

/*
+2 −2
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@ static inline __attribute__ ((const)) int clz(unsigned int x)
	return res;
}

static inline int constant_fls(int x)
static inline int constant_fls(unsigned int x)
{
	int r = 32;

@@ -312,7 +312,7 @@ static inline int constant_fls(int x)
 * @result: [1-32]
 * fls(1) = 1, fls(0x80000000) = 32, fls(0) = 0
 */
static inline __attribute__ ((const)) int fls(unsigned long x)
static inline __attribute__ ((const)) int fls(unsigned int x)
{
	if (__builtin_constant_p(x))
	       return constant_fls(x);
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ static inline unsigned long __ffs(unsigned long x)
 * This is defined the same way as ffs.
 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
 */
static inline int fls(int x)
static inline int fls(unsigned int x)
{
	if (!x)
		return 0;
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ static __always_inline unsigned long __ffs(unsigned long x)
/*
 * asm-generic/bitops/fls.h
 */
static __always_inline int fls(int x)
static __always_inline int fls(unsigned int x)
{
	asm volatile(
		"ff1 %0\n"
+1 −1
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ static inline long ffz(int x)
 * This is defined the same way as ffs.
 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
 */
static inline int fls(int x)
static inline int fls(unsigned int x)
{
	int r;

Loading