Commit e1f990c2 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Greg Kroah-Hartman

auxdisplay: ht16k33: don't access uninitialized data

gcc-7.0.1 points out that we copy uninitialized data from the stack
into a per-device structure:

drivers/auxdisplay/ht16k33.c: In function 'ht16k33_keypad_irq_thread':
arch/x86/include/asm/string_32.h:78:16: error: 'new_state' may be used uninitialized in this function [-Werror=maybe-uninitialized]
arch/x86/include/asm/string_32.h:79:22: error: '*((void *)&new_state+4)' may be used uninitialized in this function [-Werror=maybe-uninitialized]

The access is harmless because we never read the data, but we are better
off not doing this, so this changes the code to only copy the data
that was actually initialized. To make sure we don't overflow the
stack with an incorrect DT, we also need to add a sanity checkin the
probe function.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Reviewed-by: default avatarRobin van der Gracht <robin@protonic.nl>
Reviewed-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c7c3f096
...@@ -278,7 +278,7 @@ static bool ht16k33_keypad_scan(struct ht16k33_keypad *keypad) ...@@ -278,7 +278,7 @@ static bool ht16k33_keypad_scan(struct ht16k33_keypad *keypad)
} }
} }
input_sync(keypad->dev); input_sync(keypad->dev);
memcpy(keypad->last_key_state, new_state, sizeof(new_state)); memcpy(keypad->last_key_state, new_state, sizeof(u16) * keypad->cols);
return pressed; return pressed;
} }
...@@ -353,6 +353,12 @@ static int ht16k33_keypad_probe(struct i2c_client *client, ...@@ -353,6 +353,12 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
err = matrix_keypad_parse_of_params(&client->dev, &rows, &cols); err = matrix_keypad_parse_of_params(&client->dev, &rows, &cols);
if (err) if (err)
return err; return err;
if (rows > HT16K33_MATRIX_KEYPAD_MAX_ROWS ||
cols > HT16K33_MATRIX_KEYPAD_MAX_COLS) {
dev_err(&client->dev, "%u rows or %u cols out of range in DT\n",
rows, cols);
return -ERANGE;
}
keypad->rows = rows; keypad->rows = rows;
keypad->cols = cols; keypad->cols = cols;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment