mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02: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))
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2859,6 +2859,12 @@ static inline struct filename *getname_maybe_null(const char __user *name, int f
 | 
			
		|||
}
 | 
			
		||||
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,
 | 
			
		||||
			int (*open)(struct inode *, struct file *));
 | 
			
		||||
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) {
 | 
			
		||||
		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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue