summaryrefslogtreecommitdiffstats
path: root/arch/sparc/kernel/led.c
diff options
context:
space:
mode:
authorGeliang Tang <geliangtang@gmail.com>2017-05-06 17:40:20 +0200
committerDavid S. Miller <davem@davemloft.net>2017-05-09 21:16:25 +0200
commitaed74ea0a09d2e60e4b3fe45caf30f6365b6c9f3 (patch)
tree94adc10e5fff05f03d65eafc4874b96fd30f83de /arch/sparc/kernel/led.c
parentsparc: Remove redundant tests in boot_flags_init(). (diff)
downloadlinux-aed74ea0a09d2e60e4b3fe45caf30f6365b6c9f3.tar.xz
linux-aed74ea0a09d2e60e4b3fe45caf30f6365b6c9f3.zip
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: Geliang Tang <geliangtang@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc/kernel/led.c')
-rw-r--r--arch/sparc/kernel/led.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c
index 44a3ed93c214..e278bf52963b 100644
--- a/arch/sparc/kernel/led.c
+++ b/arch/sparc/kernel/led.c
@@ -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')