drm/nouveau: switch over to vmemdup_user()

Atul Raut rauji.raut at gmail.com
Fri Aug 11 06:31:11 UTC 2023


Use vmemdup_user() rather than duplicating its implementation.

This patch fixes the following Coccinelle warning:
./drivers/gpu/drm/nouveau/nouveau_gem.c:630:7-15: WARNING opportunity for vmemdup_user

Signed-off-by: Atul Raut <rauji.raut at gmail.com>
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index ab9062e50977..a244b39df213 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -627,15 +627,10 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
 
 	size *= nmemb;
 
-	mem = kvmalloc(size, GFP_KERNEL);
-	if (!mem)
+	mem = vmemdup_user(userptr, size);
+	if (IS_ERR(mem))
 		return ERR_PTR(-ENOMEM);
 
-	if (copy_from_user(mem, userptr, size)) {
-		u_free(mem);
-		return ERR_PTR(-EFAULT);
-	}
-
 	return mem;
 }
 
-- 
2.34.1



More information about the dri-devel mailing list