lkml.org 
[lkml]   [2015]   [May]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 08/12] parse_integer: convert mm/
Convert mm/ directory away from deprecated simple_strto*() interface.

One thing to note about parse_integer() and seemingly useless casts --
range of accepted values depends on result type.

int val;
parse_integer(s, 0, &val);

will accept negative integers, while

int val;
parse_integer(s, 0, (unsigned int *)&val);

will accept only 0 and positive integers.

Cast is needed when result variable has to be of different type
for some reason.

This is very important and hopefully [knocks wood] obvious.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
mm/memcontrol.c | 19 +++++++++++--------
mm/memtest.c | 2 +-
mm/page_alloc.c | 2 +-
mm/shmem.c | 14 ++++++++------
4 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 14c2f20..06a920d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4096,20 +4096,23 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
struct fd efile;
struct fd cfile;
const char *name;
- char *endp;
int ret;

buf = strstrip(buf);

- efd = simple_strtoul(buf, &endp, 10);
- if (*endp != ' ')
+ ret = parse_integer(buf, 10, &efd);
+ if (ret < 0)
+ return ret;
+ buf += ret;
+ if (*buf++ != ' ')
return -EINVAL;
- buf = endp + 1;
-
- cfd = simple_strtoul(buf, &endp, 10);
- if ((*endp != ' ') && (*endp != '\0'))
+ ret = parse_integer(buf, 10, &efd);
+ if (ret < 0)
+ return ret;
+ buf += ret;
+ if (*buf != ' ' && *buf != '\0')
return -EINVAL;
- buf = endp + 1;
+ buf++;

event = kzalloc(sizeof(*event), GFP_KERNEL);
if (!event)
diff --git a/mm/memtest.c b/mm/memtest.c
index 1997d93..e5e2914 100644
--- a/mm/memtest.c
+++ b/mm/memtest.c
@@ -93,7 +93,7 @@ static int memtest_pattern __initdata;
static int __init parse_memtest(char *arg)
{
if (arg)
- memtest_pattern = simple_strtoul(arg, NULL, 0);
+ parse_integer(arg, 0, (unsigned int *)&memtest_pattern);
else
memtest_pattern = ARRAY_SIZE(patterns);

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index ebffa0e..c3528a3 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6020,7 +6020,7 @@ static int __init set_hashdist(char *str)
{
if (!str)
return 0;
- hashdist = simple_strtoul(str, &str, 0);
+ parse_integer(str, 0, (unsigned int *)&hashdist);
return 1;
}
__setup("hashdist=", set_hashdist);
diff --git a/mm/shmem.c b/mm/shmem.c
index de98137..5ce525d 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2742,6 +2742,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
struct mempolicy *mpol = NULL;
uid_t uid;
gid_t gid;
+ int rv;

while (options != NULL) {
this_char = options;
@@ -2795,14 +2796,15 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
} else if (!strcmp(this_char,"mode")) {
if (remount)
continue;
- sbinfo->mode = simple_strtoul(value, &rest, 8) & 07777;
- if (*rest)
+ rv = parse_integer(value, 8, &sbinfo->mode);
+ if (rv < 0 || value[rv])
goto bad_val;
+ sbinfo->mode &= 07777;
} else if (!strcmp(this_char,"uid")) {
if (remount)
continue;
- uid = simple_strtoul(value, &rest, 0);
- if (*rest)
+ rv = parse_integer(value, 0, &uid);
+ if (rv < 0 || value[rv])
goto bad_val;
sbinfo->uid = make_kuid(current_user_ns(), uid);
if (!uid_valid(sbinfo->uid))
@@ -2810,8 +2812,8 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
} else if (!strcmp(this_char,"gid")) {
if (remount)
continue;
- gid = simple_strtoul(value, &rest, 0);
- if (*rest)
+ rv = parse_integer(value, 0, &gid);
+ if (rv < 0 || value[rv])
goto bad_val;
sbinfo->gid = make_kgid(current_user_ns(), gid);
if (!gid_valid(sbinfo->gid))
--
2.0.4


\
 
 \ /
  Last update: 2015-05-08 20:41    [W:0.120 / U:15.984 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site