From c9c554f21490bbc96cc554f80024d27d09670480 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 11 Jul 2018 14:19:04 -0400 Subject: alloc_file(): switch to passing O_... flags instead of FMODE_... mode ... so that it could set both ->f_flags and ->f_mode, without callers having to set ->f_flags manually. Signed-off-by: Al Viro --- mm/memfd.c | 2 +- mm/shmem.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'mm') diff --git a/mm/memfd.c b/mm/memfd.c index 27069518e3c5..2bb5e257080e 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -326,7 +326,7 @@ SYSCALL_DEFINE2(memfd_create, goto err_fd; } file->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE; - file->f_flags |= O_RDWR | O_LARGEFILE; + file->f_flags |= O_LARGEFILE; if (flags & MFD_ALLOW_SEALING) { file_seals = memfd_file_seals_ptr(file); diff --git a/mm/shmem.c b/mm/shmem.c index 2cab84403055..84844e52bf24 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3942,8 +3942,7 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, l if (IS_ERR(res)) goto put_path; - res = alloc_file(&path, FMODE_WRITE | FMODE_READ, - &shmem_file_operations); + res = alloc_file(&path, O_RDWR, &shmem_file_operations); if (IS_ERR(res)) goto put_path; -- cgit v1.2.3 From dac2d1f6cbfe3f63867a601d2431b7749d9bdbcf Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 9 Jun 2018 09:27:41 -0400 Subject: __shmem_file_setup(): reorder allocations grab inode and reserve memory first. Acked-by: Linus Torvalds Signed-off-by: Al Viro --- mm/shmem.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'mm') diff --git a/mm/shmem.c b/mm/shmem.c index 84844e52bf24..35aabed7d64d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3918,40 +3918,37 @@ 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); + sb = mnt->mnt_sb; + inode = shmem_get_inode(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; + inode->i_size = size; + clear_nlink(inode); /* It is unlinked */ + res = ERR_PTR(ramfs_nommu_expand_for_mapping(inode, size)); + if (IS_ERR(res)) { + iput(inode); + return res; + } + 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; + if (!path.dentry) { + iput(inode); + return ERR_PTR(-ENOMEM); + } 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->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)) - goto put_path; res = alloc_file(&path, O_RDWR, &shmem_file_operations); if (IS_ERR(res)) - goto put_path; - - return res; - -put_memory: - shmem_unacct_size(flags, size); -put_path: - path_put(&path); + path_put(&path); return res; } -- cgit v1.2.3 From 93dec2da7b2349f0b294bbb23244cac135f13b79 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 8 Jul 2018 23:02:03 -0400 Subject: ... and switch shmem_file_setup() to alloc_file_pseudo() Acked-by: Linus Torvalds Signed-off-by: Al Viro --- mm/shmem.c | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) (limited to 'mm') diff --git a/mm/shmem.c b/mm/shmem.c index 35aabed7d64d..d7e984141be5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3896,18 +3896,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); @@ -3918,8 +3911,8 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, l if (shmem_acct_size(flags, size)) return ERR_PTR(-ENOMEM); - sb = mnt->mnt_sb; - inode = shmem_get_inode(sb, NULL, S_IFREG | S_IRWXUGO, 0, flags); + 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); @@ -3928,27 +3921,11 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, l inode->i_size = size; clear_nlink(inode); /* It is unlinked */ res = ERR_PTR(ramfs_nommu_expand_for_mapping(inode, size)); - if (IS_ERR(res)) { - iput(inode); - return res; - } - - this.name = name; - this.len = strlen(name); - this.hash = 0; /* will go */ - path.mnt = mntget(mnt); - path.dentry = d_alloc_pseudo(sb, &this); - if (!path.dentry) { - iput(inode); - return ERR_PTR(-ENOMEM); - } - d_set_d_op(path.dentry, &anon_ops); - - d_instantiate(path.dentry, inode); - - res = alloc_file(&path, O_RDWR, &shmem_file_operations); + if (!IS_ERR(res)) + res = alloc_file_pseudo(inode, mnt, name, O_RDWR, + &shmem_file_operations); if (IS_ERR(res)) - path_put(&path); + iput(inode); return res; } -- cgit v1.2.3