Thread (9 messages) 9 messages, 2 authors, 2024-08-28
STALE684d

[PATCH -next 1/5] nfc: core: Use kmemdup_array() instead of kmemdup() for multiple allocation

From: Jinjie Ruan <hidden>
Date: 2024-08-28 07:02:14
Also in: bridge, lkml, netfilter-devel
Subsystem: networking [general], nfc subsystem, the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Heidelberg, Linus Torvalds

Let the kmemdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Jinjie Ruan <redacted>
---
 net/nfc/core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/nfc/core.c b/net/nfc/core.c
index e58dc6405054..cbc2f718aece 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -790,9 +790,8 @@ int nfc_targets_found(struct nfc_dev *dev,
 	dev->targets = NULL;
 
 	if (targets) {
-		dev->targets = kmemdup(targets,
-				       n_targets * sizeof(struct nfc_target),
-				       GFP_ATOMIC);
+		dev->targets = kmemdup_array(targets, n_targets,
+					     sizeof(struct nfc_target), GFP_ATOMIC);
 
 		if (!dev->targets) {
 			dev->n_targets = 0;
-- 
2.34.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