* [PATCH] ARM: pxa: fix GPIO double shifts
@ 2016-07-16 8:23 Robert Jarzmik
2016-07-16 20:55 ` kbuild test robot
0 siblings, 1 reply; 2+ messages in thread
From: Robert Jarzmik @ 2016-07-16 8:23 UTC (permalink / raw)
To: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Russell King
Cc: linux-arm-kernel, linux-kernel, Dan Carpenter
The commit 9bf448c66d4b ("ARM: pxa: use generic gpio operation instead of
gpio register") from Oct 17, 2011, leads to the following static checker
warning:
arch/arm/mach-pxa/spitz_pm.c:172 spitz_charger_wakeup()
warn: double left shift '!gpio_get_value(SPITZ_GPIO_KEY_INT)
<< (1 << ((SPITZ_GPIO_KEY_INT) & 31))'
As Dan reported, the value is shifted three times :
- once by gpio_get_value(), which returns either 0 or BIT(gpio)
- once by the shift operation '<<'
- a last time by GPIO_bit(gpio) which is BIT(gpio)
Therefore the calculation lead to a chained or operator of :
- (1 << gpio) << (1 << gpio) = (2^gpio)^gpio = 2 ^ (gpio * gpio)
It is be sheer luck the former statement works, only because each gpio
used is strictly smaller than 6, and therefore 2^(gpio^2) never
overflows a 32 bits value, and because it is used as a boolean value to
check a gpio activation.
Fixes: 9bf448c66d4b ("ARM: pxa: use generic gpio operation instead of
gpio register")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
arch/arm/mach-pxa/corgi_pm.c | 8 +++-----
arch/arm/mach-pxa/spitz_pm.c | 5 ++---
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/arch/arm/mach-pxa/corgi_pm.c b/arch/arm/mach-pxa/corgi_pm.c
index d9206811be9b..a7bc7e18158e 100644
--- a/arch/arm/mach-pxa/corgi_pm.c
+++ b/arch/arm/mach-pxa/corgi_pm.c
@@ -135,11 +135,9 @@ static unsigned long corgi_charger_wakeup(void)
{
unsigned long ret;
- ret = (!gpio_get_value(CORGI_GPIO_AC_IN) << GPIO_bit(CORGI_GPIO_AC_IN))
- | (!gpio_get_value(CORGI_GPIO_KEY_INT)
- << GPIO_bit(CORGI_GPIO_KEY_INT))
- | (!gpio_get_value(CORGI_GPIO_WAKEUP)
- << GPIO_bit(CORGI_GPIO_WAKEUP));
+ ret = !gpio_get_value(CORGI_GPIO_AC_IN)
+ | !gpio_get_value(CORGI_GPIO_KEY_INT)
+ | !gpio_get_value(CORGI_GPIO_WAKEUP);
return ret;
}
diff --git a/arch/arm/mach-pxa/spitz_pm.c b/arch/arm/mach-pxa/spitz_pm.c
index ea9f9034cb54..5a4c45b5a526 100644
--- a/arch/arm/mach-pxa/spitz_pm.c
+++ b/arch/arm/mach-pxa/spitz_pm.c
@@ -168,9 +168,8 @@ static int spitz_should_wakeup(unsigned int resume_on_alarm)
static unsigned long spitz_charger_wakeup(void)
{
unsigned long ret;
- ret = ((!gpio_get_value(SPITZ_GPIO_KEY_INT)
- << GPIO_bit(SPITZ_GPIO_KEY_INT))
- | gpio_get_value(SPITZ_GPIO_SYNC));
+ ret = !gpio_get_value(SPITZ_GPIO_KEY_INT)
+ | gpio_get_value(SPITZ_GPIO_SYNC);
return ret;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ARM: pxa: fix GPIO double shifts
2016-07-16 8:23 [PATCH] ARM: pxa: fix GPIO double shifts Robert Jarzmik
@ 2016-07-16 20:55 ` kbuild test robot
0 siblings, 0 replies; 2+ messages in thread
From: kbuild test robot @ 2016-07-16 20:55 UTC (permalink / raw)
To: Robert Jarzmik
Cc: kbuild-all, Daniel Mack, Haojian Zhuang, Robert Jarzmik,
Russell King, linux-arm-kernel, linux-kernel, Dan Carpenter
[-- Attachment #1: Type: text/plain, Size: 2020 bytes --]
Hi,
[auto build test WARNING on arm-soc/for-next]
[also build test WARNING on v4.7-rc7 next-20160715]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Robert-Jarzmik/ARM-pxa-fix-GPIO-double-shifts/20160716-163032
base: https://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc.git for-next
config: arm-spitz_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 5.3.1-8) 5.3.1 20160205
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm
All warnings (new ones prefixed by >>):
arch/arm/mach-pxa/spitz_pm.c: In function 'spitz_charger_wakeup':
>> arch/arm/mach-pxa/spitz_pm.c:171:8: warning: suggest parentheses around operand of '!' or change '|' to '||' or '!' to '~' [-Wparentheses]
ret = !gpio_get_value(SPITZ_GPIO_KEY_INT)
^
vim +171 arch/arm/mach-pxa/spitz_pm.c
155 if (PEDR & GPIO_bit(SPITZ_GPIO_KEY_INT))
156 is_resume |= GPIO_bit(SPITZ_GPIO_KEY_INT);
157
158 if (PKSR & GPIO_bit(SPITZ_GPIO_SYNC))
159 is_resume |= GPIO_bit(SPITZ_GPIO_SYNC);
160
161 if (resume_on_alarm && (PEDR & PWER_RTC))
162 is_resume |= PWER_RTC;
163
164 dev_dbg(sharpsl_pm.dev, "is_resume: %x\n", is_resume);
165 return is_resume;
166 }
167
168 static unsigned long spitz_charger_wakeup(void)
169 {
170 unsigned long ret;
> 171 ret = !gpio_get_value(SPITZ_GPIO_KEY_INT)
172 | gpio_get_value(SPITZ_GPIO_SYNC);
173 return ret;
174 }
175
176 unsigned long spitzpm_read_devdata(int type)
177 {
178 switch (type) {
179 case SHARPSL_STATUS_ACIN:
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 19249 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-16 20:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-16 8:23 [PATCH] ARM: pxa: fix GPIO double shifts Robert Jarzmik
2016-07-16 20:55 ` kbuild test robot
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).