Commit 7b830ae4 authored by srinidhi kasagar's avatar srinidhi kasagar Committed by Lee Jones

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: default avatarsrinidhi kasagar <srinidhi.kasagar@stericsson.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@stericsson.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Reviewed-by: default avatarJonas ABERG <jonas.aberg@stericsson.com>
Acked-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent eb1f9587
...@@ -1479,7 +1479,6 @@ static ssize_t ab8500_bank_write(struct file *file, ...@@ -1479,7 +1479,6 @@ static ssize_t ab8500_bank_write(struct file *file,
unsigned long user_bank; unsigned long user_bank;
int err; int err;
/* Get userspace string and assure termination */
err = kstrtoul_from_user(user_buf, count, 0, &user_bank); err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
if (err) if (err)
return err; return err;
...@@ -1512,7 +1511,6 @@ static ssize_t ab8500_address_write(struct file *file, ...@@ -1512,7 +1511,6 @@ static ssize_t ab8500_address_write(struct file *file,
unsigned long user_address; unsigned long user_address;
int err; int err;
/* Get userspace string and assure termination */
err = kstrtoul_from_user(user_buf, count, 0, &user_address); err = kstrtoul_from_user(user_buf, count, 0, &user_address);
if (err) if (err)
return err; return err;
...@@ -1522,6 +1520,7 @@ static ssize_t ab8500_address_write(struct file *file, ...@@ -1522,6 +1520,7 @@ static ssize_t ab8500_address_write(struct file *file,
return -EINVAL; return -EINVAL;
} }
debug_address = user_address; debug_address = user_address;
return count; return count;
} }
...@@ -1556,7 +1555,6 @@ static ssize_t ab8500_val_write(struct file *file, ...@@ -1556,7 +1555,6 @@ static ssize_t ab8500_val_write(struct file *file,
unsigned long user_val; unsigned long user_val;
int err; int err;
/* Get userspace string and assure termination */
err = kstrtoul_from_user(user_buf, count, 0, &user_val); err = kstrtoul_from_user(user_buf, count, 0, &user_val);
if (err) if (err)
return err; return err;
...@@ -2418,20 +2416,13 @@ static ssize_t ab8500_gpadc_avg_sample_write(struct file *file, ...@@ -2418,20 +2416,13 @@ static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct device *dev = ((struct seq_file *)(file->private_data))->private; struct device *dev = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
unsigned long user_avg_sample; unsigned long user_avg_sample;
int err; int err;
/* Get userspace string and assure termination */ err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
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);
if (err) if (err)
return -EINVAL; return err;
if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4) if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
|| (user_avg_sample == SAMPLE_8) || (user_avg_sample == SAMPLE_8)
|| (user_avg_sample == SAMPLE_16)) { || (user_avg_sample == SAMPLE_16)) {
...@@ -2441,7 +2432,8 @@ static ssize_t ab8500_gpadc_avg_sample_write(struct file *file, ...@@ -2441,7 +2432,8 @@ static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
"should be egal to 1, 4, 8 or 16\n"); "should be egal to 1, 4, 8 or 16\n");
return -EINVAL; return -EINVAL;
} }
return buf_size;
return count;
} }
static const struct file_operations ab8500_gpadc_avg_sample_fops = { static 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,20 +2461,13 @@ static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct device *dev = ((struct seq_file *)(file->private_data))->private; struct device *dev = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
unsigned long user_trig_edge; unsigned long user_trig_edge;
int err; int err;
/* Get userspace string and assure termination */ err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
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);
if (err) if (err)
return -EINVAL; return err;
if ((user_trig_edge == RISING_EDGE) if ((user_trig_edge == RISING_EDGE)
|| (user_trig_edge == FALLING_EDGE)) { || (user_trig_edge == FALLING_EDGE)) {
trig_edge = (u8) user_trig_edge; trig_edge = (u8) user_trig_edge;
...@@ -2492,7 +2477,8 @@ static ssize_t ab8500_gpadc_trig_edge_write(struct file *file, ...@@ -2492,7 +2477,8 @@ static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
"Enter 1. Falling edge\n"); "Enter 1. Falling edge\n");
return -EINVAL; return -EINVAL;
} }
return buf_size;
return count;
} }
static const struct file_operations ab8500_gpadc_trig_edge_fops = { static 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,20 +2506,13 @@ static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct device *dev = ((struct seq_file *)(file->private_data))->private; struct device *dev = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
unsigned long user_trig_timer; unsigned long user_trig_timer;
int err; int err;
/* Get userspace string and assure termination */ err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
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);
if (err) if (err)
return -EINVAL; return err;
if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) { if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
trig_timer = (u8) user_trig_timer; trig_timer = (u8) user_trig_timer;
} else { } else {
...@@ -2541,7 +2520,8 @@ static ssize_t ab8500_gpadc_trig_timer_write(struct file *file, ...@@ -2541,7 +2520,8 @@ static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
"should be beetween 0 to 255\n"); "should be beetween 0 to 255\n");
return -EINVAL; return -EINVAL;
} }
return buf_size;
return count;
} }
static const struct file_operations ab8500_gpadc_trig_timer_fops = { static 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,20 +2549,13 @@ static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct device *dev = ((struct seq_file *)(file->private_data))->private; struct device *dev = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
unsigned long user_conv_type; unsigned long user_conv_type;
int err; int err;
/* Get userspace string and assure termination */ err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
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);
if (err) if (err)
return -EINVAL; return err;
if ((user_conv_type == ADC_SW) if ((user_conv_type == ADC_SW)
|| (user_conv_type == ADC_HW)) { || (user_conv_type == ADC_HW)) {
conv_type = (u8) user_conv_type; conv_type = (u8) user_conv_type;
...@@ -2592,7 +2565,8 @@ static ssize_t ab8500_gpadc_conv_type_write(struct file *file, ...@@ -2592,7 +2565,8 @@ static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
"Enter 1. ADC HW conversion\n"); "Enter 1. ADC HW conversion\n");
return -EINVAL; return -EINVAL;
} }
return buf_size;
return count;
} }
static const struct file_operations ab8500_gpadc_conv_type_fops = { static const struct file_operations ab8500_gpadc_conv_type_fops = {
...@@ -2809,21 +2783,14 @@ static ssize_t ab8500_subscribe_write(struct file *file, ...@@ -2809,21 +2783,14 @@ static ssize_t ab8500_subscribe_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct device *dev = ((struct seq_file *)(file->private_data))->private; struct device *dev = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
unsigned long user_val; unsigned long user_val;
int err; int err;
unsigned int irq_index; unsigned int irq_index;
/* Get userspace string and assure termination */ err = kstrtoul_from_user(user_buf, count, 0, &user_val);
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);
if (err) if (err)
return -EINVAL; return err;
if (user_val < irq_first) { if (user_val < irq_first) {
dev_err(dev, "debugfs error input < %d\n", irq_first); dev_err(dev, "debugfs error input < %d\n", irq_first);
return -EINVAL; return -EINVAL;
...@@ -2843,7 +2810,7 @@ static ssize_t ab8500_subscribe_write(struct file *file, ...@@ -2843,7 +2810,7 @@ static ssize_t ab8500_subscribe_write(struct file *file,
*/ */
dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
GFP_KERNEL); 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); sprintf(event_name[irq_index], "%lu", user_val);
dev_attr[irq_index]->show = show_irq; dev_attr[irq_index]->show = show_irq;
dev_attr[irq_index]->store = NULL; dev_attr[irq_index]->store = NULL;
...@@ -2865,7 +2832,7 @@ static ssize_t ab8500_subscribe_write(struct file *file, ...@@ -2865,7 +2832,7 @@ static ssize_t ab8500_subscribe_write(struct file *file,
return err; return err;
} }
return buf_size; return count;
} }
static ssize_t ab8500_unsubscribe_write(struct file *file, static ssize_t ab8500_unsubscribe_write(struct file *file,
...@@ -2873,21 +2840,14 @@ static ssize_t ab8500_unsubscribe_write(struct file *file, ...@@ -2873,21 +2840,14 @@ static ssize_t ab8500_unsubscribe_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct device *dev = ((struct seq_file *)(file->private_data))->private; struct device *dev = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
unsigned long user_val; unsigned long user_val;
int err; int err;
unsigned int irq_index; unsigned int irq_index;
/* Get userspace string and assure termination */ err = kstrtoul_from_user(user_buf, count, 0, &user_val);
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);
if (err) if (err)
return -EINVAL; return err;
if (user_val < irq_first) { if (user_val < irq_first) {
dev_err(dev, "debugfs error input < %d\n", irq_first); dev_err(dev, "debugfs error input < %d\n", irq_first);
return -EINVAL; return -EINVAL;
...@@ -2912,7 +2872,7 @@ static ssize_t ab8500_unsubscribe_write(struct file *file, ...@@ -2912,7 +2872,7 @@ static ssize_t ab8500_unsubscribe_write(struct file *file,
kfree(event_name[irq_index]); kfree(event_name[irq_index]);
kfree(dev_attr[irq_index]); kfree(dev_attr[irq_index]);
return buf_size; return count;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment