提交 8504d638 编写于 作者: P Peter Huewe 提交者: Samuel Ortiz

mfd: Use kstrtoul_from_user in ab8500

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: NPeter Huewe <peterhuewe@gmx.de>
Signed-off-by: NSamuel Ortiz <sameo@linux.intel.com>
上级 402fb487
...@@ -419,20 +419,13 @@ static ssize_t ab8500_bank_write(struct file *file, ...@@ -419,20 +419,13 @@ static ssize_t ab8500_bank_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_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 >= AB8500_NUM_BANKS) { if (user_bank >= AB8500_NUM_BANKS) {
dev_err(dev, "debugfs error input > number of banks\n"); dev_err(dev, "debugfs error input > number of banks\n");
...@@ -441,7 +434,7 @@ static ssize_t ab8500_bank_write(struct file *file, ...@@ -441,7 +434,7 @@ static ssize_t ab8500_bank_write(struct file *file,
debug_bank = user_bank; debug_bank = user_bank;
return buf_size; return count;
} }
static int ab8500_address_print(struct seq_file *s, void *p) static int ab8500_address_print(struct seq_file *s, void *p)
...@@ -459,26 +452,20 @@ static ssize_t ab8500_address_write(struct file *file, ...@@ -459,26 +452,20 @@ static ssize_t ab8500_address_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_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(dev, "debugfs error input > 0xff\n"); dev_err(dev, "debugfs error input > 0xff\n");
return -EINVAL; return -EINVAL;
} }
debug_address = user_address; debug_address = user_address;
return buf_size; return count;
} }
static int ab8500_val_print(struct seq_file *s, void *p) static int ab8500_val_print(struct seq_file *s, void *p)
...@@ -509,20 +496,14 @@ static ssize_t ab8500_val_write(struct file *file, ...@@ -509,20 +496,14 @@ static ssize_t ab8500_val_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;
/* 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(dev, "debugfs error input > 0xff\n"); dev_err(dev, "debugfs error input > 0xff\n");
return -EINVAL; return -EINVAL;
...@@ -534,7 +515,7 @@ static ssize_t ab8500_val_write(struct file *file, ...@@ -534,7 +515,7 @@ static ssize_t ab8500_val_write(struct file *file,
return -EINVAL; return -EINVAL;
} }
return buf_size; return count;
} }
static const struct file_operations ab8500_bank_fops = { static const struct file_operations ab8500_bank_fops = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册