]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: allocate btrfs_ioctl_quota_rescan_args on stack
authorGoldwyn Rodrigues <rgoldwyn@suse.com>
Tue, 27 Jul 2021 21:17:29 +0000 (16:17 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 23 Aug 2021 11:19:10 +0000 (13:19 +0200)
Instead of using kmalloc() to allocate btrfs_ioctl_quota_rescan_args,
allocate btrfs_ioctl_quota_rescan_args on stack, the size is reasonably
small and ioctls are called in process context.

sizeof(btrfs_ioctl_quota_rescan_args) = 64

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ioctl.c

index ba1dab6a5012f7edfb7234954acc80adc0f56599..3d0ae797cd8d5ee00374c83ea1d2edb0d8c5c99f 100644 (file)
@@ -4403,25 +4403,20 @@ drop_write:
 static long btrfs_ioctl_quota_rescan_status(struct btrfs_fs_info *fs_info,
                                                void __user *arg)
 {
-       struct btrfs_ioctl_quota_rescan_args *qsa;
+       struct btrfs_ioctl_quota_rescan_args qsa = {0};
        int ret = 0;
 
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
-       qsa = kzalloc(sizeof(*qsa), GFP_KERNEL);
-       if (!qsa)
-               return -ENOMEM;
-
        if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN) {
-               qsa->flags = 1;
-               qsa->progress = fs_info->qgroup_rescan_progress.objectid;
+               qsa.flags = 1;
+               qsa.progress = fs_info->qgroup_rescan_progress.objectid;
        }
 
-       if (copy_to_user(arg, qsa, sizeof(*qsa)))
+       if (copy_to_user(arg, &qsa, sizeof(qsa)))
                ret = -EFAULT;
 
-       kfree(qsa);
        return ret;
 }