Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Peter Huewe and committed by
Samuel Ortiz
8504d638 402fb487

+11 -30
+11 -30
drivers/mfd/ab8500-debugfs.c
··· 419 419 size_t count, loff_t *ppos) 420 420 { 421 421 struct device *dev = ((struct seq_file *)(file->private_data))->private; 422 - char buf[32]; 423 - int buf_size; 424 422 unsigned long user_bank; 425 423 int err; 426 424 427 425 /* Get userspace string and assure termination */ 428 - buf_size = min(count, (sizeof(buf) - 1)); 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); 426 + err = kstrtoul_from_user(user_buf, count, 0, &user_bank); 434 427 if (err) 435 - return -EINVAL; 428 + return err; 436 429 437 430 if (user_bank >= AB8500_NUM_BANKS) { 438 431 dev_err(dev, "debugfs error input > number of banks\n"); ··· 434 441 435 442 debug_bank = user_bank; 436 443 437 - return buf_size; 444 + return count; 438 445 } 439 446 440 447 static int ab8500_address_print(struct seq_file *s, void *p) ··· 452 459 size_t count, loff_t *ppos) 453 460 { 454 461 struct device *dev = ((struct seq_file *)(file->private_data))->private; 455 - char buf[32]; 456 - int buf_size; 457 462 unsigned long user_address; 458 463 int err; 459 464 460 465 /* Get userspace string and assure termination */ 461 - buf_size = min(count, (sizeof(buf) - 1)); 462 - if (copy_from_user(buf, user_buf, buf_size)) 463 - return -EFAULT; 464 - buf[buf_size] = 0; 465 - 466 - err = strict_strtoul(buf, 0, &user_address); 466 + err = kstrtoul_from_user(user_buf, count, 0, &user_address); 467 467 if (err) 468 - return -EINVAL; 468 + return err; 469 + 469 470 if (user_address > 0xff) { 470 471 dev_err(dev, "debugfs error input > 0xff\n"); 471 472 return -EINVAL; 472 473 } 473 474 debug_address = user_address; 474 - return buf_size; 475 + return count; 475 476 } 476 477 477 478 static int ab8500_val_print(struct seq_file *s, void *p) ··· 496 509 size_t count, loff_t *ppos) 497 510 { 498 511 struct device *dev = ((struct seq_file *)(file->private_data))->private; 499 - char buf[32]; 500 - int buf_size; 501 512 unsigned long user_val; 502 513 int err; 503 514 504 515 /* Get userspace string and assure termination */ 505 - buf_size = min(count, (sizeof(buf)-1)); 506 - if (copy_from_user(buf, user_buf, buf_size)) 507 - return -EFAULT; 508 - buf[buf_size] = 0; 509 - 510 - err = strict_strtoul(buf, 0, &user_val); 516 + err = kstrtoul_from_user(user_buf, count, 0, &user_val); 511 517 if (err) 512 - return -EINVAL; 518 + return err; 519 + 513 520 if (user_val > 0xff) { 514 521 dev_err(dev, "debugfs error input > 0xff\n"); 515 522 return -EINVAL; ··· 515 534 return -EINVAL; 516 535 } 517 536 518 - return buf_size; 537 + return count; 519 538 } 520 539 521 540 static const struct file_operations ab8500_bank_fops = {