Commit 63b27720 authored by Al Viro's avatar Al Viro

path_parent_directory(): leave changing path->dentry to callers

Instead of returning 0, return new dentry; instead of returning
-ENOENT, return NULL.  Adjust the callers accordingly.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 6b03f7ed
...@@ -1440,19 +1440,21 @@ static void follow_mount(struct path *path) ...@@ -1440,19 +1440,21 @@ static void follow_mount(struct path *path)
} }
} }
static int path_parent_directory(struct path *path) static struct dentry *path_parent_directory(struct path *path)
{ {
struct dentry *old = path->dentry;
/* rare case of legitimate dget_parent()... */ /* rare case of legitimate dget_parent()... */
path->dentry = dget_parent(path->dentry); struct dentry *parent = dget_parent(path->dentry);
dput(old);
if (unlikely(!path_connected(path->mnt, path->dentry))) if (unlikely(!path_connected(path->mnt, parent))) {
return -ENOENT; dput(parent);
return 0; parent = NULL;
}
return parent;
} }
static int follow_dotdot(struct nameidata *nd) static int follow_dotdot(struct nameidata *nd)
{ {
struct dentry *parent;
while (1) { while (1) {
if (path_equal(&nd->path, &nd->root)) { if (path_equal(&nd->path, &nd->root)) {
if (unlikely(nd->flags & LOOKUP_BENEATH)) if (unlikely(nd->flags & LOOKUP_BENEATH))
...@@ -1460,9 +1462,11 @@ static int follow_dotdot(struct nameidata *nd) ...@@ -1460,9 +1462,11 @@ static int follow_dotdot(struct nameidata *nd)
break; break;
} }
if (nd->path.dentry != nd->path.mnt->mnt_root) { if (nd->path.dentry != nd->path.mnt->mnt_root) {
int ret = path_parent_directory(&nd->path); parent = path_parent_directory(&nd->path);
if (ret) if (!parent)
return ret; return -ENOENT;
dput(nd->path.dentry);
nd->path.dentry = parent;
break; break;
} }
if (!follow_up(&nd->path)) if (!follow_up(&nd->path))
...@@ -2600,13 +2604,13 @@ int path_pts(struct path *path) ...@@ -2600,13 +2604,13 @@ int path_pts(struct path *path)
*/ */
struct dentry *child, *parent; struct dentry *child, *parent;
struct qstr this; struct qstr this;
int ret;
ret = path_parent_directory(path); parent = path_parent_directory(path);
if (ret) if (!parent)
return ret; return -ENOENT;
parent = path->dentry; dput(path->dentry);
path->dentry = parent;
this.name = "pts"; this.name = "pts";
this.len = 3; this.len = 3;
child = d_hash_and_lookup(parent, &this); child = d_hash_and_lookup(parent, &this);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment