mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Hogan <james.hogan@imgtec.com>
To: <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Cc: James Hogan <james.hogan@imgtec.com>,
	Mike Turquette <mturquette@linaro.org>
Subject: [PATCH 1/1] clk-divider: fix is_power_of_two()
Date: Tue, 15 Jan 2013 10:28:05 +0000	[thread overview]
Message-ID: <1358245685-4392-1-git-send-email-james.hogan@imgtec.com> (raw)

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



             reply	other threads:[~2013-01-15 10:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-15 10:28 James Hogan [this message]
2013-01-15 18:31 ` Joe Perches
2013-01-16  0:56   ` Mike Turquette
2013-01-16  9:27     ` James Hogan

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=1358245685-4392-1-git-send-email-james.hogan@imgtec.com \
    --to=james.hogan@imgtec.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@linaro.org \
    /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

all inboxes | Powered by JetHome®