From patchwork Wed Jan 16 00:56:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Turquette X-Patchwork-Id: 1986201 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id B2445DF264 for ; Wed, 16 Jan 2013 01:00:23 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TvHJH-0001qB-PJ; Wed, 16 Jan 2013 00:56:56 +0000 Received: from mail-pb0-f42.google.com ([209.85.160.42]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TvHJC-0001ps-Eq for linux-arm-kernel@lists.infradead.org; Wed, 16 Jan 2013 00:56:51 +0000 Received: by mail-pb0-f42.google.com with SMTP id rp2so384596pbb.1 for ; Tue, 15 Jan 2013 16:56:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:content-type:mime-version:content-transfer-encoding:to :from:in-reply-to:cc:references:message-id:user-agent:subject:date :x-gm-message-state; bh=VAN2j2qy6wF8XjlmJOlA53carPEiL0eiLa4JZ/MQ25Q=; b=V/LpyHcxniE0fNYCUklGpO4WrVbG2wrDWPSEdvv63ro24r/7vasiDBsnU4y0A0Rmwk EEqijlH+xSBBBSf/fzdNhhFKkzb5BdsUUTBlzerXLFKBTxZxQ0vXvJxuJxw6ju5V3Im5 HmqzPGFwD9834VhfmjN/9tEeEMxZ/aEE8FUuKGL+FAnwI/m+fp/jp3l6ZYBuatwJB3aw 8KjaNIhJp7yDOPCQylW8Opa+VdI1TlijX+FVWoLn4rx4r3iDJE+Ib53/IN5huozz0FBF 5LX7S9/PJ7HAoRm6e5s4dieYlty5Gj97sYf8Y/cNX35UZgFdbC7OWR3EJuGN3iJ7d0xR zleg== X-Received: by 10.66.82.198 with SMTP id k6mr246482383pay.53.1358297806041; Tue, 15 Jan 2013 16:56:46 -0800 (PST) Received: from localhost (adsl-69-228-82-185.dsl.pltn13.pacbell.net. [69.228.82.185]) by mx.google.com with ESMTPS id qw8sm11148790pbc.39.2013.01.15.16.56.43 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 15 Jan 2013 16:56:44 -0800 (PST) MIME-Version: 1.0 To: Joe Perches , James Hogan From: Mike Turquette In-Reply-To: <1358274665.2597.11.camel@joe-AO722> References: <1358245685-4392-1-git-send-email-james.hogan@imgtec.com> <1358274665.2597.11.camel@joe-AO722> Message-ID: <20130116005639.8920.45989@quantum> User-Agent: alot/0.3.3+ Subject: Re: [PATCH 1/1] clk-divider: fix is_power_of_two() Date: Tue, 15 Jan 2013 16:56:39 -0800 X-Gm-Message-State: ALoCoQnS3F68BuM3AKQ21ZqgQG3CDqzEFW6RjfVCJ/lyIJmy+KiwWq3pHcWKgnU2oR0+KXKbpwY3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130115_195650_694416_7A63D4AB X-CRM114-Status: GOOD ( 15.94 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.42 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: rnayak@ti.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 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 Cc: Joe Perches Signed-off-by: Mike Turquette [mturquette@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 #include #include +#include /* * 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;