From patchwork Mon Jun 20 19:51:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Huewe X-Patchwork-Id: 898292 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5KK1p63019681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 20 Jun 2011 20:02:12 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QYkVD-0005cg-AL; Mon, 20 Jun 2011 19:51:19 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QYkVC-00012X-Ux; Mon, 20 Jun 2011 19:51:18 +0000 Received: from mailout-de.gmx.net ([213.165.64.23]) by canuck.infradead.org with smtp (Exim 4.76 #1 (Red Hat Linux)) id 1QYkV5-000127-Sn for linux-arm-kernel@lists.infradead.org; Mon, 20 Jun 2011 19:51:16 +0000 Received: (qmail invoked by alias); 20 Jun 2011 19:51:09 -0000 Received: from dslb-084-056-061-021.pools.arcor-ip.net (EHLO localhost.localdomain) [84.56.61.21] by mail.gmx.net (mp015) with SMTP; 20 Jun 2011 21:51:09 +0200 X-Authenticated: #12255092 X-Provags-ID: V01U2FsdGVkX18rAklNMKIrcof1GbDnyyRKejP1Zx1TprDr+ApsPk FUzrsQS8JRMI4E From: Peter Huewe To: Samuel Ortiz , Alexey Dobriyan Subject: [PATCH v3] mfd/ab8500: Convert to kstrtou8_from_user Date: Mon, 20 Jun 2011 21:51:03 +0200 Message-Id: <1308599463-29001-1-git-send-email-peterhuewe@gmx.de> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1308599189-28555-2-git-send-email-peterhuewe@gmx.de> References: <1308599189-28555-2-git-send-email-peterhuewe@gmx.de> X-Y-GMX-Trusted: 0 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110620_155112_248020_02F7437E X-CRM114-Status: GOOD ( 15.05 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is freemail (peterhuewe[at]gmx.de) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, low trust [213.165.64.23 listed in list.dnswl.org] Cc: Dimitris Papastamos , Linus Walleij , Srinidhi Kasagar , Mark Brown , kernel-janitors@vger.kernel.org, Ian Lartey , linux-kernel@vger.kernel.org, Peter Huewe , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 20 Jun 2011 20:02:13 +0000 (UTC) This patch replaces the code for getting an number from a userspace buffer by a simple call to kstrou8_from_user. This makes it easier to read and less error prone. This patch replaces the code for getting an number from a userspace buffer by a simple call to kstrou8_from_user. This makes it easier to read and less error prone. Since the old buffers held only values up to 255, we don't need kstrtoul, but rather kstrtou8. Kernel Version: v3.0-rc3 Changes in v2: - Use kstrtou8 instead of kstrtoul due to small numbers - Dropped then unnecessary checks (Both remarks from Alexey Dobriyan, Thanks!) Changes in v3: The local struct dev variable isn't needed anymore Signed-off-by: Peter Huewe --- drivers/mfd/ab8500-debugfs.c | 62 +++++++++++------------------------------ 1 files changed, 17 insertions(+), 45 deletions(-) diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c index 64748e4..bb78f4a 100644 --- a/drivers/mfd/ab8500-debugfs.c +++ b/drivers/mfd/ab8500-debugfs.c @@ -419,20 +419,13 @@ static ssize_t ab8500_bank_write(struct file *file, size_t count, loff_t *ppos) { struct device *dev = ((struct seq_file *)(file->private_data))->private; - char buf[32]; - int buf_size; - unsigned long user_bank; + u8 user_bank; int err; - /* Get userspace string and assure termination */ - buf_size = min(count, (sizeof(buf) - 1)); - if (copy_from_user(buf, user_buf, buf_size)) - return -EFAULT; - buf[buf_size] = 0; - - err = strict_strtoul(buf, 0, &user_bank); + /* Get userspace string and convert to number */ + err = kstrtou8_from_user(user_buf, count, 0, &user_bank); if (err) - return -EINVAL; + return err; if (user_bank >= AB8500_NUM_BANKS) { dev_err(dev, "debugfs error input > number of banks\n"); @@ -441,7 +434,7 @@ static ssize_t ab8500_bank_write(struct file *file, debug_bank = user_bank; - return buf_size; + return count; } static int ab8500_address_print(struct seq_file *s, void *p) @@ -458,27 +451,16 @@ static ssize_t ab8500_address_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { - struct device *dev = ((struct seq_file *)(file->private_data))->private; - char buf[32]; - int buf_size; - unsigned long user_address; + u8 user_address; int err; - /* Get userspace string and assure termination */ - buf_size = min(count, (sizeof(buf) - 1)); - if (copy_from_user(buf, user_buf, buf_size)) - return -EFAULT; - buf[buf_size] = 0; - - err = strict_strtoul(buf, 0, &user_address); + /* Get userspace string and convert to number*/ + err = kstrtou8_from_user(user_buf, count, 0, &user_address); if (err) - return -EINVAL; - if (user_address > 0xff) { - dev_err(dev, "debugfs error input > 0xff\n"); - return -EINVAL; - } + return err; + debug_address = user_address; - return buf_size; + return count; } static int ab8500_val_print(struct seq_file *s, void *p) @@ -509,24 +491,14 @@ static ssize_t ab8500_val_write(struct file *file, size_t count, loff_t *ppos) { struct device *dev = ((struct seq_file *)(file->private_data))->private; - char buf[32]; - int buf_size; - unsigned long user_val; + u8 user_val; int err; - /* Get userspace string and assure termination */ - buf_size = min(count, (sizeof(buf)-1)); - if (copy_from_user(buf, user_buf, buf_size)) - return -EFAULT; - buf[buf_size] = 0; - - err = strict_strtoul(buf, 0, &user_val); + /* Get userspace string and convert to number */ + err = kstrtou8_from_user(user_buf, count, 0, &user_val); if (err) - return -EINVAL; - if (user_val > 0xff) { - dev_err(dev, "debugfs error input > 0xff\n"); - return -EINVAL; - } + return err; + err = abx500_set_register_interruptible(dev, (u8)debug_bank, debug_address, (u8)user_val); if (err < 0) { @@ -534,7 +506,7 @@ static ssize_t ab8500_val_write(struct file *file, return -EINVAL; } - return buf_size; + return count; } static const struct file_operations ab8500_bank_fops = {