Message ID | 4bfd049f4d8956c6b257e2cf2a69373c90a0f35e.1627418762.git.rgoldwyn@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Allocate structures on stack instead of kmalloc() | expand |
On 28/07/2021 05:17, Goldwyn Rodrigues wrote: > From: Goldwyn Rodrigues <rgoldwyn@suse.com> > > Instead of using kmalloc() to allocate btrfs_ioctl_quota_rescan_args, > allocate btrfs_ioctl_quota_rescan_args on stack. > > sizeof(btrfs_ioctl_quota_rescan_args) = 64 > > Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Looks good. Reviewed-by: Anand Jain <anand.jain@oracle.com> > --- > fs/btrfs/ioctl.c | 13 ++++--------- > 1 file changed, 4 insertions(+), 9 deletions(-) > > diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c > index 9c3acc539052..291c16d8576b 100644 > --- a/fs/btrfs/ioctl.c > +++ b/fs/btrfs/ioctl.c > @@ -4390,25 +4390,20 @@ static long btrfs_ioctl_quota_rescan(struct file *file, void __user *arg) > 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; > } > >
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9c3acc539052..291c16d8576b 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4390,25 +4390,20 @@ static long btrfs_ioctl_quota_rescan(struct file *file, void __user *arg) 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; }