Input: tca8418_keypad - hide gcc-4.9 -Wmaybe-uninitialized warning
authorArnd Bergmann <arnd@arndb.de>
Wed, 26 Oct 2016 22:55:02 +0000 (15:55 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 26 Oct 2016 23:01:18 +0000 (16:01 -0700)
Older versions of gcc warn about the tca8418_irq_handler function
as they can't keep track of the variable assignment inside of the
loop when using the -Wmaybe-unintialized flag:

drivers/input/keyboard/tca8418_keypad.c: In function ‘tca8418_irq_handler’:
drivers/input/keyboard/tca8418_keypad.c:172:9: error: ‘reg’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/input/keyboard/tca8418_keypad.c:165:5: note: ‘reg’ was declared here

This is fixed in gcc-6, but it's possible to rearrange the code
in a way that avoids the warning on older compilers as well.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/tca8418_keypad.c

index 9002298698fce303de6a61b0253c6b0a667b4818..3048ef3e3e1639e2f7d24b9e60c6cf45cfe01c8a 100644 (file)
@@ -164,11 +164,18 @@ static void tca8418_read_keypad(struct tca8418_keypad *keypad_data)
        int error, col, row;
        u8 reg, state, code;
 
-       /* Initial read of the key event FIFO */
-       error = tca8418_read_byte(keypad_data, REG_KEY_EVENT_A, &reg);
+       do {
+               error = tca8418_read_byte(keypad_data, REG_KEY_EVENT_A, &reg);
+               if (error < 0) {
+                       dev_err(&keypad_data->client->dev,
+                               "unable to read REG_KEY_EVENT_A\n");
+                       break;
+               }
+
+               /* Assume that key code 0 signifies empty FIFO */
+               if (reg <= 0)
+                       break;
 
-       /* Assume that key code 0 signifies empty FIFO */
-       while (error >= 0 && reg > 0) {
                state = reg & KEY_EVENT_VALUE;
                code  = reg & KEY_EVENT_CODE;
 
@@ -184,11 +191,7 @@ static void tca8418_read_keypad(struct tca8418_keypad *keypad_data)
 
                /* Read for next loop */
                error = tca8418_read_byte(keypad_data, REG_KEY_EVENT_A, &reg);
-       }
-
-       if (error < 0)
-               dev_err(&keypad_data->client->dev,
-                       "unable to read REG_KEY_EVENT_A\n");
+       } while (1);
 
        input_sync(input);
 }