public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "zhaoxiu.zeng" <zhaoxiu.zeng@gmail.com>
To: Ohad Ben-Cohen <ohad@wizery.com>
Cc: "linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)"
Date: Mon, 7 Dec 2015 23:03:30 +0800	[thread overview]
Message-ID: <56659FC2.1070906@gmail.com> (raw)
In-Reply-To: <CAK=WgbZGX5zCjDbesh2sNToH3zi10K=ggGKyLgDcXga-FZSLjw@mail.gmail.com>

在 2015/12/7 19:08, Ohad Ben-Cohen 写道:
> Hi,
> 
> On Sun, Dec 6, 2015 at 12:33 PM, Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com> wrote:
>>
>> From: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
>>
>> Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
> 
> 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 <linux/hwspinlock.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/log2.h>
 
 #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;
 	}
-- 


  reply	other threads:[~2015-12-07 15:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-06 10:33 [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)" Zhaoxiu Zeng
2015-12-07 11:08 ` Ohad Ben-Cohen
2015-12-07 15:03   ` zhaoxiu.zeng [this message]
2015-12-07 16:16     ` Ohad Ben-Cohen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56659FC2.1070906@gmail.com \
    --to=zhaoxiu.zeng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=ohad@wizery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox