aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsrinidhi kasagar <srinidhi.kasagar@stericsson.com>2012-11-23 04:41:00 -0500
committerLee Jones <lee.jones@linaro.org>2013-03-06 23:29:26 -0500
commit7b830ae4e538cf04d3b57432bb08f58b828dbafa (patch)
tree8bce0f3dfdf08c94c729fd098706183b95cc0786
parenteb1f95872a053c5aed3e3d13234f8f68e3b2a55a (diff)
mfd: ab8500-debug: Convert to kstrtoul_from_user
Use kstrtoul_from_user for getting an unsigned long from userspace which is less error prone. Signed-off-by: srinidhi kasagar <srinidhi.kasagar@stericsson.com> Signed-off-by: Linus Walleij <linus.walleij@stericsson.com> Signed-off-by: Lee Jones <lee.jones@linaro.org> Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com> Acked-by: Samuel Ortiz <sameo@linux.intel.com>
-rw-r--r--drivers/mfd/ab8500-debugfs.c100
1 files changed, 30 insertions, 70 deletions
diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index 810ac6faabba..e33c1628c65b 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -1479,7 +1479,6 @@ static ssize_t ab8500_bank_write(struct file *file,
1479 unsigned long user_bank; 1479 unsigned long user_bank;
1480 int err; 1480 int err;
1481 1481
1482 /* Get userspace string and assure termination */
1483 err = kstrtoul_from_user(user_buf, count, 0, &user_bank); 1482 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
1484 if (err) 1483 if (err)
1485 return err; 1484 return err;
@@ -1512,7 +1511,6 @@ static ssize_t ab8500_address_write(struct file *file,
1512 unsigned long user_address; 1511 unsigned long user_address;
1513 int err; 1512 int err;
1514 1513
1515 /* Get userspace string and assure termination */
1516 err = kstrtoul_from_user(user_buf, count, 0, &user_address); 1514 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
1517 if (err) 1515 if (err)
1518 return err; 1516 return err;
@@ -1522,6 +1520,7 @@ static ssize_t ab8500_address_write(struct file *file,
1522 return -EINVAL; 1520 return -EINVAL;
1523 } 1521 }
1524 debug_address = user_address; 1522 debug_address = user_address;
1523
1525 return count; 1524 return count;
1526} 1525}
1527 1526
@@ -1556,7 +1555,6 @@ static ssize_t ab8500_val_write(struct file *file,
1556 unsigned long user_val; 1555 unsigned long user_val;
1557 int err; 1556 int err;
1558 1557
1559 /* Get userspace string and assure termination */
1560 err = kstrtoul_from_user(user_buf, count, 0, &user_val); 1558 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1561 if (err) 1559 if (err)
1562 return err; 1560 return err;
@@ -2418,20 +2416,13 @@ static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2418 size_t count, loff_t *ppos) 2416 size_t count, loff_t *ppos)
2419{ 2417{
2420 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2418 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2421 char buf[32];
2422 int buf_size;
2423 unsigned long user_avg_sample; 2419 unsigned long user_avg_sample;
2424 int err; 2420 int err;
2425 2421
2426 /* Get userspace string and assure termination */ 2422 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2427 buf_size = min(count, (sizeof(buf) - 1));
2428 if (copy_from_user(buf, user_buf, buf_size))
2429 return -EFAULT;
2430 buf[buf_size] = 0;
2431
2432 err = strict_strtoul(buf, 0, &user_avg_sample);
2433 if (err) 2423 if (err)
2434 return -EINVAL; 2424 return err;
2425
2435 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4) 2426 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2436 || (user_avg_sample == SAMPLE_8) 2427 || (user_avg_sample == SAMPLE_8)
2437 || (user_avg_sample == SAMPLE_16)) { 2428 || (user_avg_sample == SAMPLE_16)) {
@@ -2441,7 +2432,8 @@ static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2441 "should be egal to 1, 4, 8 or 16\n"); 2432 "should be egal to 1, 4, 8 or 16\n");
2442 return -EINVAL; 2433 return -EINVAL;
2443 } 2434 }
2444 return buf_size; 2435
2436 return count;
2445} 2437}
2446 2438
2447static const struct file_operations ab8500_gpadc_avg_sample_fops = { 2439static const struct file_operations ab8500_gpadc_avg_sample_fops = {
@@ -2469,20 +2461,13 @@ static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2469 size_t count, loff_t *ppos) 2461 size_t count, loff_t *ppos)
2470{ 2462{
2471 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2463 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2472 char buf[32];
2473 int buf_size;
2474 unsigned long user_trig_edge; 2464 unsigned long user_trig_edge;
2475 int err; 2465 int err;
2476 2466
2477 /* Get userspace string and assure termination */ 2467 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2478 buf_size = min(count, (sizeof(buf) - 1));
2479 if (copy_from_user(buf, user_buf, buf_size))
2480 return -EFAULT;
2481 buf[buf_size] = 0;
2482
2483 err = strict_strtoul(buf, 0, &user_trig_edge);
2484 if (err) 2468 if (err)
2485 return -EINVAL; 2469 return err;
2470
2486 if ((user_trig_edge == RISING_EDGE) 2471 if ((user_trig_edge == RISING_EDGE)
2487 || (user_trig_edge == FALLING_EDGE)) { 2472 || (user_trig_edge == FALLING_EDGE)) {
2488 trig_edge = (u8) user_trig_edge; 2473 trig_edge = (u8) user_trig_edge;
@@ -2492,7 +2477,8 @@ static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2492 "Enter 1. Falling edge\n"); 2477 "Enter 1. Falling edge\n");
2493 return -EINVAL; 2478 return -EINVAL;
2494 } 2479 }
2495 return buf_size; 2480
2481 return count;
2496} 2482}
2497 2483
2498static const struct file_operations ab8500_gpadc_trig_edge_fops = { 2484static const struct file_operations ab8500_gpadc_trig_edge_fops = {
@@ -2520,20 +2506,13 @@ static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2520 size_t count, loff_t *ppos) 2506 size_t count, loff_t *ppos)
2521{ 2507{
2522 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2508 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2523 char buf[32];
2524 int buf_size;
2525 unsigned long user_trig_timer; 2509 unsigned long user_trig_timer;
2526 int err; 2510 int err;
2527 2511
2528 /* Get userspace string and assure termination */ 2512 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2529 buf_size = min(count, (sizeof(buf) - 1));
2530 if (copy_from_user(buf, user_buf, buf_size))
2531 return -EFAULT;
2532 buf[buf_size] = 0;
2533
2534 err = strict_strtoul(buf, 0, &user_trig_timer);
2535 if (err) 2513 if (err)
2536 return -EINVAL; 2514 return err;
2515
2537 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) { 2516 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
2538 trig_timer = (u8) user_trig_timer; 2517 trig_timer = (u8) user_trig_timer;
2539 } else { 2518 } else {
@@ -2541,7 +2520,8 @@ static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2541 "should be beetween 0 to 255\n"); 2520 "should be beetween 0 to 255\n");
2542 return -EINVAL; 2521 return -EINVAL;
2543 } 2522 }
2544 return buf_size; 2523
2524 return count;
2545} 2525}
2546 2526
2547static const struct file_operations ab8500_gpadc_trig_timer_fops = { 2527static const struct file_operations ab8500_gpadc_trig_timer_fops = {
@@ -2569,20 +2549,13 @@ static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2569 size_t count, loff_t *ppos) 2549 size_t count, loff_t *ppos)
2570{ 2550{
2571 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2551 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2572 char buf[32];
2573 int buf_size;
2574 unsigned long user_conv_type; 2552 unsigned long user_conv_type;
2575 int err; 2553 int err;
2576 2554
2577 /* Get userspace string and assure termination */ 2555 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2578 buf_size = min(count, (sizeof(buf) - 1));
2579 if (copy_from_user(buf, user_buf, buf_size))
2580 return -EFAULT;
2581 buf[buf_size] = 0;
2582
2583 err = strict_strtoul(buf, 0, &user_conv_type);
2584 if (err) 2556 if (err)
2585 return -EINVAL; 2557 return err;
2558
2586 if ((user_conv_type == ADC_SW) 2559 if ((user_conv_type == ADC_SW)
2587 || (user_conv_type == ADC_HW)) { 2560 || (user_conv_type == ADC_HW)) {
2588 conv_type = (u8) user_conv_type; 2561 conv_type = (u8) user_conv_type;
@@ -2592,7 +2565,8 @@ static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2592 "Enter 1. ADC HW conversion\n"); 2565 "Enter 1. ADC HW conversion\n");
2593 return -EINVAL; 2566 return -EINVAL;
2594 } 2567 }
2595 return buf_size; 2568
2569 return count;
2596} 2570}
2597 2571
2598static const struct file_operations ab8500_gpadc_conv_type_fops = { 2572static const struct file_operations ab8500_gpadc_conv_type_fops = {
@@ -2809,21 +2783,14 @@ static ssize_t ab8500_subscribe_write(struct file *file,
2809 size_t count, loff_t *ppos) 2783 size_t count, loff_t *ppos)
2810{ 2784{
2811 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2785 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2812 char buf[32];
2813 int buf_size;
2814 unsigned long user_val; 2786 unsigned long user_val;
2815 int err; 2787 int err;
2816 unsigned int irq_index; 2788 unsigned int irq_index;
2817 2789
2818 /* Get userspace string and assure termination */ 2790 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2819 buf_size = min(count, (sizeof(buf)-1));
2820 if (copy_from_user(buf, user_buf, buf_size))
2821 return -EFAULT;
2822 buf[buf_size] = 0;
2823
2824 err = strict_strtoul(buf, 0, &user_val);
2825 if (err) 2791 if (err)
2826 return -EINVAL; 2792 return err;
2793
2827 if (user_val < irq_first) { 2794 if (user_val < irq_first) {
2828 dev_err(dev, "debugfs error input < %d\n", irq_first); 2795 dev_err(dev, "debugfs error input < %d\n", irq_first);
2829 return -EINVAL; 2796 return -EINVAL;
@@ -2843,7 +2810,7 @@ static ssize_t ab8500_subscribe_write(struct file *file,
2843 */ 2810 */
2844 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), 2811 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
2845 GFP_KERNEL); 2812 GFP_KERNEL);
2846 event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL); 2813 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
2847 sprintf(event_name[irq_index], "%lu", user_val); 2814 sprintf(event_name[irq_index], "%lu", user_val);
2848 dev_attr[irq_index]->show = show_irq; 2815 dev_attr[irq_index]->show = show_irq;
2849 dev_attr[irq_index]->store = NULL; 2816 dev_attr[irq_index]->store = NULL;
@@ -2865,7 +2832,7 @@ static ssize_t ab8500_subscribe_write(struct file *file,
2865 return err; 2832 return err;
2866 } 2833 }
2867 2834
2868 return buf_size; 2835 return count;
2869} 2836}
2870 2837
2871static ssize_t ab8500_unsubscribe_write(struct file *file, 2838static ssize_t ab8500_unsubscribe_write(struct file *file,
@@ -2873,21 +2840,14 @@ static ssize_t ab8500_unsubscribe_write(struct file *file,
2873 size_t count, loff_t *ppos) 2840 size_t count, loff_t *ppos)
2874{ 2841{
2875 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2842 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2876 char buf[32];
2877 int buf_size;
2878 unsigned long user_val; 2843 unsigned long user_val;
2879 int err; 2844 int err;
2880 unsigned int irq_index; 2845 unsigned int irq_index;
2881 2846
2882 /* Get userspace string and assure termination */ 2847 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
2883 buf_size = min(count, (sizeof(buf)-1));
2884 if (copy_from_user(buf, user_buf, buf_size))
2885 return -EFAULT;
2886 buf[buf_size] = 0;
2887
2888 err = strict_strtoul(buf, 0, &user_val);
2889 if (err) 2848 if (err)
2890 return -EINVAL; 2849 return err;
2850
2891 if (user_val < irq_first) { 2851 if (user_val < irq_first) {
2892 dev_err(dev, "debugfs error input < %d\n", irq_first); 2852 dev_err(dev, "debugfs error input < %d\n", irq_first);
2893 return -EINVAL; 2853 return -EINVAL;
@@ -2912,7 +2872,7 @@ static ssize_t ab8500_unsubscribe_write(struct file *file,
2912 kfree(event_name[irq_index]); 2872 kfree(event_name[irq_index]);
2913 kfree(dev_attr[irq_index]); 2873 kfree(dev_attr[irq_index]);
2914 2874
2915 return buf_size; 2875 return count;
2916} 2876}
2917 2877
2918/* 2878/*