Thread (2 messages) 2 messages, 2 authors, 2024-08-26
STALE642d LANDED

[PATCH v1] Input: wistron_btns - use kmemdup_array instead of kmemdup for multiple allocation

From: Shen Lichuan <hidden>
Date: 2024-08-26 04:53:18
Also in: lkml
Subsystem: input (keyboard, mouse, joystick, touchscreen) drivers, the rest, wistron laptop button driver · Maintainers: Dmitry Torokhov, Linus Torvalds, Miloslav Trmac

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 <redacted>
---
 drivers/input/misc/wistron_btns.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c
index 5c4956678cd0..907b1a4e6633 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;
 
-- 
2.17.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help