From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752159AbbEBA5A (ORCPT ); Fri, 1 May 2015 20:57:00 -0400 Received: from mail-wg0-f46.google.com ([74.125.82.46]:35802 "EHLO mail-wg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750804AbbEBA47 (ORCPT ); Fri, 1 May 2015 20:56:59 -0400 Date: Sat, 2 May 2015 03:56:55 +0300 From: Alexey Dobriyan To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 07/10] parse_integer: convert misc fs/ code Message-ID: <20150502005655.GG21655@p183.telecom.by> References: <20150502004714.GA21655@p183.telecom.by> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150502004714.GA21655@p183.telecom.by> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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(-) --- 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 "); --- 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); --- 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); --- 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); --- 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);