Skip to content

Commit e1f990c

Browse files
arndbgregkh
authored andcommitted
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: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Robin van der Gracht <robin@protonic.nl> Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c7c3f09 commit e1f990c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/auxdisplay/ht16k33.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static bool ht16k33_keypad_scan(struct ht16k33_keypad *keypad)
278278
}
279279
}
280280
input_sync(keypad->dev);
281-
memcpy(keypad->last_key_state, new_state, sizeof(new_state));
281+
memcpy(keypad->last_key_state, new_state, sizeof(u16) * keypad->cols);
282282

283283
return pressed;
284284
}
@@ -353,6 +353,12 @@ static int ht16k33_keypad_probe(struct i2c_client *client,
353353
err = matrix_keypad_parse_of_params(&client->dev, &rows, &cols);
354354
if (err)
355355
return err;
356+
if (rows > HT16K33_MATRIX_KEYPAD_MAX_ROWS ||
357+
cols > HT16K33_MATRIX_KEYPAD_MAX_COLS) {
358+
dev_err(&client->dev, "%u rows or %u cols out of range in DT\n",
359+
rows, cols);
360+
return -ERANGE;
361+
}
356362

357363
keypad->rows = rows;
358364
keypad->cols = cols;

0 commit comments

Comments
 (0)