Skip to contentSkip to conversation

drm/nouveau/gem: Use vmemdup_user() rather than duplicating its implementation

PATCH Superseded Markus Elfring 2 participants 4 messages Aug 11, 2020 – Aug 14, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/nouveau/gem: Use vmemdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
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

---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/nouveau/nouveau_gem.c +3 -9
index 81f111ad3f4f..7ef6221408af 100644
@@ -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

#1 lore raw

[PATCH] drm/nouveau/gem: fix err_cast.cocci warnings

drivers/gpu/drm/nouveau/nouveau_gem.c:589:9-16: WARNING: ERR_CAST can be used with mem

From: kernel test robot <[email protected]>

drivers/gpu/drm/nouveau/nouveau_gem.c:589:9-16: WARNING: ERR_CAST can be used with mem

Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...))

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

---

url:    https://github.com/0day-ci/linux/commits/Markus-Elfring/drm-nouveau-gem-Use-vmemdup_user-rather-than-duplicating-its-implementation/20200812-150757
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
 nouveau_gem.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_gem.c +1 -1
@@ -586,7 +586,7 @@ u_memcpya(uint64_t user, unsigned nmemb,
 	size *= nmemb;
 	mem = vmemdup_user(userptr, size);
 	if (IS_ERR(mem))
-		return ERR_PTR(PTR_ERR(mem));
+		return ERR_CAST(mem);
 
 	return mem;
 }
#2 lore raw
In reply to Markus Elfring
Thank you for the patch! Perhaps something to improve:

Hi Markus,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on drm-tip/drm-tip tegra-drm/drm/tegra/for-next linus/master drm/drm-next drm-exynos/exynos-drm-next v5.8 next-20200812] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Markus-Elfring/drm-nouveau-gem-Use-vmemdup_user-rather-than-duplicating-its-implementation/20200812-150757
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: x86_64-randconfig-c002-20200811 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate

coccinelle warnings: (new ones prefixed by >>)

>> drivers/gpu/drm/nouveau/nouveau_gem.c:589:9-16: WARNING: ERR_CAST can be used with mem

Please review and possibly fold the followup patch.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

#3 lore raw

PATCH v2 1/1 drm/nouveau/gem: Use vmemdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Fri, 14 Aug 2020 08:56:54 +0200

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

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

* See also:
[PATCH] drm/nouveau/gem: fix err_cast.cocci warnings

* Simplify this function implementation further by omitting the local variable “mem” and extra error handling here.

---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/gpu/drm/nouveau/nouveau_gem.c +1 -12
index 81f111ad3f4f..536ad5e2cbe6 100644
@@ -583,21 +583,10 @@ u_free(void *addr)
 static inline void *
 u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
 {
-	void *mem;
 	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);
-	}
-
-	return mem;
+	return vmemdup_user(userptr, size);
 }
 
 static int

--
2.28.0