Commit 402fb487 authored by Peter Huewe's avatar Peter Huewe Committed by Samuel Ortiz

mfd: Use kstrtoul_from_user in ab3550

This patch replaces the code for getting an unsigned long from a
userspace buffer by a simple call to kstroul_from_user.
This makes it easier to read and less error prone.
Signed-off-by: default avatarPeter Huewe <peterhuewe@gmx.de>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent 914e6d4e
...@@ -879,20 +879,13 @@ static ssize_t ab3550_bank_write(struct file *file, ...@@ -879,20 +879,13 @@ static ssize_t ab3550_bank_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
unsigned long user_bank; unsigned long user_bank;
int err; int err;
/* Get userspace string and assure termination */ /* Get userspace string and assure termination */
buf_size = min(count, (sizeof(buf) - 1)); err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
if (copy_from_user(buf, user_buf, buf_size))
return -EFAULT;
buf[buf_size] = 0;
err = strict_strtoul(buf, 0, &user_bank);
if (err) if (err)
return -EINVAL; return err;
if (user_bank >= AB3550_NUM_BANKS) { if (user_bank >= AB3550_NUM_BANKS) {
dev_err(&ab->i2c_client[0]->dev, dev_err(&ab->i2c_client[0]->dev,
...@@ -902,7 +895,7 @@ static ssize_t ab3550_bank_write(struct file *file, ...@@ -902,7 +895,7 @@ static ssize_t ab3550_bank_write(struct file *file,
ab->debug_bank = user_bank; ab->debug_bank = user_bank;
return buf_size; return count;
} }
static int ab3550_address_print(struct seq_file *s, void *p) static int ab3550_address_print(struct seq_file *s, void *p)
...@@ -923,27 +916,21 @@ static ssize_t ab3550_address_write(struct file *file, ...@@ -923,27 +916,21 @@ static ssize_t ab3550_address_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
char buf[32];
int buf_size;
unsigned long user_address; unsigned long user_address;
int err; int err;
/* Get userspace string and assure termination */ /* Get userspace string and assure termination */
buf_size = min(count, (sizeof(buf) - 1)); err = kstrtoul_from_user(user_buf, count, 0, &user_address);
if (copy_from_user(buf, user_buf, buf_size))
return -EFAULT;
buf[buf_size] = 0;
err = strict_strtoul(buf, 0, &user_address);
if (err) if (err)
return -EINVAL; return err;
if (user_address > 0xff) { if (user_address > 0xff) {
dev_err(&ab->i2c_client[0]->dev, dev_err(&ab->i2c_client[0]->dev,
"debugfs error input > 0xff\n"); "debugfs error input > 0xff\n");
return -EINVAL; return -EINVAL;
} }
ab->debug_address = user_address; ab->debug_address = user_address;
return buf_size; return count;
} }
static int ab3550_val_print(struct seq_file *s, void *p) static int ab3550_val_print(struct seq_file *s, void *p)
...@@ -971,21 +958,15 @@ static ssize_t ab3550_val_write(struct file *file, ...@@ -971,21 +958,15 @@ static ssize_t ab3550_val_write(struct file *file,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private; struct ab3550 *ab = ((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;
u8 regvalue; u8 regvalue;
/* Get userspace string and assure termination */ /* Get userspace string and assure termination */
buf_size = min(count, (sizeof(buf)-1)); err = kstrtoul_from_user(user_buf, count, 0, &user_val);
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 > 0xff) { if (user_val > 0xff) {
dev_err(&ab->i2c_client[0]->dev, dev_err(&ab->i2c_client[0]->dev,
"debugfs error input > 0xff\n"); "debugfs error input > 0xff\n");
...@@ -1002,7 +983,7 @@ static ssize_t ab3550_val_write(struct file *file, ...@@ -1002,7 +983,7 @@ static ssize_t ab3550_val_write(struct file *file,
if (err) if (err)
return -EINVAL; return -EINVAL;
return buf_size; return count;
} }
static const struct file_operations ab3550_bank_fops = { static const struct file_operations ab3550_bank_fops = {
......
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