fs: dedup handling of struct filename init and refcounts bumps
PATCH 1/1 fs: dedup handling of struct filename init and refcounts bumps
No functional changes.
---
This is extracted from the patch which tried to introduce optional non-atomic operation.
I think this is an ok cleanup, but I'm not going to argue about it.
ultimately this is a big NOP
fs/namei.c | 17 +++++++++-------- include/linux/fs.h | 6 ++++++ kernel/auditsc.c | 12 +++++------- 3 files changed, 20 insertions(+), 15 deletions(-)
fs/namei.c +9 -8
@@ -125,6 +125,13 @@#define EMBEDDED_NAME_MAX (PATH_MAX - offsetof(struct filename, iname)) +static inline void initname (struct filename *name) +{ + name->uptr =NULL ; + name->aname =NULL ; +atomic_set (&name->refcnt,1 ); +} +struct filename *getname_flags (const char __user *filename,int flags) {
@@ -203,10 +210,7 @@ getname_flags(const char __user *filename, int flags)return ERR_PTR (-ENAMETOOLONG ); } } - -atomic_set (&result->refcnt,1 ); - result->uptr = filename; - result->aname =NULL ; +initname (result);audit_getname (result);return result; }
@@ -264,11 +268,8 @@ struct filename *getname_kernel(const char * filename)return ERR_PTR (-ENAMETOOLONG ); }memcpy ((char *)result->name, filename, len); - result->uptr =NULL ; - result->aname =NULL ; -atomic_set (&result->refcnt,1 ); +initname (result);audit_getname (result); -return result; }EXPORT_SYMBOL (getname_kernel);
include/linux/fs.h +6 -0
@@ -2865,6 +2865,12 @@ static inline struct filename *getname_maybe_null(const char __user *name, int fextern void putname (struct filename *name); DEFINE_FREE(putname, struct filename *, if (!IS_ERR_OR_NULL(_T)) putname(_T)) +static inline struct filename *refname (struct filename *name) +{ +atomic_inc (&name->refcnt); +return name; +} +extern int finish_open (struct file *file,struct dentry *dentry,int (*open)(struct inode *,struct file *));extern int finish_no_open (struct file *file,struct dentry *dentry);
kernel/auditsc.c +5 -7
@@ -2207,10 +2207,8 @@ __audit_reusename(const __user char *uptr)list_for_each_entry (n, &context->names_list, list) {if (!n->name)continue ; -if (n->name->uptr == uptr) { -atomic_inc (&n->name->refcnt); -return n->name; - } +if (n->name->uptr == uptr) +return refname (n->name); }return NULL ; }
@@ -2237,7 +2235,7 @@ void __audit_getname(struct filename *name) n->name = name; n->name_len =AUDIT_NAME_FULL ; name->aname = n; -atomic_inc (&name->refcnt); +refname (name); } static inline int audit_copy_fcaps(struct audit_names *name,
@@ -2369,7 +2367,7 @@ void __audit_inode(struct filename *name, const struct dentry *dentry,return ;if (name) { n->name = name; -atomic_inc (&name->refcnt); +refname (name); } out:
@@ -2496,7 +2494,7 @@ void __audit_inode_child(struct inode *parent,if (found_parent) { found_child->name = found_parent->name; found_child->name_len =AUDIT_NAME_FULL ; -atomic_inc (&found_child->name->refcnt); +refname (found_child->name); } }
Signature · 1 line
2.43.0
Quoted 3 lines · Mateusz Guzik
No functional changes.
Applied to the vfs-6.15.misc branch of the vfs/vfs.git tree. Patches in the vfs-6.15.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.15.misc
[1/1] fs: dedup handling of struct filename init and refcounts bumps
https://git.kernel.org/vfs/vfs/c/e05a35026336