mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] misc: fastrpc: Use memdup_user() rather than duplicating its implementation
@ 2024-01-28 14:35 Markus Elfring
  2024-01-29 14:42 ` [PATCH v2] " Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2024-01-28 14:35 UTC (permalink / raw)
  To: linux-arm-msm, kernel-janitors, Arnd Bergmann, Amol Maheshwari,
	Greg Kroah-Hartman, Srinivas Kandagatla
  Cc: LKML, Cong Liu, Kunwu Chan

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Jan 2024 15:17:03 +0100

Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

Generated by: scripts/coccinelle/api/memdup_user.cocci

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/misc/fastrpc.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 1c6c62a7f7f5..83da6ad4e541 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1260,17 +1260,12 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
 		goto err;
 	}

-	name = kzalloc(init.namelen, GFP_KERNEL);
-	if (!name) {
-		err = -ENOMEM;
+	name = memdup_user(init.name, init.namelen);
+	if (IS_ERR(name) {
+		err = PTR_ERR(name);
 		goto err;
 	}

-	if (copy_from_user(name, (void __user *)(uintptr_t)init.name, init.namelen)) {
-		err = -EFAULT;
-		goto err_name;
-	}
-
 	if (!fl->cctx->remote_heap) {
 		err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen,
 						&fl->cctx->remote_heap);
--
2.43.0


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

* [PATCH v2] misc: fastrpc: Use memdup_user() rather than duplicating its implementation
  2024-01-28 14:35 [PATCH] misc: fastrpc: Use memdup_user() rather than duplicating its implementation Markus Elfring
@ 2024-01-29 14:42 ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2024-01-29 14:42 UTC (permalink / raw)
  To: linux-arm-msm, kernel-janitors, Arnd Bergmann, Amol Maheshwari,
	Greg Kroah-Hartman, Srinivas Kandagatla
  Cc: LKML, Cong Liu, Kunwu Chan

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 29 Jan 2024 15:33:41 +0100

* Reuse existing functionality from memdup_user() instead of keeping
  duplicate source code.

  Generated by: scripts/coccinelle/api/memdup_user.cocci

* Adjust a data type conversion for a function call parameter.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---

v2:
A data type conversion should still be applied for one function call parameter.

 drivers/misc/fastrpc.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 1c6c62a7f7f5..3b18c339d091 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1260,17 +1260,12 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
 		goto err;
 	}

-	name = kzalloc(init.namelen, GFP_KERNEL);
-	if (!name) {
-		err = -ENOMEM;
+	name = memdup_user(u64_to_user_ptr(init.name), init.namelen);
+	if (IS_ERR(name) {
+		err = PTR_ERR(name);
 		goto err;
 	}

-	if (copy_from_user(name, (void __user *)(uintptr_t)init.name, init.namelen)) {
-		err = -EFAULT;
-		goto err_name;
-	}
-
 	if (!fl->cctx->remote_heap) {
 		err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen,
 						&fl->cctx->remote_heap);
--
2.43.0


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

end of thread, other threads:[~2024-01-29 14:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-28 14:35 [PATCH] misc: fastrpc: Use memdup_user() rather than duplicating its implementation Markus Elfring
2024-01-29 14:42 ` [PATCH v2] " Markus Elfring

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®