mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
fs: dedup handling of struct filename init and refcounts bumps
No functional changes. Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://lore.kernel.org/r/20250313142744.1323281-1-mjguzik@gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
f381640e1b
commit
611851010c
3 changed files with 20 additions and 15 deletions
17
fs/namei.c
17
fs/namei.c
|
@ -125,6 +125,13 @@
|
||||||
|
|
||||||
#define EMBEDDED_NAME_MAX (PATH_MAX - offsetof(struct filename, iname))
|
#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 *
|
struct filename *
|
||||||
getname_flags(const char __user *filename, int flags)
|
getname_flags(const char __user *filename, int flags)
|
||||||
{
|
{
|
||||||
|
@ -203,10 +210,7 @@ getname_flags(const char __user *filename, int flags)
|
||||||
return ERR_PTR(-ENAMETOOLONG);
|
return ERR_PTR(-ENAMETOOLONG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
initname(result);
|
||||||
atomic_set(&result->refcnt, 1);
|
|
||||||
result->uptr = filename;
|
|
||||||
result->aname = NULL;
|
|
||||||
audit_getname(result);
|
audit_getname(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -264,11 +268,8 @@ struct filename *getname_kernel(const char * filename)
|
||||||
return ERR_PTR(-ENAMETOOLONG);
|
return ERR_PTR(-ENAMETOOLONG);
|
||||||
}
|
}
|
||||||
memcpy((char *)result->name, filename, len);
|
memcpy((char *)result->name, filename, len);
|
||||||
result->uptr = NULL;
|
initname(result);
|
||||||
result->aname = NULL;
|
|
||||||
atomic_set(&result->refcnt, 1);
|
|
||||||
audit_getname(result);
|
audit_getname(result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(getname_kernel);
|
EXPORT_SYMBOL(getname_kernel);
|
||||||
|
|
|
@ -2859,6 +2859,12 @@ static inline struct filename *getname_maybe_null(const char __user *name, int f
|
||||||
}
|
}
|
||||||
extern void putname(struct filename *name);
|
extern void putname(struct filename *name);
|
||||||
|
|
||||||
|
static inline struct filename *refname(struct filename *name)
|
||||||
|
{
|
||||||
|
atomic_inc(&name->refcnt);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
extern int finish_open(struct file *file, struct dentry *dentry,
|
extern int finish_open(struct file *file, struct dentry *dentry,
|
||||||
int (*open)(struct inode *, struct file *));
|
int (*open)(struct inode *, struct file *));
|
||||||
extern int finish_no_open(struct file *file, struct dentry *dentry);
|
extern int finish_no_open(struct file *file, struct dentry *dentry);
|
||||||
|
|
|
@ -2207,10 +2207,8 @@ __audit_reusename(const __user char *uptr)
|
||||||
list_for_each_entry(n, &context->names_list, list) {
|
list_for_each_entry(n, &context->names_list, list) {
|
||||||
if (!n->name)
|
if (!n->name)
|
||||||
continue;
|
continue;
|
||||||
if (n->name->uptr == uptr) {
|
if (n->name->uptr == uptr)
|
||||||
atomic_inc(&n->name->refcnt);
|
return refname(n->name);
|
||||||
return n->name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2237,7 +2235,7 @@ void __audit_getname(struct filename *name)
|
||||||
n->name = name;
|
n->name = name;
|
||||||
n->name_len = AUDIT_NAME_FULL;
|
n->name_len = AUDIT_NAME_FULL;
|
||||||
name->aname = n;
|
name->aname = n;
|
||||||
atomic_inc(&name->refcnt);
|
refname(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int audit_copy_fcaps(struct audit_names *name,
|
static inline int audit_copy_fcaps(struct audit_names *name,
|
||||||
|
@ -2369,7 +2367,7 @@ out_alloc:
|
||||||
return;
|
return;
|
||||||
if (name) {
|
if (name) {
|
||||||
n->name = name;
|
n->name = name;
|
||||||
atomic_inc(&name->refcnt);
|
refname(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -2496,7 +2494,7 @@ void __audit_inode_child(struct inode *parent,
|
||||||
if (found_parent) {
|
if (found_parent) {
|
||||||
found_child->name = found_parent->name;
|
found_child->name = found_parent->name;
|
||||||
found_child->name_len = AUDIT_NAME_FULL;
|
found_child->name_len = AUDIT_NAME_FULL;
|
||||||
atomic_inc(&found_child->name->refcnt);
|
refname(found_child->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue