configfs: handle kzalloc() failure in check_perm()
[firefly-linux-kernel-4.4.55.git] / fs / configfs / file.c
index c26cd61f13afd3c9cc02ff7799ff95c58f622df5..cf33fac68c840cccc21ac91c617064ac36f90097 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <linux/fs.h>
 #include <linux/module.h>
-#include <linux/dnotify.h>
 #include <linux/slab.h>
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
@@ -138,8 +137,8 @@ configfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *pp
                if ((retval = fill_read_buffer(file->f_dentry,buffer)))
                        goto out;
        }
-       pr_debug("%s: count = %d, ppos = %lld, buf = %s\n",
-                __FUNCTION__,count,*ppos,buffer->page);
+       pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
+                __FUNCTION__, count, *ppos, buffer->page);
        retval = flush_read_buffer(buffer,buf,count,ppos);
 out:
        up(&buffer->sem);
@@ -150,7 +149,7 @@ out:
 /**
  *     fill_write_buffer - copy buffer from userspace.
  *     @buffer:        data buffer for file.
- *     @userbuf:       data from user.
+ *     @buf:           data from user.
  *     @count:         number of bytes in @userbuf.
  *
  *     Allocate @buffer->page if it hasn't been already, then
@@ -177,8 +176,9 @@ fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size
 
 /**
  *     flush_write_buffer - push buffer to config_item.
- *     @file:          file pointer.
+ *     @dentry:        dentry to the attribute
  *     @buffer:        data buffer for file.
+ *     @count:         number of bytes
  *
  *     Get the correct pointers for the config_item and the attribute we're
  *     dealing with, then call the store() method for the attribute,
@@ -217,15 +217,16 @@ static ssize_t
 configfs_write_file(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
 {
        struct configfs_buffer * buffer = file->private_data;
+       ssize_t len;
 
        down(&buffer->sem);
-       count = fill_write_buffer(buffer,buf,count);
-       if (count > 0)
-               count = flush_write_buffer(file->f_dentry,buffer,count);
-       if (count > 0)
-               *ppos += count;
+       len = fill_write_buffer(buffer, buf, count);
+       if (len > 0)
+               len = flush_write_buffer(file->f_dentry, buffer, count);
+       if (len > 0)
+               *ppos += len;
        up(&buffer->sem);
-       return count;
+       return len;
 }
 
 static int check_perm(struct inode * inode, struct file * file)
@@ -273,15 +274,15 @@ static int check_perm(struct inode * inode, struct file * file)
        /* No error? Great, allocate a buffer for the file, and store it
         * it in file->private_data for easy access.
         */
-       buffer = kmalloc(sizeof(struct configfs_buffer),GFP_KERNEL);
-       if (buffer) {
-               memset(buffer,0,sizeof(struct configfs_buffer));
-               init_MUTEX(&buffer->sem);
-               buffer->needs_read_fill = 1;
-               buffer->ops = ops;
-               file->private_data = buffer;
-       } else
+       buffer = kzalloc(sizeof(struct configfs_buffer),GFP_KERNEL);
+       if (!buffer) {
                error = -ENOMEM;
+               goto Enomem;
+       }
+       init_MUTEX(&buffer->sem);
+       buffer->needs_read_fill = 1;
+       buffer->ops = ops;
+       file->private_data = buffer;
        goto Done;
 
  Einval:
@@ -289,6 +290,7 @@ static int check_perm(struct inode * inode, struct file * file)
        goto Done;
  Eaccess:
        error = -EACCES;
+ Enomem:
        module_put(attr->ca_owner);
  Done:
        if (error && item)
@@ -321,7 +323,7 @@ static int configfs_release(struct inode * inode, struct file * filp)
        return 0;
 }
 
-struct file_operations configfs_file_operations = {
+const struct file_operations configfs_file_operations = {
        .read           = configfs_read_file,
        .write          = configfs_write_file,
        .llseek         = generic_file_llseek,