]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/sysfs/symlink.c
Merge branch 'master' of /home/trondmy/kernel/linux-2.6/
[linux-2.6-omap-h63xx.git] / fs / sysfs / symlink.c
index de402fa915f2778e010d20bfeca2c6ebc05f6ddd..7b9c5bfde920fb1ea30af8f81d4313f84bf981ec 100644 (file)
@@ -3,9 +3,11 @@
  */
 
 #include <linux/fs.h>
+#include <linux/mount.h>
 #include <linux/module.h>
 #include <linux/kobject.h>
 #include <linux/namei.h>
+#include <asm/semaphore.h>
 
 #include "sysfs.h"
 
@@ -66,6 +68,7 @@ static int sysfs_add_link(struct dentry * parent, const char * name, struct kobj
        if (!error)
                return 0;
 
+       kobject_put(target);
        kfree(sl->link_name);
 exit2:
        kfree(sl);
@@ -81,14 +84,24 @@ exit1:
  */
 int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name)
 {
-       struct dentry * dentry = kobj->dentry;
-       int error = 0;
+       struct dentry *dentry = NULL;
+       int error = -EEXIST;
+
+       BUG_ON(!name);
 
-       BUG_ON(!kobj || !kobj->dentry || !name);
+       if (!kobj) {
+               if (sysfs_mount && sysfs_mount->mnt_sb)
+                       dentry = sysfs_mount->mnt_sb->s_root;
+       } else
+               dentry = kobj->dentry;
 
-       down(&dentry->d_inode->i_sem);
-       error = sysfs_add_link(dentry, name, target);
-       up(&dentry->d_inode->i_sem);
+       if (!dentry)
+               return -EFAULT;
+
+       mutex_lock(&dentry->d_inode->i_mutex);
+       if (!sysfs_dirent_exist(dentry->d_fsdata, name))
+               error = sysfs_add_link(dentry, name, target);
+       mutex_unlock(&dentry->d_inode->i_mutex);
        return error;
 }
 
@@ -168,7 +181,7 @@ static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *co
                free_page((unsigned long)page);
 }
 
-struct inode_operations sysfs_symlink_inode_operations = {
+const struct inode_operations sysfs_symlink_inode_operations = {
        .readlink = generic_readlink,
        .follow_link = sysfs_follow_link,
        .put_link = sysfs_put_link,
@@ -177,4 +190,3 @@ struct inode_operations sysfs_symlink_inode_operations = {
 
 EXPORT_SYMBOL_GPL(sysfs_create_link);
 EXPORT_SYMBOL_GPL(sysfs_remove_link);
-