From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751738AbcGaUou (ORCPT ); Sun, 31 Jul 2016 16:44:50 -0400 Received: from smtprelay0226.hostedemail.com ([216.40.44.226]:41131 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751145AbcGaUos (ORCPT ); Sun, 31 Jul 2016 16:44:48 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::,RULES_HIT:41:355:379:541:599:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1543:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2198:2199:2200:2201:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3871:3872:3874:4031:4043:4321:4362:4385:4605:5007:7875:7903:10004:10400:10848:11026:11232:11473:11658:11783:11914:12043:12048:12296:12438:12517:12519:12740:13161:13229:13439:13894:13972:14181:14659:14721:21080:30054:30064:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: roof63_80dacb21ba74b X-Filterd-Recvd-Size: 4129 Message-ID: <1469997882.3998.136.camel@perches.com> Subject: Re: [PATCH v3] ARM: pxa: fix GPIO double shifts From: Joe Perches To: Robert Jarzmik , Daniel Mack , Haojian Zhuang , Russell King Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Sun, 31 Jul 2016 13:44:42 -0700 In-Reply-To: <1469967435-23436-1-git-send-email-robert.jarzmik@free.fr> References: <1469967435-23436-1-git-send-email-robert.jarzmik@free.fr> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2016-07-31 at 14:17 +0200, Robert Jarzmik wrote: > 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. > > As the xxx_charger_wakeup() functions are used as a true/false detection > mechanism, take that opportunity to change their prototypes from integer > return value to boolean one. > > Fixes: 9bf448c66d4b ("ARM: pxa: use generic gpio operation instead of > gpio register") > Reported-by: Dan Carpenter > Cc: Joe Perches > Signed-off-by: Robert Jarzmik > --- > Since v1: replaced binary ORs with logical ORs after assembly comparison > Since v2: changed charger_wakeup prototype to bool foo() Thanks Robert trivially: > diff --git a/arch/arm/mach-pxa/corgi_pm.c b/arch/arm/mach-pxa/corgi_pm.c [] > @@ -131,15 +131,13 @@ static int corgi_should_wakeup(unsigned int resume_on_alarm) >   return is_resume; >  } >   > -static unsigned long corgi_charger_wakeup(void) > +static bool corgi_charger_wakeup(void) >  { > - unsigned long ret; > + bool 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); These might be better without the automatic use of ret return !gpio_get_value(CORGI_GPIO_AC_IN) ||        !gpio_get_value(CORGI_GPIO_KEY_INT) ||        !gpio_get_value(CORGI_GPIO_WAKEUP); and > diff --git a/arch/arm/mach-pxa /spitz_pm.c b/arch/arm/mach-pxa/spitz_pm.c [] > @@ -165,12 +165,12 @@ static int spitz_should_wakeup(unsigned int resume_on_alarm) >   return is_resume; >  } >   > -static unsigned long spitz_charger_wakeup(void) > +static bool 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)); > + bool ret; > + > + ret = !gpio_get_value(SPITZ_GPIO_KEY_INT) > + || gpio_get_value(SPITZ_GPIO_SYNC); >   return ret; >  } return !gpio_get_value(SPITZ_GPIO_KEY_INT) || gpio_get_value(SPITZ_GPIO_SYNC);