Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1285526

Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)"

From "zhaoxiu.zeng" <zhaoxiu.zeng@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)"
Date 2015-12-07 16:10 +0100
Message-ID <qD5Ao-6co-53@gated-at.bofh.it> (permalink)
References <qCETv-5Ko-5@gated-at.bofh.it> <qD1Q5-3GX-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


在 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;
 	}
-- 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)" Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com> - 2015-12-06 11:40 +0100
  Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) !=  1" with "!is_power_of_2(i & 0xf)" Ohad Ben-Cohen <ohad@wizery.com> - 2015-12-07 12:10 +0100
    Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) !=  1" with "!is_power_of_2(i & 0xf)" "zhaoxiu.zeng" <zhaoxiu.zeng@gmail.com> - 2015-12-07 16:10 +0100
      Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) !=  1" with "!is_power_of_2(i & 0xf)" Ohad Ben-Cohen <ohad@wizery.com> - 2015-12-07 17:20 +0100

csiph-web