From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933122AbbLGPEr (ORCPT ); Mon, 7 Dec 2015 10:04:47 -0500 Received: from mail-pf0-f171.google.com ([209.85.192.171]:33247 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932442AbbLGPEp (ORCPT ); Mon, 7 Dec 2015 10:04:45 -0500 Subject: Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)" To: Ohad Ben-Cohen References: <1449398006-14450-1-git-send-email-zhaoxiu.zeng@gmail.com> Cc: "linux-omap@vger.kernel.org" , "linux-kernel@vger.kernel.org" From: "zhaoxiu.zeng" Message-ID: <56659FC2.1070906@gmail.com> Date: Mon, 7 Dec 2015 23:03:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2015/12/7 19:08, Ohad Ben-Cohen 写道: > Hi, > > On Sun, Dec 6, 2015 at 12:33 PM, Zhaoxiu Zeng wrote: >> >> From: Zeng Zhaoxiu >> >> Signed-off-by: Zeng Zhaoxiu > > Please explain why do you think we should make this change. is_power_of_2 is simple, and faster than "hweightN(x) == 1" on most architectures. And the "& 0xf" operation is unnecessary, we will check whether or not greater than 8 behind. > > Btw, the original code used is_power_of_2, but we thought hweight is > more explicit so it was adopted. > > Thanks, > Ohad. > --- drivers/hwspinlock/omap_hwspinlock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index ad2f8ca..1848a4c 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "hwspinlock_internal.h" @@ -125,7 +126,7 @@ static int omap_hwspinlock_probe(struct platform_device *pdev) goto iounmap_base; /* one of the four lsb's must be set, and nothing else */ - if (hweight_long(i & 0xf) != 1 || i > 8) { + if (!is_power_of_2(i) || i > 8) { ret = -EINVAL; goto iounmap_base; } --