[PATCH 09/12] parse_integer: convert fs/

From: Alexey Dobriyan
Date: Fri May 08 2015 - 14:36:46 EST


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@xxxxxxxxx>
---
fs/binfmt_misc.c | 12 +++++++++---
fs/dcache.c | 2 +-
fs/inode.c | 2 +-
fs/libfs.c | 26 ++++++++++----------------
fs/namespace.c | 4 ++--
5 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 78f005f..75df426 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 656ce52..b2443d9 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -3374,7 +3374,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 ea37cd1..332f097 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1787,7 +1787,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 cb1fb4b..5b778e0 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -752,7 +752,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 */
@@ -830,31 +829,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 1f4f9da..738144c 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);
--
2.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/