switched inotify_init1() to alloc_file()
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 5 Aug 2009 14:35:21 +0000 (18:35 +0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 16 Dec 2009 17:16:40 +0000 (12:16 -0500)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/notify/inotify/inotify_user.c

index 5ef5f365a5c86acb32813e7ff9b11d713f54f21b..9e4f90042eaff0d58fe0f5fce1adf9f31914374a 100644 (file)
@@ -659,12 +659,6 @@ SYSCALL_DEFINE1(inotify_init1, int, flags)
        if (fd < 0)
                return fd;
 
-       filp = get_empty_filp();
-       if (!filp) {
-               ret = -ENFILE;
-               goto out_put_fd;
-       }
-
        user = get_current_user();
        if (unlikely(atomic_read(&user->inotify_devs) >=
                        inotify_max_user_instances)) {
@@ -679,24 +673,25 @@ SYSCALL_DEFINE1(inotify_init1, int, flags)
                goto out_free_uid;
        }
 
-       filp->f_op = &inotify_fops;
-       filp->f_path.mnt = mntget(inotify_mnt);
-       filp->f_path.dentry = dget(inotify_mnt->mnt_root);
-       filp->f_mapping = filp->f_path.dentry->d_inode->i_mapping;
-       filp->f_mode = FMODE_READ;
+       atomic_inc(&user->inotify_devs);
+
+       filp = alloc_file(inotify_mnt, dget(inotify_mnt->mnt_root),
+                         FMODE_READ, &inotify_fops);
+       if (!filp)
+               goto Enfile;
+
        filp->f_flags = O_RDONLY | (flags & O_NONBLOCK);
        filp->private_data = group;
 
-       atomic_inc(&user->inotify_devs);
-
        fd_install(fd, filp);
 
        return fd;
 
+Enfile:
+       ret = -ENFILE;
+       atomic_dec(&user->inotify_devs);
 out_free_uid:
        free_uid(user);
-       put_filp(filp);
-out_put_fd:
        put_unused_fd(fd);
        return ret;
 }