On Wed, 21 Sept 2022 at 10:09, Christian Brauner <brauner@xxxxxxxxxx> wrote: > > Feels like this could be simplified while being equally legible to > something like: > > /** > * tmpfile_open - open a tmpfile for kernel internal use > * @mnt_userns: user namespace of the mount the inode was found from > * @parentpath: path of the base directory > * @mode: mode of the new tmpfile > * @open_flag: flags > * @cred: credentials for open > * > * Create and open a temporary file. The file is not accounted in nr_files, > * hence this is only for kernel internal use, and must not be installed into > * file tables or such. > * > * The helper relies on the "noaccount" property of open_with_fake_path(). > * Otherwise it is equivalent to dentry_open(). > * > * Return: Opened tmpfile on success, error pointer on failure. > */ > struct file *tmpfile_open(struct user_namespace *mnt_userns, > const struct path *parentpath, > umode_t mode, int open_flag, const struct cred *cred) > { > struct file *file; > int error; > struct path path = { .mnt = parentpath->mnt }; > > path.dentry = vfs_tmpfile(mnt_userns, parentpath->dentry, mode, open_flag); > if (IS_ERR(path.dentry)) > return ERR_CAST(path.dentry); > > error = may_open(mnt_userns, &path, 0, open_flag); > if (!error) > file = open_with_fake_path(&path, open_flag, d_inode(path.dentry), cred); > else > file = ERR_PTR(error); > dput(path.dentry); > return file; > } > EXPORT_SYMBOL(tmpfile_open); Okay, but this code gets completely rewritten in 7/9, so maybe not worth bothering about. Thanks, Miklos