]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
ARM: pxa: fix GPIO double shifts
authorRobert Jarzmik <robert.jarzmik@free.fr>
Mon, 1 Aug 2016 22:01:32 +0000 (00:01 +0200)
committerRobert Jarzmik <robert.jarzmik@free.fr>
Fri, 9 Sep 2016 16:07:59 +0000 (18:07 +0200)
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 <dan.carpenter@oracle.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
arch/arm/mach-pxa/corgi_pm.c
arch/arm/mach-pxa/sharpsl_pm.c
arch/arm/mach-pxa/sharpsl_pm.h
arch/arm/mach-pxa/spitz_pm.c

index d9206811be9b31dd03efae8235ee8d15ec7548e5..c71c483f410eaa94046ed22e3223cb0c52d8f7a9 100644 (file)
@@ -131,16 +131,11 @@ 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;
-
-       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));
-       return ret;
+       return !gpio_get_value(CORGI_GPIO_AC_IN) ||
+               !gpio_get_value(CORGI_GPIO_KEY_INT) ||
+               !gpio_get_value(CORGI_GPIO_WAKEUP);
 }
 
 unsigned long corgipm_read_devdata(int type)
index b80eab9993c5e0d89eedff4aae08fb3ac8ba7ca8..249b7bd5fbc4cf1c2b4b94dbb7a163f9b62a9b39 100644 (file)
@@ -744,7 +744,7 @@ static int sharpsl_off_charge_battery(void)
                time = RCNR;
                while (1) {
                        /* Check if any wakeup event had occurred */
-                       if (sharpsl_pm.machinfo->charger_wakeup() != 0)
+                       if (sharpsl_pm.machinfo->charger_wakeup())
                                return 0;
                        /* Check for timeout */
                        if ((RCNR - time) > SHARPSL_WAIT_CO_TIME)
index 905be6755f040fb390e630bc4f5a4b4caeba2dbc..fa75b6df8134a582ed68254579735a2c414091ac 100644 (file)
@@ -34,7 +34,7 @@ struct sharpsl_charger_machinfo {
 #define SHARPSL_STATUS_LOCK     5
 #define SHARPSL_STATUS_CHRGFULL 6
 #define SHARPSL_STATUS_FATAL    7
-       unsigned long (*charger_wakeup)(void);
+       bool (*charger_wakeup)(void);
        int (*should_wakeup)(unsigned int resume_on_alarm);
        void (*backlight_limit)(int);
        int (*backlight_get_status) (void);
index ea9f9034cb5427c67dc38ea69d7c2d18e6e7e63d..4e64a140252e9ebbe3dd6de75ac6548cb92af2e9 100644 (file)
@@ -165,13 +165,10 @@ 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));
-       return ret;
+       return !gpio_get_value(SPITZ_GPIO_KEY_INT) ||
+               gpio_get_value(SPITZ_GPIO_SYNC);
 }
 
 unsigned long spitzpm_read_devdata(int type)