sparc: use memdup_user_nul in sun4m LED driver
authorGeliang Tang <geliangtang@gmail.com>
Sat, 6 May 2017 15:40:20 +0000 (23:40 +0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 9 May 2017 19:16:25 +0000 (12:16 -0700)
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>
arch/sparc/kernel/led.c

index 44a3ed93c214c5ad785386c1f7ad604525721025..e278bf52963b58e834ca21015ac59c2a84fe6ec0 100644 (file)
@@ -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')