Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
[powerpc.git] / fs / sysfs / symlink.c
index d2eac3c..7b9c5bf 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"
 
@@ -82,10 +84,19 @@ exit1:
  */
 int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name)
 {
-       struct dentry * dentry = kobj->dentry;
+       struct dentry *dentry = NULL;
        int error = -EEXIST;
 
-       BUG_ON(!kobj || !kobj->dentry || !name);
+       BUG_ON(!name);
+
+       if (!kobj) {
+               if (sysfs_mount && sysfs_mount->mnt_sb)
+                       dentry = sysfs_mount->mnt_sb->s_root;
+       } else
+               dentry = kobj->dentry;
+
+       if (!dentry)
+               return -EFAULT;
 
        mutex_lock(&dentry->d_inode->i_mutex);
        if (!sysfs_dirent_exist(dentry->d_fsdata, name))
@@ -170,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,