linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] clk-divider: fix is_power_of_two()
@ 2013-01-15 10:28 James Hogan
  2013-01-15 18:31 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: James Hogan @ 2013-01-15 10:28 UTC (permalink / raw)
  To: linux-arm-kernel

The macro is_power_of_two() in clk-divider.c was defined as !(i & ~i)
which is always true. Correct it to !(i & (i - 1)).

Also add brackets around the macro arguments in div_mask and
is_power_of_two, as well as around the is_power_of_two expression as a
whole to avoid any future operator precedence problems.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Mike Turquette <mturquette@linaro.org>
---
I haven't tested this other than with a couple of compile time asserts.

 drivers/clk/clk-divider.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index a9204c6..13bca0c 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -29,8 +29,8 @@
 
 #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
 
-#define div_mask(d)	((1 << (d->width)) - 1)
-#define is_power_of_two(i)	!(i & ~i)
+#define div_mask(d)	((1 << ((d)->width)) - 1)
+#define is_power_of_two(i)	(!((i) & ((i) - 1)))
 
 static unsigned int _get_table_maxdiv(const struct clk_div_table *table)
 {
-- 
1.7.7.6

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

* [PATCH 1/1] clk-divider: fix is_power_of_two()
  2013-01-15 10:28 [PATCH 1/1] clk-divider: fix is_power_of_two() James Hogan
@ 2013-01-15 18:31 ` Joe Perches
  2013-01-16  0:56   ` Mike Turquette
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2013-01-15 18:31 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 2013-01-15 at 10:28 +0000, James Hogan wrote:
> The macro is_power_of_two() in clk-divider.c was defined as !(i & ~i)
> which is always true. Correct it to !(i & (i - 1)).
[]
> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
[]
> @@ -29,8 +29,8 @@
[]
> -#define div_mask(d)	((1 << (d->width)) - 1)
> -#define is_power_of_two(i)	!(i & ~i)
> +#define div_mask(d)	((1 << ((d)->width)) - 1)
> +#define is_power_of_two(i)	(!((i) & ((i) - 1)))

Use is_power_of_2 in log2.h instead?

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

* [PATCH 1/1] clk-divider: fix is_power_of_two()
  2013-01-15 18:31 ` Joe Perches
@ 2013-01-16  0:56   ` Mike Turquette
  2013-01-16  9:27     ` James Hogan
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Turquette @ 2013-01-16  0:56 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting Joe Perches (2013-01-15 10:31:05)
> On Tue, 2013-01-15 at 10:28 +0000, James Hogan wrote:
> > The macro is_power_of_two() in clk-divider.c was defined as !(i & ~i)
> > which is always true. Correct it to !(i & (i - 1)).
> []
> > diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> []
> > @@ -29,8 +29,8 @@
> []
> > -#define div_mask(d)  ((1 << (d->width)) - 1)
> > -#define is_power_of_two(i)   !(i & ~i)
> > +#define div_mask(d)  ((1 << ((d)->width)) - 1)
> > +#define is_power_of_two(i)   (!((i) & ((i) - 1)))
> 
> Use is_power_of_2 in log2.h instead?

Both are fine suggestions.  How about I apply the below patch?

Thanks,
Mike



>From 54c6c9e5f61693effbe6e4fb28ef9f2f9b3d7a23 Mon Sep 17 00:00:00 2001
From: James Hogan <james.hogan@imgtec.com>
Date: Tue, 15 Jan 2013 10:28:05 +0000
Subject: [PATCH] clk-divider: fix macros

The macro is_power_of_two() in clk-divider.c was defined as !(i & ~i)
which is always true.  Instead use is_power_of_2() from log2.h.

Also add brackets around the macro arguments in div_mask to avoid any
future operator precedence problems.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
[mturquette at linaro.org: use log2.h per Joe Perches; update changelog]
---
 drivers/clk/clk-divider.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index a9204c6..68b4021 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -16,6 +16,7 @@
 #include <linux/io.h>
 #include <linux/err.h>
 #include <linux/string.h>
+#include <linux/log2.h>
 
 /*
  * DOC: basic adjustable divider clock that cannot gate
@@ -29,8 +30,7 @@
 
 #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
 
-#define div_mask(d)	((1 << (d->width)) - 1)
-#define is_power_of_two(i)	!(i & ~i)
+#define div_mask(d)	((1 << ((d)->width)) - 1)
 
 static unsigned int _get_table_maxdiv(const struct clk_div_table *table)
 {
@@ -137,7 +137,7 @@ static bool _is_valid_table_div(const struct clk_div_table *table,
 static bool _is_valid_div(struct clk_divider *divider, unsigned int div)
 {
 	if (divider->flags & CLK_DIVIDER_POWER_OF_TWO)
-		return is_power_of_two(div);
+		return is_power_of_2(div);
 	if (divider->table)
 		return _is_valid_table_div(divider->table, div);
 	return true;
-- 
1.7.10.4

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

* [PATCH 1/1] clk-divider: fix is_power_of_two()
  2013-01-16  0:56   ` Mike Turquette
@ 2013-01-16  9:27     ` James Hogan
  0 siblings, 0 replies; 4+ messages in thread
From: James Hogan @ 2013-01-16  9:27 UTC (permalink / raw)
  To: linux-arm-kernel

On 16/01/13 00:56, Mike Turquette wrote:
> Quoting Joe Perches (2013-01-15 10:31:05)
>> On Tue, 2013-01-15 at 10:28 +0000, James Hogan wrote:
>>> The macro is_power_of_two() in clk-divider.c was defined as !(i & ~i)
>>> which is always true. Correct it to !(i & (i - 1)).
>> []
>>> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
>> []
>>> @@ -29,8 +29,8 @@
>> []
>>> -#define div_mask(d)  ((1 << (d->width)) - 1)
>>> -#define is_power_of_two(i)   !(i & ~i)
>>> +#define div_mask(d)  ((1 << ((d)->width)) - 1)
>>> +#define is_power_of_two(i)   (!((i) & ((i) - 1)))
>>
>> Use is_power_of_2 in log2.h instead?
> 
> Both are fine suggestions.  How about I apply the below patch?

Looks good to me, thanks for taking care of the log.h change.

Cheers
James

> From 54c6c9e5f61693effbe6e4fb28ef9f2f9b3d7a23 Mon Sep 17 00:00:00 2001
> From: James Hogan <james.hogan@imgtec.com>
> Date: Tue, 15 Jan 2013 10:28:05 +0000
> Subject: [PATCH] clk-divider: fix macros
> 
> The macro is_power_of_two() in clk-divider.c was defined as !(i & ~i)
> which is always true.  Instead use is_power_of_2() from log2.h.
> 
> Also add brackets around the macro arguments in div_mask to avoid any
> future operator precedence problems.
> 
> Signed-off-by: James Hogan <james.hogan@imgtec.com>
> Cc: Joe Perches <joe@perches.com>
> Signed-off-by: Mike Turquette <mturquette@linaro.org>
> [mturquette at linaro.org: use log2.h per Joe Perches; update changelog]
> ---
>  drivers/clk/clk-divider.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> index a9204c6..68b4021 100644
> --- a/drivers/clk/clk-divider.c
> +++ b/drivers/clk/clk-divider.c
> @@ -16,6 +16,7 @@
>  #include <linux/io.h>
>  #include <linux/err.h>
>  #include <linux/string.h>
> +#include <linux/log2.h>
>  
>  /*
>   * DOC: basic adjustable divider clock that cannot gate
> @@ -29,8 +30,7 @@
>  
>  #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
>  
> -#define div_mask(d)	((1 << (d->width)) - 1)
> -#define is_power_of_two(i)	!(i & ~i)
> +#define div_mask(d)	((1 << ((d)->width)) - 1)
>  
>  static unsigned int _get_table_maxdiv(const struct clk_div_table *table)
>  {
> @@ -137,7 +137,7 @@ static bool _is_valid_table_div(const struct clk_div_table *table,
>  static bool _is_valid_div(struct clk_divider *divider, unsigned int div)
>  {
>  	if (divider->flags & CLK_DIVIDER_POWER_OF_TWO)
> -		return is_power_of_two(div);
> +		return is_power_of_2(div);
>  	if (divider->table)
>  		return _is_valid_table_div(divider->table, div);
>  	return true;
> 

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

end of thread, other threads:[~2013-01-16  9:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-15 10:28 [PATCH 1/1] clk-divider: fix is_power_of_two() James Hogan
2013-01-15 18:31 ` Joe Perches
2013-01-16  0:56   ` Mike Turquette
2013-01-16  9:27     ` James Hogan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).