]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/sysfs/file.c
sysfs: Introduce sysfs_rename_mutex
[linux-2.6-omap-h63xx.git] / fs / sysfs / file.c
index 3e1cc062a74030687013da9c386476f3a164975f..ff93c92164b308c8536d6045642b7f5ee5c9e439 100644 (file)
@@ -8,8 +8,8 @@
 #include <linux/namei.h>
 #include <linux/poll.h>
 #include <linux/list.h>
+#include <linux/mutex.h>
 #include <asm/uaccess.h>
-#include <asm/semaphore.h>
 
 #include "sysfs.h"
 
@@ -55,7 +55,7 @@ struct sysfs_buffer {
        loff_t                  pos;
        char                    * page;
        struct sysfs_ops        * ops;
-       struct semaphore        sem;
+       struct mutex            mutex;
        int                     needs_read_fill;
        int                     event;
 };
@@ -128,7 +128,7 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
        struct sysfs_buffer * buffer = file->private_data;
        ssize_t retval = 0;
 
-       down(&buffer->sem);
+       mutex_lock(&buffer->mutex);
        if (buffer->needs_read_fill) {
                retval = fill_read_buffer(file->f_path.dentry,buffer);
                if (retval)
@@ -139,7 +139,7 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
        retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
                                         buffer->count);
 out:
-       up(&buffer->sem);
+       mutex_unlock(&buffer->mutex);
        return retval;
 }
 
@@ -228,13 +228,13 @@ sysfs_write_file(struct file *file, const char __user *buf, size_t count, loff_t
        struct sysfs_buffer * buffer = file->private_data;
        ssize_t len;
 
-       down(&buffer->sem);
+       mutex_lock(&buffer->mutex);
        len = fill_write_buffer(buffer, buf, count);
        if (len > 0)
                len = flush_write_buffer(file->f_path.dentry, buffer, len);
        if (len > 0)
                *ppos += len;
-       up(&buffer->sem);
+       mutex_unlock(&buffer->mutex);
        return len;
 }
 
@@ -294,7 +294,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
        if (!buffer)
                goto err_out;
 
-       init_MUTEX(&buffer->sem);
+       mutex_init(&buffer->mutex);
        buffer->needs_read_fill = 1;
        buffer->ops = ops;
        file->private_data = buffer;
@@ -335,7 +335,7 @@ static int sysfs_release(struct inode * inode, struct file * filp)
  * again will not get new data, or reset the state of 'poll'.
  * Reminder: this only works for attributes which actively support
  * it, and it is not possible to test an attribute from userspace
- * to see if it supports poll (Nether 'poll' or 'select' return
+ * to see if it supports poll (Neither 'poll' nor 'select' return
  * an appropriate error code).  When in doubt, set a suitable timeout value.
  */
 static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
@@ -397,6 +397,7 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
        umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
        struct sysfs_addrm_cxt acxt;
        struct sysfs_dirent *sd;
+       int rc;
 
        sd = sysfs_new_dirent(attr->name, mode, type);
        if (!sd)
@@ -404,18 +405,13 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
        sd->s_elem.attr.attr = (void *)attr;
 
        sysfs_addrm_start(&acxt, dir_sd);
+       rc = sysfs_add_one(&acxt, sd);
+       sysfs_addrm_finish(&acxt);
 
-       if (!sysfs_find_dirent(dir_sd, attr->name)) {
-               sysfs_add_one(&acxt, sd);
-               sysfs_link_sibling(sd);
-       }
-
-       if (!sysfs_addrm_finish(&acxt)) {
+       if (rc)
                sysfs_put(sd);
-               return -EEXIST;
-       }
 
-       return 0;
+       return rc;
 }
 
 
@@ -474,7 +470,9 @@ int sysfs_update_file(struct kobject * kobj, const struct attribute * attr)
        if (!victim_sd)
                goto out;
 
+       mutex_lock(&sysfs_rename_mutex);
        victim = sysfs_get_dentry(victim_sd);
+       mutex_unlock(&sysfs_rename_mutex);
        if (IS_ERR(victim)) {
                rc = PTR_ERR(victim);
                victim = NULL;
@@ -513,7 +511,9 @@ int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
        if (!victim_sd)
                goto out;
 
+       mutex_lock(&sysfs_rename_mutex);
        victim = sysfs_get_dentry(victim_sd);
+       mutex_unlock(&sysfs_rename_mutex);
        if (IS_ERR(victim)) {
                rc = PTR_ERR(victim);
                victim = NULL;