From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932421AbcHISwX (ORCPT ); Tue, 9 Aug 2016 14:52:23 -0400 Received: from smtp08.smtpout.orange.fr ([80.12.242.130]:30333 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932207AbcHISwW (ORCPT ); Tue, 9 Aug 2016 14:52:22 -0400 X-ME-Helo: belgarion X-ME-Auth: amFyem1pay5yb2JlcnRAb3JhbmdlLmZy X-ME-Date: Tue, 09 Aug 2016 20:52:19 +0200 X-ME-IP: 109.222.82.242 From: Robert Jarzmik To: Daniel Mack Cc: Haojian Zhuang , Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joe Perches Subject: Re: [PATCH v4] ARM: pxa: fix GPIO double shifts References: <1470088892-31373-1-git-send-email-robert.jarzmik@free.fr> X-URL: http://belgarath.falguerolles.org/ Date: Tue, 09 Aug 2016 20:52:17 +0200 In-Reply-To: <1470088892-31373-1-git-send-email-robert.jarzmik@free.fr> (Robert Jarzmik's message of "Tue, 2 Aug 2016 00:01:32 +0200") Message-ID: <878tw5vkpq.fsf@belgarion.home> User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Robert Jarzmik writes: > 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 Queued into pxa/for-next. -- Robert