summaryrefslogtreecommitdiff
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2024-08-18 21:58:01 -0700
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2025-07-01 14:16:17 -0700
commit647fc2bfe21e1114b06de8ee2bc1e479072e7509 (patch)
tree60746c6db91f37cb25d545d86bdff7dcae07dff8 /drivers/input
parent706a066328dbdd7a15ac4904905fa7f8bd29cdf0 (diff)
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 <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20240819045813.2154642-5-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/keyboard/samsung-keypad.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c
index ada4cd151dc6..e3a1b0db7ec8 100644
--- a/drivers/input/keyboard/samsung-keypad.c
+++ b/drivers/input/keyboard/samsung-keypad.c
@@ -318,7 +318,6 @@ static int samsung_keypad_probe(struct platform_device *pdev)
struct resource *res;
struct input_dev *input_dev;
unsigned int row_shift;
- unsigned int keymap_size;
int error;
pdata = dev_get_platdata(&pdev->dev);
@@ -345,9 +344,10 @@ static int samsung_keypad_probe(struct platform_device *pdev)
pdata->cfg_gpio(pdata->rows, pdata->cols);
row_shift = get_count_order(pdata->cols);
- keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]);
- keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size,
+ keypad = devm_kzalloc(&pdev->dev,
+ struct_size(keypad, keycodes,
+ pdata->rows << row_shift),
GFP_KERNEL);
if (!keypad)
return -ENOMEM;