summaryrefslogtreecommitdiff
path: root/drivers/firmware/efi/libstub/gop.c
diff options
context:
space:
mode:
authorArvind Sankar <nivedita@alum.mit.edu>2020-03-19 22:00:22 -0400
committerArd Biesheuvel <ardb@kernel.org>2020-04-23 20:15:06 +0200
commit9867fc9de6a6a7a54edb2c43540c6db226e84a14 (patch)
tree5b72b1c7bcc5446d069a8bad42e3bd8b79363b08 /drivers/firmware/efi/libstub/gop.c
parentf1d1853bdbcfb2d00ae0b850baf26d87e6d363d8 (diff)
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 <nivedita@alum.mit.edu> Link: https://lore.kernel.org/r/20200320020028.1936003-9-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Diffstat (limited to 'drivers/firmware/efi/libstub/gop.c')
-rw-r--r--drivers/firmware/efi/libstub/gop.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c
index 7b0baf9a912f..8bf424f35759 100644
--- a/drivers/firmware/efi/libstub/gop.c
+++ b/drivers/firmware/efi/libstub/gop.c
@@ -5,6 +5,7 @@
*
* ----------------------------------------------------------------------- */
+#include <linux/bitops.h>
#include <linux/efi.h>
#include <linux/screen_info.h>
#include <asm/efi.h>
@@ -12,27 +13,16 @@
#include "efistub.h"
-static void find_bits(unsigned long mask, u8 *pos, u8 *size)
+static void find_bits(u32 mask, u8 *pos, u8 *size)
{
- u8 first, len;
-
- first = 0;
- len = 0;
-
- if (mask) {
- while (!(mask & 0x1)) {
- mask = mask >> 1;
- first++;
- }
-
- while (mask & 0x1) {
- mask = mask >> 1;
- len++;
- }
+ if (!mask) {
+ *pos = *size = 0;
+ return;
}
- *pos = first;
- *size = len;
+ /* UEFI spec guarantees that the set bits are contiguous */
+ *pos = __ffs(mask);
+ *size = __fls(mask) - *pos + 1;
}
static void