On Tue, Sep 20, 2022 at 09:36:27PM +0200, Miklos Szeredi wrote: > Use the tmpfile_open() helper instead of doing tmpfile creation and opening > separately. > > Signed-off-by: Miklos Szeredi <mszeredi@xxxxxxxxxx> > --- > fs/cachefiles/namei.c | 26 ++++++++++---------------- > 1 file changed, 10 insertions(+), 16 deletions(-) > > diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c > index d3a5884fe5c9..44f575328af4 100644 > --- a/fs/cachefiles/namei.c > +++ b/fs/cachefiles/namei.c > @@ -451,18 +451,19 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object) > const struct cred *saved_cred; > struct dentry *fan = volume->fanout[(u8)object->cookie->key_hash]; > struct file *file; > - struct path path; > + struct path path = { .mnt = cache->mnt, .dentry = fan }; > uint64_t ni_size; > long ret; Maybe we shouldn't use struct path to first refer to the parent path and then to the tmp path to avoid any potential confusion and instead rely on a compount initializer for the tmpfile_open() call (__not tested__)?: diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c index 44f575328af4..979b2f173ac3 100644 --- a/fs/cachefiles/namei.c +++ b/fs/cachefiles/namei.c @@ -451,7 +451,7 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object) const struct cred *saved_cred; struct dentry *fan = volume->fanout[(u8)object->cookie->key_hash]; struct file *file; - struct path path = { .mnt = cache->mnt, .dentry = fan }; + struct path path; uint64_t ni_size; long ret; @@ -460,8 +460,10 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object) ret = cachefiles_inject_write_error(); if (ret == 0) { - file = tmpfile_open(&init_user_ns, &path, S_IFREG, - O_RDWR | O_LARGEFILE | O_DIRECT, + file = tmpfile_open(&init_user_ns, + &{const struct path} {.mnt = cache->mnt, + .dentry = fan}, + S_IFREG, O_RDWR | O_LARGEFILE | O_DIRECT, cache->cache_cred); ret = PTR_ERR_OR_ZERO(file); } @@ -472,7 +474,9 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object) cachefiles_io_error_obj(object, "Failed to create tmpfile"); goto err; } - /* From now path refers to the tmpfile */ + + /* prepare tmp path */ + path.mnt = cache->mnt; path.dentry = file->f_path.dentry; trace_cachefiles_tmpfile(object, d_backing_inode(path.dentry));