[Nouveau] [PATCH] drm/nouveau/gem: Use vmemdup_user() rather than duplicating its implementation

Markus Elfring Markus.Elfring at web.de
Tue Aug 11 17:56:15 UTC 2020


From: Markus Elfring <elfring at users.sourceforge.net>
Date: Tue, 11 Aug 2020 19:25:22 +0200

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

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

Signed-off-by: Markus Elfring <elfring at users.sourceforge.net>
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 81f111ad3f4f..7ef6221408af 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -587,15 +587,9 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
 	void __user *userptr = (void __force __user *)(uintptr_t)user;

 	size *= nmemb;
-
-	mem = kvmalloc(size, GFP_KERNEL);
-	if (!mem)
-		return ERR_PTR(-ENOMEM);
-
-	if (copy_from_user(mem, userptr, size)) {
-		u_free(mem);
-		return ERR_PTR(-EFAULT);
-	}
+	mem = vmemdup_user(userptr, size);
+	if (IS_ERR(mem))
+		return ERR_PTR(PTR_ERR(mem));

 	return mem;
 }
--
2.28.0



More information about the Nouveau mailing list