public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)"
@ 2015-12-06 10:33 Zhaoxiu Zeng
  2015-12-07 11:08 ` Ohad Ben-Cohen
  0 siblings, 1 reply; 4+ messages in thread
From: Zhaoxiu Zeng @ 2015-12-06 10:33 UTC (permalink / raw)
  To: ohad, linux-omap; +Cc: linux-kernel, Zeng Zhaoxiu

From: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>

Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
---
 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 & 0xf) || i > 8) {
 		ret = -EINVAL;
 		goto iounmap_base;
 	}
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)"
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Ohad Ben-Cohen @ 2015-12-07 11:08 UTC (permalink / raw)
  To: Zhaoxiu Zeng; +Cc: linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org

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.

Btw, the original code used is_power_of_2, but we thought hweight is
more explicit so it was adopted.

Thanks,
Ohad.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)"
  2015-12-07 11:08 ` Ohad Ben-Cohen
@ 2015-12-07 15:03   ` zhaoxiu.zeng
  2015-12-07 16:16     ` Ohad Ben-Cohen
  0 siblings, 1 reply; 4+ messages in thread
From: zhaoxiu.zeng @ 2015-12-07 15:03 UTC (permalink / raw)
  To: Ohad Ben-Cohen; +Cc: linux-omap@vger.kernel.org, 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 <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;
 	}
-- 


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 04/10] omap_hwspinlock: Replace "hweight_long(i & 0xf) != 1" with "!is_power_of_2(i & 0xf)"
  2015-12-07 15:03   ` zhaoxiu.zeng
@ 2015-12-07 16:16     ` Ohad Ben-Cohen
  0 siblings, 0 replies; 4+ messages in thread
From: Ohad Ben-Cohen @ 2015-12-07 16:16 UTC (permalink / raw)
  To: zhaoxiu.zeng; +Cc: linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org

On Mon, Dec 7, 2015 at 5:03 PM, zhaoxiu.zeng <zhaoxiu.zeng@gmail.com> wrote:
> is_power_of_2 is simple, and faster than "hweightN(x) == 1" on most architectures.

Thanks. I'm not sure that speed is a major concern here, since this
code executes only once during the lifetime of the driver. Readability
is probably more important.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-12-07 16:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2015-12-07 16:16     ` Ohad Ben-Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox