Skip to content

Commit 794ebce

Browse files
brenns10Al Viro
authored andcommitted
namei: Standardize callers of filename_lookup()
filename_lookup() has two variants, one which drops the caller's reference to filename (filename_lookup), and one which does not (__filename_lookup). This can be confusing as it's unusual to drop a caller's reference. Remove filename_lookup, rename __filename_lookup to filename_lookup, and convert all callers. The cost is a few slightly longer functions, but the clarity is greater. [AV: consuming a reference is not at all unusual, actually; look at e.g. do_mkdirat(), for example. It's more that we want non-consuming variant for close relative of that function...] Link: https://lore.kernel.org/linux-fsdevel/[email protected]/ Cc: Christoph Hellwig <[email protected]> Cc: Al Viro <[email protected]> Signed-off-by: Stephen Brennan <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent c5f563f commit 794ebce

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

fs/fs_parser.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ int fs_lookup_param(struct fs_context *fc,
165165
return invalf(fc, "%s: not usable as path", param->key);
166166
}
167167

168-
f->refcnt++; /* filename_lookup() drops our ref. */
169168
ret = filename_lookup(param->dirfd, f, flags, _path, NULL);
170169
if (ret < 0) {
171170
errorf(fc, "%s: Lookup failure for '%s'", param->key, f->name);

fs/namei.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,7 +2467,7 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path
24672467
return err;
24682468
}
24692469

2470-
static int __filename_lookup(int dfd, struct filename *name, unsigned flags,
2470+
int filename_lookup(int dfd, struct filename *name, unsigned flags,
24712471
struct path *path, struct path *root)
24722472
{
24732473
int retval;
@@ -2488,15 +2488,6 @@ static int __filename_lookup(int dfd, struct filename *name, unsigned flags,
24882488
return retval;
24892489
}
24902490

2491-
int filename_lookup(int dfd, struct filename *name, unsigned flags,
2492-
struct path *path, struct path *root)
2493-
{
2494-
int retval = __filename_lookup(dfd, name, flags, path, root);
2495-
2496-
putname(name);
2497-
return retval;
2498-
}
2499-
25002491
/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
25012492
static int path_parentat(struct nameidata *nd, unsigned flags,
25022493
struct path *parent)
@@ -2573,8 +2564,12 @@ struct dentry *kern_path_locked(const char *name, struct path *path)
25732564

25742565
int kern_path(const char *name, unsigned int flags, struct path *path)
25752566
{
2576-
return filename_lookup(AT_FDCWD, getname_kernel(name),
2577-
flags, path, NULL);
2567+
struct filename *filename = getname_kernel(name);
2568+
int ret = filename_lookup(AT_FDCWD, filename, flags, path, NULL);
2569+
2570+
putname(filename);
2571+
return ret;
2572+
25782573
}
25792574
EXPORT_SYMBOL(kern_path);
25802575

@@ -2590,10 +2585,15 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
25902585
const char *name, unsigned int flags,
25912586
struct path *path)
25922587
{
2588+
struct filename *filename;
25932589
struct path root = {.mnt = mnt, .dentry = dentry};
2590+
int ret;
2591+
2592+
filename = getname_kernel(name);
25942593
/* the first argument of filename_lookup() is ignored with root */
2595-
return filename_lookup(AT_FDCWD, getname_kernel(name),
2596-
flags , path, &root);
2594+
ret = filename_lookup(AT_FDCWD, filename, flags, path, &root);
2595+
putname(filename);
2596+
return ret;
25972597
}
25982598
EXPORT_SYMBOL(vfs_path_lookup);
25992599

@@ -2797,8 +2797,11 @@ int path_pts(struct path *path)
27972797
int user_path_at_empty(int dfd, const char __user *name, unsigned flags,
27982798
struct path *path, int *empty)
27992799
{
2800-
return filename_lookup(dfd, getname_flags(name, flags, empty),
2801-
flags, path, NULL);
2800+
struct filename *filename = getname_flags(name, flags, empty);
2801+
int ret = filename_lookup(dfd, filename, flags, path, NULL);
2802+
2803+
putname(filename);
2804+
return ret;
28022805
}
28032806
EXPORT_SYMBOL(user_path_at_empty);
28042807

@@ -4425,7 +4428,7 @@ int do_linkat(int olddfd, struct filename *old, int newdfd,
44254428
if (flags & AT_SYMLINK_FOLLOW)
44264429
how |= LOOKUP_FOLLOW;
44274430
retry:
4428-
error = __filename_lookup(olddfd, old, how, &old_path, NULL);
4431+
error = filename_lookup(olddfd, old, how, &old_path, NULL);
44294432
if (error)
44304433
goto out_putnames;
44314434

0 commit comments

Comments
 (0)