Commit aed74ea0 authored by Geliang Tang's avatar Geliang Tang Committed by David S. Miller

sparc: use memdup_user_nul in sun4m LED driver

Use memdup_user_nul() helper instead of open-coding to simplify the code.
Signed-off-by: default avatarGeliang Tang <geliangtang@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8c64415c
...@@ -70,16 +70,9 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer, ...@@ -70,16 +70,9 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer,
if (count > LED_MAX_LENGTH) if (count > LED_MAX_LENGTH)
count = LED_MAX_LENGTH; count = LED_MAX_LENGTH;
buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL); buf = memdup_user_nul(buffer, count);
if (!buf) if (IS_ERR(buf))
return -ENOMEM; return PTR_ERR(buf);
if (copy_from_user(buf, buffer, count)) {
kfree(buf);
return -EFAULT;
}
buf[count] = '\0';
/* work around \n when echo'ing into proc */ /* work around \n when echo'ing into proc */
if (buf[count - 1] == '\n') if (buf[count - 1] == '\n')
......
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