Skip to content

Commit 647fc2b

Browse files
committed
Input: samsung-keypad - use struct_size() helper
When allocating memory for the keypad use struct_size() helper to be protected from overflows. Reviewed-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 706a066 commit 647fc2b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/input/keyboard/samsung-keypad.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ static int samsung_keypad_probe(struct platform_device *pdev)
318318
struct resource *res;
319319
struct input_dev *input_dev;
320320
unsigned int row_shift;
321-
unsigned int keymap_size;
322321
int error;
323322

324323
pdata = dev_get_platdata(&pdev->dev);
@@ -345,9 +344,10 @@ static int samsung_keypad_probe(struct platform_device *pdev)
345344
pdata->cfg_gpio(pdata->rows, pdata->cols);
346345

347346
row_shift = get_count_order(pdata->cols);
348-
keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]);
349347

350-
keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size,
348+
keypad = devm_kzalloc(&pdev->dev,
349+
struct_size(keypad, keycodes,
350+
pdata->rows << row_shift),
351351
GFP_KERNEL);
352352
if (!keypad)
353353
return -ENOMEM;

0 commit comments

Comments
 (0)