powerpc/powernv: use memdup_user
authorGeliang Tang <geliangtang@gmail.com>
Sat, 29 Apr 2017 01:45:14 +0000 (09:45 +0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 24 Jul 2017 11:48:42 +0000 (21:48 +1000)
Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/platforms/powernv/opal-prd.c

index 2d6ee1c5ad859f4253f4b3c42e2aca1a6f9056a5..de4dd09f4a15c3ba5130322ccd57c134033739f7 100644 (file)
@@ -241,15 +241,9 @@ static ssize_t opal_prd_write(struct file *file, const char __user *buf,
 
        size = be16_to_cpu(hdr.size);
 
-       msg = kmalloc(size, GFP_KERNEL);
-       if (!msg)
-               return -ENOMEM;
-
-       rc = copy_from_user(msg, buf, size);
-       if (rc) {
-               size = -EFAULT;
-               goto out_free;
-       }
+       msg = memdup_user(buf, size);
+       if (IS_ERR(msg))
+               return PTR_ERR(msg);
 
        rc = opal_prd_msg(msg);
        if (rc) {
@@ -257,7 +251,6 @@ static ssize_t opal_prd_write(struct file *file, const char __user *buf,
                size = -EIO;
        }
 
-out_free:
        kfree(msg);
 
        return size;