driver core: module.c: Use kasprintf
[safe/jmp/linux-2.6] / drivers / base / devtmpfs.c
index 50375bb..057cf11 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/cred.h>
 #include <linux/sched.h>
 #include <linux/init_task.h>
+#include <linux/slab.h>
 
 static struct vfsmount *dev_mnt;
 
@@ -32,7 +33,7 @@ static int dev_mount = 1;
 static int dev_mount;
 #endif
 
-static rwlock_t dirlock;
+static DEFINE_MUTEX(dirlock);
 
 static int __init mount_param(char *str)
 {
@@ -93,7 +94,7 @@ static int create_path(const char *nodepath)
 {
        int err;
 
-       read_lock(&dirlock);
+       mutex_lock(&dirlock);
        err = dev_mkdir(nodepath, 0755);
        if (err == -ENOENT) {
                char *path;
@@ -101,8 +102,10 @@ static int create_path(const char *nodepath)
 
                /* parent directories do not exist, create them */
                path = kstrdup(nodepath, GFP_KERNEL);
-               if (!path)
-                       return -ENOMEM;
+               if (!path) {
+                       err = -ENOMEM;
+                       goto out;
+               }
                s = path;
                for (;;) {
                        s = strchr(s, '/');
@@ -117,7 +120,8 @@ static int create_path(const char *nodepath)
                }
                kfree(path);
        }
-       read_unlock(&dirlock);
+out:
+       mutex_unlock(&dirlock);
        return err;
 }
 
@@ -229,7 +233,7 @@ static int delete_path(const char *nodepath)
        if (!path)
                return -ENOMEM;
 
-       write_lock(&dirlock);
+       mutex_lock(&dirlock);
        for (;;) {
                char *base;
 
@@ -241,7 +245,7 @@ static int delete_path(const char *nodepath)
                if (err)
                        break;
        }
-       write_unlock(&dirlock);
+       mutex_unlock(&dirlock);
 
        kfree(path);
        return err;
@@ -298,6 +302,19 @@ int devtmpfs_delete_node(struct device *dev)
                if (dentry->d_inode) {
                        err = vfs_getattr(nd.path.mnt, dentry, &stat);
                        if (!err && dev_mynode(dev, dentry->d_inode, &stat)) {
+                               struct iattr newattrs;
+                               /*
+                                * before unlinking this node, reset permissions
+                                * of possible references like hardlinks
+                                */
+                               newattrs.ia_uid = 0;
+                               newattrs.ia_gid = 0;
+                               newattrs.ia_mode = stat.mode & ~0777;
+                               newattrs.ia_valid =
+                                       ATTR_UID|ATTR_GID|ATTR_MODE;
+                               mutex_lock(&dentry->d_inode->i_mutex);
+                               notify_change(dentry, &newattrs);
+                               mutex_unlock(&dentry->d_inode->i_mutex);
                                err = vfs_unlink(nd.path.dentry->d_inode,
                                                 dentry);
                                if (!err || err == -ENOENT)
@@ -351,8 +368,7 @@ int __init devtmpfs_init(void)
 {
        int err;
        struct vfsmount *mnt;
-
-       rwlock_init(&dirlock);
+       char options[] = "mode=0755";
 
        err = register_filesystem(&dev_fs_type);
        if (err) {
@@ -361,7 +377,7 @@ int __init devtmpfs_init(void)
                return err;
        }
 
-       mnt = kern_mount_data(&dev_fs_type, "mode=0755");
+       mnt = kern_mount_data(&dev_fs_type, options);
        if (IS_ERR(mnt)) {
                err = PTR_ERR(mnt);
                printk(KERN_ERR "devtmpfs: unable to create devtmpfs %i\n", err);