Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp167675ybb; Thu, 19 Mar 2020 19:01:22 -0700 (PDT) X-Google-Smtp-Source: ADFU+vudPfr23lI9gX2trIVqvS1HoFCTuIoSwI5tZtzTNPSLvBaoaJoKHRpVYAoAA5EFlMTM9V5+ X-Received: by 2002:a05:6830:1249:: with SMTP id s9mr4787577otp.359.1584669682060; Thu, 19 Mar 2020 19:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584669682; cv=none; d=google.com; s=arc-20160816; b=pkZcP9dLp+f/OTJt7uegb+ZZV8zb5J4lA3fhutiC7NGTdRqk7rnnFqFssx9yl6JmZ0 UkBq8toVNB3DnGtIWAOcXcJniqgtLjB4vX1VR/xC5Z7x/14RzasTFzllMxvPayXtzwHq qpQ7jC9+sMK06TkN3w1BWWgv6RujqQkme4jXrvKwwDD7Iz0jTNIZPl4KIbCyBJwwa+H+ u/wNkxEJXZ9GHrXrvp0MntyBht75OYfzLf2N9ToXBxTzJleqbHOMKYWOjnpmVaKdDR69 HohX323hTftaAU3RMEkGyJQuYnitcSWaNn25bMGiJk+a+ciglV9xaFeuUNNE99wSEogj Xs9g== 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=DtBQWdBkkqe3fhdfURPHLDD1XuJ8YhVpNyF/SeTjimhW8efXrMxk//NWTezRVAYwR3 /ro1nG/lsbW5CRe6/2T0IQYt00TE5kJhRAIlXLyVIorFoNySYn9yqto7rWs8e/8pzoO8 0xPjZtHcZu5lA3CsWQGUwLCj/aTSgXGQvLcYXMSVQa+JD6cd6+LEO4pc65ZWuuoZHryQ epyRni4QM5V6Mmqdv7bdjfKDUU8noLuWFTCM60RlnkmurIdeg5NivTErIm3645GVJQls GWt4c0F1xX5wa/bew2oo9vhoNvXLlPrBvzK7qXeDAjKWzO7gYKCk2D2bQnNqO5qUiHQM bpTg== 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 66si2076826otx.151.2020.03.19.19.01.09; Thu, 19 Mar 2020 19:01:22 -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 S1727534AbgCTCAm (ORCPT + 99 others); Thu, 19 Mar 2020 22:00:42 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:43113 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727384AbgCTCAi (ORCPT ); Thu, 19 Mar 2020 22:00:38 -0400 Received: by mail-qt1-f193.google.com with SMTP id l13so3727588qtv.10; Thu, 19 Mar 2020 19:00:37 -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=Tt/3n3QqhhdMgCk69MkeRisJ3ybSs4PBEUsaSkZQpKX9/i8YuWbIlvcW/+mqkpfyXM AwEUj9M2++iIWyYHP8rbvs+ZON38s6UMu3AVAua9eZsk+VMdU2xsXaf6kF96ZDc3uyZe kVDXq0opJT3NYsUhNjjcRCk5XT+QlaH/C2VOID7sCaIVWOyLLvgbHhCBXYAi6Oloqnyd F+JKzrGI2hcnv93Jkm6OPurc7BpSzx4xbMIMvRiL1p08/T8zKT2EXfbgTBGcm3ifAL77 MCBzgydmZ4GKjKyYDU3CmKIMIw2RH+GjV1cNgxsNA72YuRkERlXQ9rvITlBOPbGOpsdd BCfw== X-Gm-Message-State: ANhLgQ0uH3+wM+1Ds+u6pG/6JDTmOxhCzAvP62MM3dLRviiPGItZNBpJ F/pTAhzu/H+78PLdzIO8iyY= X-Received: by 2002:ac8:545a:: with SMTP id d26mr6011921qtq.238.1584669637023; Thu, 19 Mar 2020 19:00:37 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id n46sm3342198qtb.48.2020.03.19.19.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 19:00:36 -0700 (PDT) From: Arvind Sankar To: Ard Biesheuvel Cc: Hans de Goede , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 08/14] efi/gop: Use helper macros for find_bits Date: Thu, 19 Mar 2020 22:00:22 -0400 Message-Id: <20200320020028.1936003-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