[PATCH v7 2/3] erofs: add sysfs interface
Gao Xiang
xiang at kernel.org
Wed Dec 8 13:02:05 AEDT 2021
Hi Jianan,
On Wed, Dec 01, 2021 at 10:54:36PM +0800, Huang Jianan wrote:
> Add sysfs interface to configure erofs related parameters later.
>
> Signed-off-by: Huang Jianan <huangjianan at oppo.com>
> Reviewed-by: Chao Yu <chao at kernel.org>
...
> +static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
> + s_kobj);
> + struct erofs_attr *a = container_of(attr, struct erofs_attr, attr);
> + unsigned char *ptr = __struct_ptr(sbi, a->struct_type, a->offset);
> + unsigned long t;
> + int ret;
> +
> + switch (a->attr_id) {
> + case attr_pointer_ui:
> + if (!ptr)
> + return 0;
> + ret = kstrtoul(skip_spaces(buf), 0, &t);
> + if (ret)
> + return ret;
> + if (t > UINT_MAX)
> + return -EINVAL;
Intel 0day CI report a warning.
https://lore.kernel.org/r/61aede22.lQ5T3RqGz2H%2Fg4aR%25lkp@intel.com
I fix this like below:
diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
index 41a7de772412..33e15fa63c82 100644
--- a/fs/erofs/sysfs.c
+++ b/fs/erofs/sysfs.c
@@ -128,8 +128,8 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
ret = kstrtoul(skip_spaces(buf), 0, &t);
if (ret)
return ret;
- if (t > UINT_MAX)
- return -EINVAL;
+ if (t != (unsigned int)t)
+ return -ERANGE;
*(unsigned int *)ptr = t;
return len;
case attr_pointer_bool:
Thanks,
Gao Xiang
More information about the Linux-erofs
mailing list