]> git.ipfire.org Git - thirdparty/kernel/stable.git/blobdiff - mm/shmem.c
Merge branch 'work.open3' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[thirdparty/kernel/stable.git] / mm / shmem.c
index 41b9bbf24e16b49db1da4be286fe7310941ad542..96bcc51fb9ec7ffcbe4df1202bbc23439e6d2f57 100644 (file)
@@ -3897,18 +3897,11 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range);
 
 /* common code */
 
-static const struct dentry_operations anon_ops = {
-       .d_dname = simple_dname
-};
-
 static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, loff_t size,
                                       unsigned long flags, unsigned int i_flags)
 {
-       struct file *res;
        struct inode *inode;
-       struct path path;
-       struct super_block *sb;
-       struct qstr this;
+       struct file *res;
 
        if (IS_ERR(mnt))
                return ERR_CAST(mnt);
@@ -3919,41 +3912,21 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, l
        if (shmem_acct_size(flags, size))
                return ERR_PTR(-ENOMEM);
 
-       res = ERR_PTR(-ENOMEM);
-       this.name = name;
-       this.len = strlen(name);
-       this.hash = 0; /* will go */
-       sb = mnt->mnt_sb;
-       path.mnt = mntget(mnt);
-       path.dentry = d_alloc_pseudo(sb, &this);
-       if (!path.dentry)
-               goto put_memory;
-       d_set_d_op(path.dentry, &anon_ops);
-
-       res = ERR_PTR(-ENOSPC);
-       inode = shmem_get_inode(sb, NULL, S_IFREG | 0777, 0, flags);
-       if (!inode)
-               goto put_memory;
-
+       inode = shmem_get_inode(mnt->mnt_sb, NULL, S_IFREG | S_IRWXUGO, 0,
+                               flags);
+       if (unlikely(!inode)) {
+               shmem_unacct_size(flags, size);
+               return ERR_PTR(-ENOSPC);
+       }
        inode->i_flags |= i_flags;
-       d_instantiate(path.dentry, inode);
        inode->i_size = size;
        clear_nlink(inode);     /* It is unlinked */
        res = ERR_PTR(ramfs_nommu_expand_for_mapping(inode, size));
+       if (!IS_ERR(res))
+               res = alloc_file_pseudo(inode, mnt, name, O_RDWR,
+                               &shmem_file_operations);
        if (IS_ERR(res))
-               goto put_path;
-
-       res = alloc_file(&path, FMODE_WRITE | FMODE_READ,
-                 &shmem_file_operations);
-       if (IS_ERR(res))
-               goto put_path;
-
-       return res;
-
-put_memory:
-       shmem_unacct_size(flags, size);
-put_path:
-       path_put(&path);
+               iput(inode);
        return res;
 }