diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2015-07-20 08:57:12 +1000 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2015-07-22 14:31:47 +1000 |
commit | 99a12415d5227058023d28b99a0a435046956d14 (patch) | |
tree | 8f4d6fadf2107cfa43ce9535494f37e930be56ab | |
parent | e6095dc6300faf2658a2b690afea583269fe1427 (diff) |
parse_integer: convert fs/
Convert random fs/ code away from simple_strto*() interfaces.
Note about "struct simple_attr" conversion:
->set_buf is unneeded because everything can be done from stack.
->get_buf is useless as well, but that's a separate patch.
Mutex is not removed, as it may guard readers from writers,
separate story as well.
(code has been copied to arch/powerpc/.../spufs/, don't forget!)
binfmt_misc: file offset can't really be negative, type changed.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
-rw-r--r-- | fs/binfmt_misc.c | 12 | ||||
-rw-r--r-- | fs/dcache.c | 2 | ||||
-rw-r--r-- | fs/inode.c | 2 | ||||
-rw-r--r-- | fs/libfs.c | 26 | ||||
-rw-r--r-- | fs/namespace.c | 4 |
5 files changed, 23 insertions, 23 deletions
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c index 78f005f37847..75df4264176d 100644 --- a/fs/binfmt_misc.c +++ b/fs/binfmt_misc.c @@ -47,7 +47,7 @@ enum {Enabled, Magic}; typedef struct { struct list_head list; unsigned long flags; /* type, status, etc. */ - int offset; /* offset of magic */ + unsigned int offset; /* offset of magic */ int size; /* size of magic/mask */ char *magic; /* magic or filename extension */ char *mask; /* mask, NULL for exact match */ @@ -370,7 +370,13 @@ static Node *create_entry(const char __user *buffer, size_t count) if (!s) goto einval; *s++ = '\0'; - e->offset = simple_strtoul(p, &p, 10); + err = parse_integer(p, 10, &e->offset); + if (err < 0) { + kfree(e); + goto out; + + } + p += err; if (*p++) goto einval; pr_debug("register: offset: %#x\n", e->offset); @@ -548,7 +554,7 @@ static void entry_status(Node *e, char *page) if (!test_bit(Magic, &e->flags)) { sprintf(dp, "extension .%s\n", e->magic); } else { - dp += sprintf(dp, "offset %i\nmagic ", e->offset); + dp += sprintf(dp, "offset %u\nmagic ", e->offset); dp = bin2hex(dp, e->magic, e->size); if (e->mask) { dp += sprintf(dp, "\nmask "); diff --git a/fs/dcache.c b/fs/dcache.c index 9b5fe503f6cb..258685b5e039 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -3369,7 +3369,7 @@ static int __init set_dhash_entries(char *str) { if (!str) return 0; - dhash_entries = simple_strtoul(str, &str, 0); + parse_integer(str, 0, &dhash_entries); return 1; } __setup("dhash_entries=", set_dhash_entries); diff --git a/fs/inode.c b/fs/inode.c index d30640f7a193..e560535706ff 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1828,7 +1828,7 @@ static int __init set_ihash_entries(char *str) { if (!str) return 0; - ihash_entries = simple_strtoul(str, &str, 0); + parse_integer(str, 0, &ihash_entries); return 1; } __setup("ihash_entries=", set_ihash_entries); diff --git a/fs/libfs.c b/fs/libfs.c index 102edfd39000..0b01e7c4dd83 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -747,7 +747,6 @@ struct simple_attr { int (*get)(void *, u64 *); int (*set)(void *, u64); char get_buf[24]; /* enough to store a u64 and "\n\0" */ - char set_buf[24]; void *data; const char *fmt; /* format for read operation */ struct mutex mutex; /* protects access to these buffers */ @@ -825,31 +824,26 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf, size_t len, loff_t *ppos) { struct simple_attr *attr; - u64 val; - size_t size; - ssize_t ret; + s64 val; + int ret; attr = file->private_data; if (!attr->set) return -EACCES; + ret = kstrtos64_from_user(buf, len, 0, &val); + if (ret < 0) + return ret; + ret = mutex_lock_interruptible(&attr->mutex); if (ret) return ret; - - ret = -EFAULT; - size = min(sizeof(attr->set_buf) - 1, len); - if (copy_from_user(attr->set_buf, buf, size)) - goto out; - - attr->set_buf[size] = '\0'; - val = simple_strtoll(attr->set_buf, NULL, 0); ret = attr->set(attr->data, val); - if (ret == 0) - ret = len; /* on success, claim we got the whole input */ -out: mutex_unlock(&attr->mutex); - return ret; + if (ret < 0) + return ret; + /* on success, claim we got the whole input */ + return len; } EXPORT_SYMBOL_GPL(simple_attr_write); diff --git a/fs/namespace.c b/fs/namespace.c index c7cb8a526c05..54e427af5cf7 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -37,7 +37,7 @@ static int __init set_mhash_entries(char *str) { if (!str) return 0; - mhash_entries = simple_strtoul(str, &str, 0); + parse_integer(str, 0, &mhash_entries); return 1; } __setup("mhash_entries=", set_mhash_entries); @@ -47,7 +47,7 @@ static int __init set_mphash_entries(char *str) { if (!str) return 0; - mphash_entries = simple_strtoul(str, &str, 0); + parse_integer(str, 0, &mphash_entries); return 1; } __setup("mphash_entries=", set_mphash_entries); |