From: kernel test robot <lkp(a)intel.com>
mm/util.c:198:5-13: WARNING opportunity for vmemdup_user
Use memdup_user rather than duplicating its implementation
This is a little bit restricted to reduce false positives
Generated by: scripts/coccinelle/api/memdup_user.cocci
CC: Josef Bacik <josef(a)toxicpanda.com>
Signed-off-by: kernel test robot <lkp(a)intel.com>
---
url:
https://github.com/0day-ci/linux/commits/Josef-Bacik/proc-use-vmalloc-for...
base:
https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next
Please take the patch only if it's a positive warning. Thanks!
util.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
--- a/mm/util.c
+++ b/mm/util.c
@@ -195,14 +195,9 @@ void *kvmemdup_user(const void __user *s
{
void *p;
- p = kvmalloc(len, GFP_USER);
- if (!p)
- return ERR_PTR(-ENOMEM);
-
- if (copy_from_user(p, src, len)) {
- kvfree(p);
- return ERR_PTR(-EFAULT);
- }
+ p = vmemdup_user(src, len);
+ if (IS_ERR(p))
+ return ERR_PTR(PTR_ERR(p));
return p;
}