mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH -next] fastrpc: Use memdup_user instead of kmalloc/copy_from_user
@ 2023-05-15  9:26 Yang Li
  2023-05-15  9:37 ` Luca Weiss
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Li @ 2023-05-15  9:26 UTC (permalink / raw)
  To: srinivas.kandagatla
  Cc: amahesh, arnd, linux-arm-msm, linux-kernel, Yang Li, Abaci Robot

Use memdup_user rather than duplicating its implementation, which
makes code simple and easy to understand, and silence the following
warning:

./drivers/misc/fastrpc.c:1259:8-15: WARNING opportunity for memdup_user

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4949
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
 drivers/misc/fastrpc.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index f60bbf99485c..a897dab13c61 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1256,16 +1256,9 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
 		goto err;
 	}
 
-	name = kzalloc(init.namelen, GFP_KERNEL);
-	if (!name) {
-		err = -ENOMEM;
-		goto err;
-	}
-
-	if (copy_from_user(name, (void __user *)(uintptr_t)init.name, init.namelen)) {
-		err = -EFAULT;
-		goto err_name;
-	}
+	name = memdup_user((void __user *)(uintptr_t)init.name, init.namelen);
+	if (IS_ERR(name))
+		return PTR_ERR(name);
 
 	if (!fl->cctx->remote_heap) {
 		err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen,
-- 
2.20.1.7.g153144c


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-15  9:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-15  9:26 [PATCH -next] fastrpc: Use memdup_user instead of kmalloc/copy_from_user Yang Li
2023-05-15  9:37 ` Luca Weiss

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®