From: Shen Lichuan Date: Mon, 26 Aug 2024 04:52:53 +0000 (+0800) Subject: Input: wistron_btns - use kmemdup_array instead of kmemdup for multiple allocation X-Git-Tag: v6.12-rc1~65^2~2^2~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7ffc98a6a55bf93021a5dcb88a7682ae6cb0177;p=thirdparty%2Fkernel%2Fstable.git Input: wistron_btns - use kmemdup_array instead of kmemdup for multiple allocation Let the kmemdup_array() take care about multiplication and possible overflows. Using kmemdup_array() is more appropriate and makes the code easier to audit. Signed-off-by: Shen Lichuan Link: https://lore.kernel.org/r/20240826045253.3503-1-shenlichuan@vivo.com Signed-off-by: Dmitry Torokhov --- diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c index 5c4956678cd0a..907b1a4e6633a 100644 --- a/drivers/input/misc/wistron_btns.c +++ b/drivers/input/misc/wistron_btns.c @@ -990,8 +990,8 @@ static int __init copy_keymap(void) for (key = keymap; key->type != KE_END; key++) length++; - new_keymap = kmemdup(keymap, length * sizeof(struct key_entry), - GFP_KERNEL); + new_keymap = kmemdup_array(keymap, length, sizeof(struct key_entry), + GFP_KERNEL); if (!new_keymap) return -ENOMEM;