From patchwork Fri Feb 15 12:57:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14919 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9B0BA23E01 for ; Fri, 15 Feb 2013 12:58:32 +0000 (UTC) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by fiordland.canonical.com (Postfix) with ESMTP id 3746CA18762 for ; Fri, 15 Feb 2013 12:58:32 +0000 (UTC) Received: by mail-vc0-f174.google.com with SMTP id n11so2097781vch.19 for ; Fri, 15 Feb 2013 04:58:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=WZiCQuLTbwPrdKQaczjFaIXf9x6KafFllYmrHwi8lco=; b=Cl6uC3zdrZJQL0Kp6b9Rw444AM9e9EwruObf/+ubBFx/U0+AvKZgq3/+DU2tMB5se9 UpRUCr3p57Svq32+YJRNjLDtHV7yKmARrKOrbBtIqgfk6Ge6baPqzOkdtF5G7Ff3eshD 6crPFLlzHcDvttz5uhnRtlpm7Rko6zgvKUaKZYm1TdegsEcPDSjyT36qA1JZLjj912Qr kxGwNqTW33uSmoJ4ySPztIuu+E6zdjrpdeEeChSnpBswzssKcii3loxrPMxWbDQwSW98 cp988op1/sz9YIVyx3cCs8KOwhEQT96+0Fri3lmKFa98rG27r1xP3T4/uNyDGf8FIbKU Hp3A== X-Received: by 10.52.98.5 with SMTP id ee5mr2515594vdb.102.1360933111680; Fri, 15 Feb 2013 04:58:31 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.221.4.5 with SMTP id oa5csp11444vcb; Fri, 15 Feb 2013 04:58:31 -0800 (PST) X-Received: by 10.180.79.37 with SMTP id g5mr5728611wix.24.1360933110798; Fri, 15 Feb 2013 04:58:30 -0800 (PST) Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by mx.google.com with ESMTPS id j8si1055494wia.43.2013.02.15.04.58.30 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:58:30 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.180 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.180; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.180 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wi0-f180.google.com with SMTP id hi8so1120586wib.1 for ; Fri, 15 Feb 2013 04:58:30 -0800 (PST) X-Received: by 10.194.174.234 with SMTP id bv10mr3974026wjc.47.1360933110385; Fri, 15 Feb 2013 04:58:30 -0800 (PST) Received: from localhost.localdomain (cpc34-aztw25-2-0-cust250.18-1.cable.virginmedia.com. [86.16.136.251]) by mx.google.com with ESMTPS id j4sm2852410wiz.10.2013.02.15.04.58.28 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:58:29 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, sameo@linux.intel.com Cc: arnd@arndb.de, linus.walleij@stericsson.com, srinidhi kasagar , Lee Jones Subject: [PATCH 34/35] mfd: ab8500-debug: Convert to kstrtoul_from_user Date: Fri, 15 Feb 2013 12:57:05 +0000 Message-Id: <1360933026-30325-35-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360933026-30325-1-git-send-email-lee.jones@linaro.org> References: <1360933026-30325-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQlRqvMJ00wmnHK6D3SrTEdDspoFhUl6gXxOohy53+aKIFQXIH4p3np+OSQJwjec6wBTrL7g From: srinidhi kasagar Use kstrtoul_from_user for getting an unsigned long from userspace which is less error prone. Signed-off-by: srinidhi kasagar Signed-off-by: Linus Walleij Signed-off-by: Lee Jones Reviewed-by: Jonas ABERG --- drivers/mfd/ab8500-debugfs.c | 100 +++++++++++++----------------------------- 1 file changed, 30 insertions(+), 70 deletions(-) diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c index 37f595d..8fdc3b1 100644 --- a/drivers/mfd/ab8500-debugfs.c +++ b/drivers/mfd/ab8500-debugfs.c @@ -1478,7 +1478,6 @@ static ssize_t ab8500_bank_write(struct file *file, unsigned long user_bank; int err; - /* Get userspace string and assure termination */ err = kstrtoul_from_user(user_buf, count, 0, &user_bank); if (err) return err; @@ -1511,7 +1510,6 @@ static ssize_t ab8500_address_write(struct file *file, unsigned long user_address; int err; - /* Get userspace string and assure termination */ err = kstrtoul_from_user(user_buf, count, 0, &user_address); if (err) return err; @@ -1521,6 +1519,7 @@ static ssize_t ab8500_address_write(struct file *file, return -EINVAL; } debug_address = user_address; + return count; } @@ -1555,7 +1554,6 @@ static ssize_t ab8500_val_write(struct file *file, unsigned long user_val; int err; - /* Get userspace string and assure termination */ err = kstrtoul_from_user(user_buf, count, 0, &user_val); if (err) return err; @@ -2417,20 +2415,13 @@ static ssize_t ab8500_gpadc_avg_sample_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_avg_sample; 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_avg_sample); + err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample); if (err) - return -EINVAL; + return err; + if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4) || (user_avg_sample == SAMPLE_8) || (user_avg_sample == SAMPLE_16)) { @@ -2440,7 +2431,8 @@ static ssize_t ab8500_gpadc_avg_sample_write(struct file *file, "should be egal to 1, 4, 8 or 16\n"); return -EINVAL; } - return buf_size; + + return count; } static const struct file_operations ab8500_gpadc_avg_sample_fops = { @@ -2468,20 +2460,13 @@ static ssize_t ab8500_gpadc_trig_edge_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_trig_edge; 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_trig_edge); + err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge); if (err) - return -EINVAL; + return err; + if ((user_trig_edge == RISING_EDGE) || (user_trig_edge == FALLING_EDGE)) { trig_edge = (u8) user_trig_edge; @@ -2491,7 +2476,8 @@ static ssize_t ab8500_gpadc_trig_edge_write(struct file *file, "Enter 1. Falling edge\n"); return -EINVAL; } - return buf_size; + + return count; } static const struct file_operations ab8500_gpadc_trig_edge_fops = { @@ -2519,20 +2505,13 @@ static ssize_t ab8500_gpadc_trig_timer_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_trig_timer; 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_trig_timer); + err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer); if (err) - return -EINVAL; + return err; + if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) { trig_timer = (u8) user_trig_timer; } else { @@ -2540,7 +2519,8 @@ static ssize_t ab8500_gpadc_trig_timer_write(struct file *file, "should be beetween 0 to 255\n"); return -EINVAL; } - return buf_size; + + return count; } static const struct file_operations ab8500_gpadc_trig_timer_fops = { @@ -2568,20 +2548,13 @@ static ssize_t ab8500_gpadc_conv_type_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_conv_type; 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_conv_type); + err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type); if (err) - return -EINVAL; + return err; + if ((user_conv_type == ADC_SW) || (user_conv_type == ADC_HW)) { conv_type = (u8) user_conv_type; @@ -2591,7 +2564,8 @@ static ssize_t ab8500_gpadc_conv_type_write(struct file *file, "Enter 1. ADC HW conversion\n"); return -EINVAL; } - return buf_size; + + return count; } static const struct file_operations ab8500_gpadc_conv_type_fops = { @@ -2808,21 +2782,14 @@ static ssize_t ab8500_subscribe_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; int err; unsigned int irq_index; - /* 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); + err = kstrtoul_from_user(user_buf, count, 0, &user_val); if (err) - return -EINVAL; + return err; + if (user_val < irq_first) { dev_err(dev, "debugfs error input < %d\n", irq_first); return -EINVAL; @@ -2842,7 +2809,7 @@ static ssize_t ab8500_subscribe_write(struct file *file, */ dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), GFP_KERNEL); - event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL); + event_name[irq_index] = kmalloc(count, GFP_KERNEL); sprintf(event_name[irq_index], "%lu", user_val); dev_attr[irq_index]->show = show_irq; dev_attr[irq_index]->store = NULL; @@ -2864,7 +2831,7 @@ static ssize_t ab8500_subscribe_write(struct file *file, return err; } - return buf_size; + return count; } static ssize_t ab8500_unsubscribe_write(struct file *file, @@ -2872,21 +2839,14 @@ static ssize_t ab8500_unsubscribe_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; int err; unsigned int irq_index; - /* 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); + err = kstrtoul_from_user(user_buf, count, 0, &user_val); if (err) - return -EINVAL; + return err; + if (user_val < irq_first) { dev_err(dev, "debugfs error input < %d\n", irq_first); return -EINVAL; @@ -2911,7 +2871,7 @@ static ssize_t ab8500_unsubscribe_write(struct file *file, kfree(event_name[irq_index]); kfree(dev_attr[irq_index]); - return buf_size; + return count; } /*