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 <[email protected]>
> Reviewed-by: Chao Yu <[email protected]>

...

> +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%[email protected]

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

Reply via email to