lkml.org 
[lkml]   [2021]   [Dec]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH v7 2/3] erofs: add sysfs interface
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@oppo.com>
> Reviewed-by: Chao Yu <chao@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

\
 
 \ /
  Last update: 2021-12-08 03:02    [W:0.095 / U:0.088 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site