linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: mka@chromium.org (Matthias Kaehlcke)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v1] soc: rockchip: power-domain: Fix clang warning about negative shift count
Date: Fri, 10 Mar 2017 18:21:53 -0800	[thread overview]
Message-ID: <20170311022153.139362-1-mka@chromium.org> (raw)

The following warning is generated when building with clang:

drivers/soc/rockchip/pm_domains.c:726:22: error: shift count is negative [-Werror,-Wshift-count-negative]
        [RK3399_PD_TCPD0]       = DOMAIN_RK3399(8, 8, -1, false),
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/soc/rockchip/pm_domains.c:101:2: note: expanded from macro 'DOMAIN_RK3399'
        DOMAIN(pwr, status, req, req, req, wakeup)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/soc/rockchip/pm_domains.c:88:27: note: expanded from macro 'DOMAIN'
        .req_mask = (req >= 0) ? BIT(req) : 0,          \
                                 ^~~~~~~~
include/linux/bitops.h:6:24: note: expanded from macro 'BIT'

The BIT macro is evaluated with the negative value -1, even though the
resulting value would not be assigned. To fix this we only pass values
between 0 and 63 to BIT(). Unfortunately this means that we lose the
benefit of the compiler checking for out of bounds errors.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 drivers/soc/rockchip/pm_domains.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c
index 1c78c42416c6..6f2bb1222992 100644
--- a/drivers/soc/rockchip/pm_domains.c
+++ b/drivers/soc/rockchip/pm_domains.c
@@ -77,13 +77,15 @@ struct rockchip_pmu {
 
 #define to_rockchip_pd(gpd) container_of(gpd, struct rockchip_pm_domain, genpd)
 
+#define RK_MASK(bit) ((bit >= 0) ? BIT(bit & 0x3f) : 0)
+
 #define DOMAIN(pwr, status, req, idle, ack, wakeup)	\
-{						\
-	.pwr_mask = (pwr >= 0) ? BIT(pwr) : 0,		\
-	.status_mask = (status >= 0) ? BIT(status) : 0,	\
-	.req_mask = (req >= 0) ? BIT(req) : 0,		\
-	.idle_mask = (idle >= 0) ? BIT(idle) : 0,	\
-	.ack_mask = (ack >= 0) ? BIT(ack) : 0,		\
+{							\
+	.pwr_mask = RK_MASK(pwr),			\
+	.status_mask = RK_MASK(status),			\
+	.req_mask = RK_MASK(req),			\
+	.idle_mask = RK_MASK(idle),			\
+	.ack_mask = RK_MASK(ack),			\
 	.active_wakeup = wakeup,			\
 }
 
-- 
2.12.0.246.ga2ecc84866-goog

             reply	other threads:[~2017-03-11  2:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-11  2:21 Matthias Kaehlcke [this message]
2017-03-11 12:03 ` [PATCH v1] soc: rockchip: power-domain: Fix clang warning about negative shift count Heiko Stuebner
2017-03-13 17:22   ` Matthias Kaehlcke
2017-03-13 18:49     ` Matthias Kaehlcke

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=20170311022153.139362-1-mka@chromium.org \
    --to=mka@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).