]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/afs/proc.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[karo-tx-linux.git] / fs / afs / proc.c
index 24a905b076fd77268c74978053afef93ba4ef5d9..2853b40953442c44be94c3795caea497606872e4 100644 (file)
@@ -230,14 +230,9 @@ static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
        if (size <= 1 || size >= PAGE_SIZE)
                return -EINVAL;
 
-       kbuf = kmalloc(size + 1, GFP_KERNEL);
-       if (!kbuf)
-               return -ENOMEM;
-
-       ret = -EFAULT;
-       if (copy_from_user(kbuf, buf, size) != 0)
-               goto done;
-       kbuf[size] = 0;
+       kbuf = memdup_user_nul(buf, size);
+       if (IS_ERR(kbuf))
+               return PTR_ERR(kbuf);
 
        /* trim to first NL */
        name = memchr(kbuf, '\n', size);
@@ -315,15 +310,9 @@ static ssize_t afs_proc_rootcell_write(struct file *file,
        if (size <= 1 || size >= PAGE_SIZE)
                return -EINVAL;
 
-       ret = -ENOMEM;
-       kbuf = kmalloc(size + 1, GFP_KERNEL);
-       if (!kbuf)
-               goto nomem;
-
-       ret = -EFAULT;
-       if (copy_from_user(kbuf, buf, size) != 0)
-               goto infault;
-       kbuf[size] = 0;
+       kbuf = memdup_user_nul(buf, size);
+       if (IS_ERR(kbuf))
+               return PTR_ERR(kbuf);
 
        /* trim to first NL */
        s = memchr(kbuf, '\n', size);
@@ -337,9 +326,7 @@ static ssize_t afs_proc_rootcell_write(struct file *file,
        if (ret >= 0)
                ret = size;     /* consume everything, always */
 
-infault:
        kfree(kbuf);
-nomem:
        _leave(" = %d", ret);
        return ret;
 }