Skip to content

Commit 9867fc9

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/gop: Use helper macros for find_bits
Use the __ffs/__fls macros to calculate the position and size of the mask. Correct type of mask to u32 instead of unsigned long. Signed-off-by: Arvind Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent f1d1853 commit 9867fc9

File tree

1 file changed

+8
-18
lines changed
  • drivers/firmware/efi/libstub

1 file changed

+8
-18
lines changed

drivers/firmware/efi/libstub/gop.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,24 @@
55
*
66
* ----------------------------------------------------------------------- */
77

8+
#include <linux/bitops.h>
89
#include <linux/efi.h>
910
#include <linux/screen_info.h>
1011
#include <asm/efi.h>
1112
#include <asm/setup.h>
1213

1314
#include "efistub.h"
1415

15-
static void find_bits(unsigned long mask, u8 *pos, u8 *size)
16+
static void find_bits(u32 mask, u8 *pos, u8 *size)
1617
{
17-
u8 first, len;
18-
19-
first = 0;
20-
len = 0;
21-
22-
if (mask) {
23-
while (!(mask & 0x1)) {
24-
mask = mask >> 1;
25-
first++;
26-
}
27-
28-
while (mask & 0x1) {
29-
mask = mask >> 1;
30-
len++;
31-
}
18+
if (!mask) {
19+
*pos = *size = 0;
20+
return;
3221
}
3322

34-
*pos = first;
35-
*size = len;
23+
/* UEFI spec guarantees that the set bits are contiguous */
24+
*pos = __ffs(mask);
25+
*size = __fls(mask) - *pos + 1;
3626
}
3727

3828
static void

0 commit comments

Comments
 (0)