Skip to content

Commit

Permalink
sparc: use memdup_user_nul in sun4m LED driver
Browse files Browse the repository at this point in the history
Use memdup_user_nul() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
geliangtang authored and davem330 committed May 9, 2017
1 parent 8c64415 commit aed74ea
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions arch/sparc/kernel/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,9 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer,
if (count > LED_MAX_LENGTH)
count = LED_MAX_LENGTH;

buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL);
if (!buf)
return -ENOMEM;

if (copy_from_user(buf, buffer, count)) {
kfree(buf);
return -EFAULT;
}

buf[count] = '\0';
buf = memdup_user_nul(buffer, count);
if (IS_ERR(buf))
return PTR_ERR(buf);

/* work around \n when echo'ing into proc */
if (buf[count - 1] == '\n')
Expand Down

0 comments on commit aed74ea

Please sign in to comment.