From: Alexey Dobriyan <adobriyan@gmail.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Add parse_integer() (replacement for simple_strto*())
Date: Thu, 9 Apr 2015 18:28:27 +0300 [thread overview]
Message-ID: <20150409152827.GB14850@p183.telecom.by> (raw)
In-Reply-To: <20150409152613.GA14850@p183.telecom.by>
On Thu, Apr 09, 2015 at 06:26:14PM +0300, Alexey Dobriyan wrote:
> int parse_integer(const char *s, unsigned int base, T *val);
This is an example how conversion looks like (for mm/ directory):
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4187,20 +4187,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;
+ if (buf[ret] != ' ')
return -EINVAL;
- buf = endp + 1;
+ buf += ret + 1;
- cfd = simple_strtoul(buf, &endp, 10);
- if ((*endp != ' ') && (*endp != '\0'))
+ ret = parse_integer(buf, 10, &cfd);
+ if (ret < 0)
+ return ret;
+ if (buf[ret] != ' ' && buf[ret] != '\0')
return -EINVAL;
- buf = endp + 1;
+ buf += ret + 1;
event = kzalloc(sizeof(*event), GFP_KERNEL);
if (!event)
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5977,7 +5977,7 @@ static int __init set_hashdist(char *str)
{
if (!str)
return 0;
- hashdist = simple_strtoul(str, &str, 0);
+ parse_integer(str, 0, &hashdist);
return 1;
}
__setup("hashdist=", set_hashdist);
--- 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))
next prev parent reply other threads:[~2015-04-09 15:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-09 15:26 Alexey Dobriyan
2015-04-09 15:28 ` Alexey Dobriyan [this message]
2015-04-09 20:02 ` Andrew Morton
2015-04-11 15:36 ` Alexey Dobriyan
2015-04-11 15:38 ` [PATCH 1/2] " Alexey Dobriyan
2015-04-11 15:43 ` [PATCH 2/2] parse_integer: rewrite kstrto*() Alexey Dobriyan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150409152827.GB14850@p183.telecom.by \
--to=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®