tree: https://git.kernel.org/pub/scm/linux/kernel/git/fdmanana/linux.git dio_fixes
head: f01450d13f24e9a01436b60f5f2596ef650c790f
commit: fce393f3e59414984ba87693911080747b08ed09 [3/42] btrfs: sysfs: add force_chunk_alloc trigger to force allocation
config: riscv-randconfig-m031-20220709
compiler: riscv32-linux-gcc (GCC) 11.3.0
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
smatch warnings:
fs/btrfs/sysfs.c:811 btrfs_force_chunk_alloc_store() warn: passing zero to 'PTR_ERR'
vim +/PTR_ERR +811 fs/btrfs/sysfs.c
fce393f3e59414 Stefan Roesch 2022-02-08 782 static ssize_t btrfs_force_chunk_alloc_store(struct kobject *kobj,
fce393f3e59414 Stefan Roesch 2022-02-08 783 struct kobj_attribute *a,
fce393f3e59414 Stefan Roesch 2022-02-08 784 const char *buf, size_t len)
fce393f3e59414 Stefan Roesch 2022-02-08 785 {
fce393f3e59414 Stefan Roesch 2022-02-08 786 struct btrfs_space_info *space_info = to_space_info(kobj);
fce393f3e59414 Stefan Roesch 2022-02-08 787 struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
fce393f3e59414 Stefan Roesch 2022-02-08 788 struct btrfs_trans_handle *trans;
fce393f3e59414 Stefan Roesch 2022-02-08 789 bool val;
fce393f3e59414 Stefan Roesch 2022-02-08 790 int ret;
fce393f3e59414 Stefan Roesch 2022-02-08 791
fce393f3e59414 Stefan Roesch 2022-02-08 792 if (!capable(CAP_SYS_ADMIN))
fce393f3e59414 Stefan Roesch 2022-02-08 793 return -EPERM;
fce393f3e59414 Stefan Roesch 2022-02-08 794
fce393f3e59414 Stefan Roesch 2022-02-08 795 if (sb_rdonly(fs_info->sb))
fce393f3e59414 Stefan Roesch 2022-02-08 796 return -EROFS;
fce393f3e59414 Stefan Roesch 2022-02-08 797
fce393f3e59414 Stefan Roesch 2022-02-08 798 ret = kstrtobool(buf, &val);
fce393f3e59414 Stefan Roesch 2022-02-08 799 if (ret)
fce393f3e59414 Stefan Roesch 2022-02-08 800 return ret;
fce393f3e59414 Stefan Roesch 2022-02-08 801
fce393f3e59414 Stefan Roesch 2022-02-08 802 if (!val)
fce393f3e59414 Stefan Roesch 2022-02-08 803 return -EINVAL;
fce393f3e59414 Stefan Roesch 2022-02-08 804
fce393f3e59414 Stefan Roesch 2022-02-08 805 /*
fce393f3e59414 Stefan Roesch 2022-02-08 806 * This is unsafe to be called from sysfs context and may cause
fce393f3e59414 Stefan Roesch 2022-02-08 807 * unexpected problems.
fce393f3e59414 Stefan Roesch 2022-02-08 808 */
fce393f3e59414 Stefan Roesch 2022-02-08 809 trans = btrfs_start_transaction(fs_info->tree_root, 0);
fce393f3e59414 Stefan Roesch 2022-02-08 810 if (!trans)
fce393f3e59414 Stefan Roesch 2022-02-08 @811 return PTR_ERR(trans);
This bug is already fixed upstread. Need to pull the NULL -> IS_ERR()
patch.
fce393f3e59414 Stefan Roesch 2022-02-08 812 ret = btrfs_force_chunk_alloc(trans, space_info->flags);
fce393f3e59414 Stefan Roesch 2022-02-08 813 btrfs_end_transaction(trans);
fce393f3e59414 Stefan Roesch 2022-02-08 814
fce393f3e59414 Stefan Roesch 2022-02-08 815 if (ret == 1)
fce393f3e59414 Stefan Roesch 2022-02-08 816 return len;
fce393f3e59414 Stefan Roesch 2022-02-08 817
fce393f3e59414 Stefan Roesch 2022-02-08 818 return -ENOSPC;
fce393f3e59414 Stefan Roesch 2022-02-08 819 }