aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorPeter Huewe <peterhuewe@gmx.de>2011-06-06 16:43:32 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2011-07-31 17:28:21 -0400
commit8504d638041d50901b8bfba4fe646bd0bbb5cbb9 (patch)
tree4cdf8b10a1c6fd83427ea54905aa31159ce0643a /drivers/mfd
parent402fb487005d0fcbd4ce627b10426b3491ac0590 (diff)
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: Peter Huewe <peterhuewe@gmx.de> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/ab8500-debugfs.c41
1 files changed, 11 insertions, 30 deletions
diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index 64748e42ac03..64bdeeb1c11a 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -419,20 +419,13 @@ static ssize_t ab8500_bank_write(struct file *file,
419 size_t count, loff_t *ppos) 419 size_t count, loff_t *ppos)
420{ 420{
421 struct device *dev = ((struct seq_file *)(file->private_data))->private; 421 struct device *dev = ((struct seq_file *)(file->private_data))->private;
422 char buf[32];
423 int buf_size;
424 unsigned long user_bank; 422 unsigned long user_bank;
425 int err; 423 int err;
426 424
427 /* Get userspace string and assure termination */ 425 /* Get userspace string and assure termination */
428 buf_size = min(count, (sizeof(buf) - 1)); 426 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
429 if (copy_from_user(buf, user_buf, buf_size))
430 return -EFAULT;
431 buf[buf_size] = 0;
432
433 err = strict_strtoul(buf, 0, &user_bank);
434 if (err) 427 if (err)
435 return -EINVAL; 428 return err;
436 429
437 if (user_bank >= AB8500_NUM_BANKS) { 430 if (user_bank >= AB8500_NUM_BANKS) {
438 dev_err(dev, "debugfs error input > number of banks\n"); 431 dev_err(dev, "debugfs error input > number of banks\n");
@@ -441,7 +434,7 @@ static ssize_t ab8500_bank_write(struct file *file,
441 434
442 debug_bank = user_bank; 435 debug_bank = user_bank;
443 436
444 return buf_size; 437 return count;
445} 438}
446 439
447static int ab8500_address_print(struct seq_file *s, void *p) 440static int ab8500_address_print(struct seq_file *s, void *p)
@@ -459,26 +452,20 @@ static ssize_t ab8500_address_write(struct file *file,
459 size_t count, loff_t *ppos) 452 size_t count, loff_t *ppos)
460{ 453{
461 struct device *dev = ((struct seq_file *)(file->private_data))->private; 454 struct device *dev = ((struct seq_file *)(file->private_data))->private;
462 char buf[32];
463 int buf_size;
464 unsigned long user_address; 455 unsigned long user_address;
465 int err; 456 int err;
466 457
467 /* Get userspace string and assure termination */ 458 /* Get userspace string and assure termination */
468 buf_size = min(count, (sizeof(buf) - 1)); 459 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
469 if (copy_from_user(buf, user_buf, buf_size))
470 return -EFAULT;
471 buf[buf_size] = 0;
472
473 err = strict_strtoul(buf, 0, &user_address);
474 if (err) 460 if (err)
475 return -EINVAL; 461 return err;
462
476 if (user_address > 0xff) { 463 if (user_address > 0xff) {
477 dev_err(dev, "debugfs error input > 0xff\n"); 464 dev_err(dev, "debugfs error input > 0xff\n");
478 return -EINVAL; 465 return -EINVAL;
479 } 466 }
480 debug_address = user_address; 467 debug_address = user_address;
481 return buf_size; 468 return count;
482} 469}
483 470
484static int ab8500_val_print(struct seq_file *s, void *p) 471static int ab8500_val_print(struct seq_file *s, void *p)
@@ -509,20 +496,14 @@ static ssize_t ab8500_val_write(struct file *file,
509 size_t count, loff_t *ppos) 496 size_t count, loff_t *ppos)
510{ 497{
511 struct device *dev = ((struct seq_file *)(file->private_data))->private; 498 struct device *dev = ((struct seq_file *)(file->private_data))->private;
512 char buf[32];
513 int buf_size;
514 unsigned long user_val; 499 unsigned long user_val;
515 int err; 500 int err;
516 501
517 /* Get userspace string and assure termination */ 502 /* Get userspace string and assure termination */
518 buf_size = min(count, (sizeof(buf)-1)); 503 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
519 if (copy_from_user(buf, user_buf, buf_size))
520 return -EFAULT;
521 buf[buf_size] = 0;
522
523 err = strict_strtoul(buf, 0, &user_val);
524 if (err) 504 if (err)
525 return -EINVAL; 505 return err;
506
526 if (user_val > 0xff) { 507 if (user_val > 0xff) {
527 dev_err(dev, "debugfs error input > 0xff\n"); 508 dev_err(dev, "debugfs error input > 0xff\n");
528 return -EINVAL; 509 return -EINVAL;
@@ -534,7 +515,7 @@ static ssize_t ab8500_val_write(struct file *file,
534 return -EINVAL; 515 return -EINVAL;
535 } 516 }
536 517
537 return buf_size; 518 return count;
538} 519}
539 520
540static const struct file_operations ab8500_bank_fops = { 521static const struct file_operations ab8500_bank_fops = {