btrfs: use memdup_user()
[linux-2.6-block.git] / fs / btrfs / super.c
index 9744af9d71e95afa3a66f9ac1b2188722318aad8..a7acfe639a449eeb278214a04bfc6037249e3048 100644 (file)
@@ -635,14 +635,9 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
-       vol = kmalloc(sizeof(*vol), GFP_KERNEL);
-       if (!vol)
-               return -ENOMEM;
-
-       if (copy_from_user(vol, (void __user *)arg, sizeof(*vol))) {
-               ret = -EFAULT;
-               goto out;
-       }
+       vol = memdup_user((void __user *)arg, sizeof(*vol));
+       if (IS_ERR(vol))
+               return PTR_ERR(vol);
 
        switch (cmd) {
        case BTRFS_IOC_SCAN_DEV:
@@ -650,7 +645,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
                                            &btrfs_fs_type, &fs_devices);
                break;
        }
-out:
+
        kfree(vol);
        return ret;
 }