Skip to content

Commit 3c95f0d

Browse files
author
Al Viro
committed
merge common parts of lookup_one_len{,_unlocked} into common helper
Signed-off-by: Al Viro <[email protected]>
1 parent 04bbc97 commit 3c95f0d

File tree

1 file changed

+34
-56
lines changed

1 file changed

+34
-56
lines changed

fs/namei.c

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,52 +2417,57 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
24172417
}
24182418
EXPORT_SYMBOL(vfs_path_lookup);
24192419

2420-
/**
2421-
* lookup_one_len - filesystem helper to lookup single pathname component
2422-
* @name: pathname component to lookup
2423-
* @base: base directory to lookup from
2424-
* @len: maximum length @len should be interpreted to
2425-
*
2426-
* Note that this routine is purely a helper for filesystem usage and should
2427-
* not be called by generic code.
2428-
*
2429-
* The caller must hold base->i_mutex.
2430-
*/
2431-
struct dentry *lookup_one_len(const char *name, struct dentry *base, int len)
2420+
static int lookup_one_len_common(const char *name, struct dentry *base,
2421+
int len, struct qstr *this)
24322422
{
2433-
struct qstr this;
2434-
unsigned int c;
2435-
int err;
2436-
2437-
WARN_ON_ONCE(!inode_is_locked(base->d_inode));
2438-
2439-
this.name = name;
2440-
this.len = len;
2441-
this.hash = full_name_hash(base, name, len);
2423+
this->name = name;
2424+
this->len = len;
2425+
this->hash = full_name_hash(base, name, len);
24422426
if (!len)
2443-
return ERR_PTR(-EACCES);
2427+
return -EACCES;
24442428

24452429
if (unlikely(name[0] == '.')) {
24462430
if (len < 2 || (len == 2 && name[1] == '.'))
2447-
return ERR_PTR(-EACCES);
2431+
return -EACCES;
24482432
}
24492433

24502434
while (len--) {
2451-
c = *(const unsigned char *)name++;
2435+
unsigned int c = *(const unsigned char *)name++;
24522436
if (c == '/' || c == '\0')
2453-
return ERR_PTR(-EACCES);
2437+
return -EACCES;
24542438
}
24552439
/*
24562440
* See if the low-level filesystem might want
24572441
* to use its own hash..
24582442
*/
24592443
if (base->d_flags & DCACHE_OP_HASH) {
2460-
int err = base->d_op->d_hash(base, &this);
2444+
int err = base->d_op->d_hash(base, this);
24612445
if (err < 0)
2462-
return ERR_PTR(err);
2446+
return err;
24632447
}
24642448

2465-
err = inode_permission(base->d_inode, MAY_EXEC);
2449+
return inode_permission(base->d_inode, MAY_EXEC);
2450+
}
2451+
2452+
/**
2453+
* lookup_one_len - filesystem helper to lookup single pathname component
2454+
* @name: pathname component to lookup
2455+
* @base: base directory to lookup from
2456+
* @len: maximum length @len should be interpreted to
2457+
*
2458+
* Note that this routine is purely a helper for filesystem usage and should
2459+
* not be called by generic code.
2460+
*
2461+
* The caller must hold base->i_mutex.
2462+
*/
2463+
struct dentry *lookup_one_len(const char *name, struct dentry *base, int len)
2464+
{
2465+
struct qstr this;
2466+
int err;
2467+
2468+
WARN_ON_ONCE(!inode_is_locked(base->d_inode));
2469+
2470+
err = lookup_one_len_common(name, base, len, &this);
24662471
if (err)
24672472
return ERR_PTR(err);
24682473

@@ -2486,37 +2491,10 @@ struct dentry *lookup_one_len_unlocked(const char *name,
24862491
struct dentry *base, int len)
24872492
{
24882493
struct qstr this;
2489-
unsigned int c;
24902494
int err;
24912495
struct dentry *ret;
24922496

2493-
this.name = name;
2494-
this.len = len;
2495-
this.hash = full_name_hash(base, name, len);
2496-
if (!len)
2497-
return ERR_PTR(-EACCES);
2498-
2499-
if (unlikely(name[0] == '.')) {
2500-
if (len < 2 || (len == 2 && name[1] == '.'))
2501-
return ERR_PTR(-EACCES);
2502-
}
2503-
2504-
while (len--) {
2505-
c = *(const unsigned char *)name++;
2506-
if (c == '/' || c == '\0')
2507-
return ERR_PTR(-EACCES);
2508-
}
2509-
/*
2510-
* See if the low-level filesystem might want
2511-
* to use its own hash..
2512-
*/
2513-
if (base->d_flags & DCACHE_OP_HASH) {
2514-
int err = base->d_op->d_hash(base, &this);
2515-
if (err < 0)
2516-
return ERR_PTR(err);
2517-
}
2518-
2519-
err = inode_permission(base->d_inode, MAY_EXEC);
2497+
err = lookup_one_len_common(name, base, len, &this);
25202498
if (err)
25212499
return ERR_PTR(err);
25222500

0 commit comments

Comments
 (0)