Message ID | 1358245685-4392-1-git-send-email-james.hogan@imgtec.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
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?
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) {
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(-)