sysfs: add sysfs_dirent->s_name
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / sysfs / file.c
index 0e637adc2b872c31d43aecae810c767c31b79e56..8240b1687dd08139b855c407a78cf19a78742214 100644 (file)
@@ -111,36 +111,6 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
        return ret;
 }
 
-
-/**
- *     flush_read_buffer - push buffer to userspace.
- *     @buffer:        data buffer for file.
- *     @buf:           user-passed buffer.
- *     @count:         number of bytes requested.
- *     @ppos:          file position.
- *
- *     Copy the buffer we filled in fill_read_buffer() to userspace.
- *     This is done at the reader's leisure, copying and advancing 
- *     the amount they specify each time.
- *     This may be called continuously until the buffer is empty.
- */
-static int flush_read_buffer(struct sysfs_buffer * buffer, char __user * buf,
-                            size_t count, loff_t * ppos)
-{
-       int error;
-
-       if (*ppos > buffer->count)
-               return 0;
-
-       if (count > (buffer->count - *ppos))
-               count = buffer->count - *ppos;
-
-       error = copy_to_user(buf,buffer->page + *ppos,count);
-       if (!error)
-               *ppos += count;
-       return error ? -EFAULT : count;
-}
-
 /**
  *     sysfs_read_file - read an attribute. 
  *     @file:  file pointer.
@@ -177,7 +147,8 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
        }
        pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
                 __FUNCTION__, count, *ppos, buffer->page);
-       retval = flush_read_buffer(buffer,buf,count,ppos);
+       retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
+                                        buffer->count);
 out:
        up(&buffer->sem);
        return retval;
@@ -473,14 +444,25 @@ int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type)
 {
        struct sysfs_dirent * parent_sd = dir->d_fsdata;
        umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
-       int error = -EEXIST;
+       struct sysfs_dirent *sd;
+       int error = 0;
 
        mutex_lock(&dir->d_inode->i_mutex);
-       if (!sysfs_dirent_exist(parent_sd, attr->name))
-               error = sysfs_make_dirent(parent_sd, NULL, (void *)attr,
-                                         mode, type);
-       mutex_unlock(&dir->d_inode->i_mutex);
 
+       if (sysfs_dirent_exist(parent_sd, attr->name)) {
+               error = -EEXIST;
+               goto out_unlock;
+       }
+
+       sd = sysfs_new_dirent(attr->name, (void *)attr, mode, type);
+       if (!sd) {
+               error = -ENOMEM;
+               goto out_unlock;
+       }
+       sysfs_attach_dirent(sd, parent_sd, NULL);
+
+ out_unlock:
+       mutex_unlock(&dir->d_inode->i_mutex);
        return error;
 }