s390/tape: Use memdup_user() rather than duplicating its implementation
authorMarkus Elfring <elfring@users.sourceforge.net>
Sat, 20 Aug 2016 17:25:34 +0000 (19:25 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Wed, 24 Aug 2016 07:23:57 +0000 (09:23 +0200)
Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
drivers/s390/char/tape_3590.c

index d3d1936057b48404f440c94d8ac853d7d92975aa..e352047ed9f7a8d6d8ec0a70a688c1efadbfdf9d 100644 (file)
@@ -312,15 +312,10 @@ static int tape_3592_ioctl_kekl_set(struct tape_device *device,
                return -ENOSYS;
        if (!crypt_enabled(device))
                return -EUNATCH;
-       ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
-       if (!ext_kekls)
-               return -ENOMEM;
-       if (copy_from_user(ext_kekls, (char __user *)arg, sizeof(*ext_kekls))) {
-               rc = -EFAULT;
-               goto out;
-       }
+       ext_kekls = memdup_user((char __user *)arg, sizeof(*ext_kekls));
+       if (IS_ERR(ext_kekls))
+               return PTR_ERR(ext_kekls);
        rc = tape_3592_kekl_set(device, ext_kekls);
-out:
        kfree(ext_kekls);
        return rc;
 }