Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp107602ybb; Thu, 19 Mar 2020 12:30:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs2klK6intTGxQsp0zBFK+Q6cCLUiANFFmJhWwYXLdKidA9r1GK000D/ybLiZHlnAQx+xxL X-Received: by 2002:aca:ed54:: with SMTP id l81mr3732248oih.69.1584646244997; Thu, 19 Mar 2020 12:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584646244; cv=none; d=google.com; s=arc-20160816; b=v6iQA/FlJxLetq4+4cLQYsdWolhSVLuv1OciSRFFrOK2cmOPZ/4znZc3cBJ6aCBt6q 0V1dsjojSmEcmBZa6k6wPel0G4uLrxZToVnfoTv9qn24eQUl3rICPiozWx1jUgaLIGGN K9rBrUD8JEQYrW2YZ/IEglJtlFyuMVH9Fj1R+9V2WSteac8nWIsKwcpBWArDZQegTpru vEsxmqgRjVIIw5erulvUo/rYwP/lBblRI8eZYOA8EbSixbEB+SNeb+AMtQzABzRy43CN LWeXJQ15jZiXdJM1++JvMu/d60AnDRv4ovcvmDe+3ci7uuaRZ9DHTPrBGQZ2FyPSG4u4 65oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dCY4pcQQ/duoAuYSGzQpiC4wbuyHn31kQSsl0gZlWOc=; b=Ye5qpTOohr1WptIPiCVoRzu1YogG1LBgOSMzBThAqhwI6ohBnB38u9nRtmVGkJzzv+ XPAJvyVO99Z7Wf/HNG1R+AUs/qzPrre8p5BHHJrKVuB3iYoCERJvzjv5bKiJ12KAWf/5 Kk2uWZyL/9hBfHA2jLC+ouSxjZZzSYABm7vdwn47fkLCFDB6Ix576nLZPcNfPUCJIGnn hrjYmZFZsZ9aSE4P/kn1p6cIleBljA5JS1HhrzF9erByS7HmK/s6o/9mexL0XnpFQZE6 ZdSbHAYBGl3TSk373pKPjfUPOLgBFSSVHcuUmZhmm57FmWOohcdJ7NmYe+CBqOXyaC1f 6bGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13si1690708otm.111.2020.03.19.12.30.32; Thu, 19 Mar 2020 12:30:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727545AbgCST3n (ORCPT + 99 others); Thu, 19 Mar 2020 15:29:43 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:44755 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727654AbgCST3F (ORCPT ); Thu, 19 Mar 2020 15:29:05 -0400 Received: by mail-qk1-f195.google.com with SMTP id j4so4361083qkc.11; Thu, 19 Mar 2020 12:29:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dCY4pcQQ/duoAuYSGzQpiC4wbuyHn31kQSsl0gZlWOc=; b=kbulQfOLEr2KCq3sg9vk+/sXQeyjFqankmDJlfS0zRCmK8QZpj8BVxf2wlKbXVrCka ctTflcgQDzYTwlybcF4TxZVoxzSDVZSpLkwu/DZCYrWe9FWpBEQrgGWI0w0YsbTCHqFa pQYLHjls6S7N1npAvQum60nuceatdbdOqWb76GuQaWqN/7/stVAJbvDfvZAzIE0W7WVO U5+3hCfCUjyHUy2WjaMaxXc1nxqkvqiGnFTWArjiPbPIeI3I0HKGGgGMjjQ+52aQrPpE ivqZzD5D7fm67Wh+ie+ZfE13AjCqnaIIT+Zr/aHpgiiR3fBEDy6WL8Wz0/WSuIfDm2G/ 6VCQ== X-Gm-Message-State: ANhLgQ3uK9uTObmh89Z8mV4C/r2EUvnOJPu07koNStGlOWlabMu58B1j Z7AHIe3Z0WXgcIthnsWfwuM= X-Received: by 2002:a37:b305:: with SMTP id c5mr4646140qkf.213.1584646144376; Thu, 19 Mar 2020 12:29:04 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id x89sm2292649qtd.43.2020.03.19.12.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 12:29:03 -0700 (PDT) From: Arvind Sankar To: Ard Biesheuvel Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/14] efi/gop: Use helper macros for find_bits Date: Thu, 19 Mar 2020 15:28:49 -0400 Message-Id: <20200319192855.29876-9-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200319192855.29876-1-nivedita@alum.mit.edu> References: <20200319192855.29876-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/firmware/efi/libstub/gop.c | 26 ++++++++------------------ 1 file 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 #include #include #include @@ -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 -- 2.24.1