linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHES] more d_splice_alias() in ->lookup() instances
@ 2018-08-03 16:51 Al Viro
  2018-08-03 16:51 ` [PATCH 1/5] hostfs_lookup: switch to d_splice_alias() Al Viro
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Al Viro @ 2018-08-03 16:51 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

In the spirit of "thou shalt not push into your tree without
at least posting for review"...

* hostfs conversion of ->lookup() to use of d_splice_alias()
* afs conversions of ->lookup() to use of d_splice_alias()
* hpfs conversion of ->lookup() to use of d_splice_alias(),
leak fix on failure exit.

Stuff is in vfs.git#work.lookup, to go into #for-next if nobody
yells.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] hostfs_lookup: switch to d_splice_alias()
  2018-08-03 16:51 [PATCHES] more d_splice_alias() in ->lookup() instances Al Viro
@ 2018-08-03 16:51 ` Al Viro
  2018-08-03 16:51 ` [PATCH 2/5] afs: switch dynroot lookups " Al Viro
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2018-08-03 16:51 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/hostfs/hostfs_kern.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 2597b290c2a5..444c7b170359 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -610,33 +610,21 @@ static struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry,
 	int err;
 
 	inode = hostfs_iget(ino->i_sb);
-	if (IS_ERR(inode)) {
-		err = PTR_ERR(inode);
+	if (IS_ERR(inode))
 		goto out;
-	}
 
 	err = -ENOMEM;
 	name = dentry_name(dentry);
-	if (name == NULL)
-		goto out_put;
-
-	err = read_name(inode, name);
-
-	__putname(name);
-	if (err == -ENOENT) {
+	if (name) {
+		err = read_name(inode, name);
+		__putname(name);
+	}
+	if (err) {
 		iput(inode);
-		inode = NULL;
+		inode = (err == -ENOENT) ? NULL : ERR_PTR(err);
 	}
-	else if (err)
-		goto out_put;
-
-	d_add(dentry, inode);
-	return NULL;
-
- out_put:
-	iput(inode);
  out:
-	return ERR_PTR(err);
+	return d_splice_alias(inode, dentry);
 }
 
 static int hostfs_link(struct dentry *to, struct inode *ino,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] afs: switch dynroot lookups to d_splice_alias()
  2018-08-03 16:51 [PATCHES] more d_splice_alias() in ->lookup() instances Al Viro
  2018-08-03 16:51 ` [PATCH 1/5] hostfs_lookup: switch to d_splice_alias() Al Viro
@ 2018-08-03 16:51 ` Al Viro
  2018-08-03 16:51 ` [PATCH 3/5] afs_lookup(): switch " Al Viro
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2018-08-03 16:51 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/afs/dynroot.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/fs/afs/dynroot.c b/fs/afs/dynroot.c
index 174e843f0633..40fea59067b3 100644
--- a/fs/afs/dynroot.c
+++ b/fs/afs/dynroot.c
@@ -143,7 +143,6 @@ static struct dentry *afs_dynroot_lookup(struct inode *dir, struct dentry *dentr
 {
 	struct afs_vnode *vnode;
 	struct inode *inode;
-	int ret;
 
 	vnode = AFS_FS_I(dir);
 
@@ -161,21 +160,10 @@ static struct dentry *afs_dynroot_lookup(struct inode *dir, struct dentry *dentr
 		return afs_lookup_atcell(dentry);
 
 	inode = afs_try_auto_mntpt(dentry, dir);
-	if (IS_ERR(inode)) {
-		ret = PTR_ERR(inode);
-		if (ret == -ENOENT) {
-			d_add(dentry, NULL);
-			_leave(" = NULL [negative]");
-			return NULL;
-		}
-		_leave(" = %d [do]", ret);
-		return ERR_PTR(ret);
-	}
+	if (inode == ERR_PTR(-ENOENT))
+		inode = NULL;
 
-	d_add(dentry, inode);
-	_leave(" = 0 { ino=%lu v=%u }",
-	       d_inode(dentry)->i_ino, d_inode(dentry)->i_generation);
-	return NULL;
+	return d_splice_alias(inode, dentry);
 }
 
 const struct inode_operations afs_dynroot_inode_operations = {
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] afs_lookup(): switch to d_splice_alias()
  2018-08-03 16:51 [PATCHES] more d_splice_alias() in ->lookup() instances Al Viro
  2018-08-03 16:51 ` [PATCH 1/5] hostfs_lookup: switch to d_splice_alias() Al Viro
  2018-08-03 16:51 ` [PATCH 2/5] afs: switch dynroot lookups " Al Viro
@ 2018-08-03 16:51 ` Al Viro
  2018-08-03 16:51 ` [PATCH 4/5] afs_try_auto_mntpt(): return NULL instead of ERR_PTR(-ENOENT) Al Viro
  2018-08-03 16:51 ` [PATCH 5/5] hpfs: fix an inode leak in lookup, switch to d_splice_alias() Al Viro
  4 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2018-08-03 16:51 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/afs/dir.c | 47 ++++++++++++-----------------------------------
 1 file changed, 12 insertions(+), 35 deletions(-)

diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 7d623008157f..3099349cedfa 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -822,6 +822,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
 {
 	struct afs_vnode *dvnode = AFS_FS_I(dir);
 	struct inode *inode;
+	struct dentry *d;
 	struct key *key;
 	int ret;
 
@@ -862,43 +863,19 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
 
 	afs_stat_v(dvnode, n_lookup);
 	inode = afs_do_lookup(dir, dentry, key);
-	if (IS_ERR(inode)) {
-		ret = PTR_ERR(inode);
-		if (ret == -ENOENT) {
-			inode = afs_try_auto_mntpt(dentry, dir);
-			if (!IS_ERR(inode)) {
-				key_put(key);
-				goto success;
-			}
-
-			ret = PTR_ERR(inode);
-		}
-
-		key_put(key);
-		if (ret == -ENOENT) {
-			d_add(dentry, NULL);
-			_leave(" = NULL [negative]");
-			return NULL;
-		}
-		_leave(" = %d [do]", ret);
-		return ERR_PTR(ret);
+	if (inode == ERR_PTR(-ENOENT)) {
+		inode = afs_try_auto_mntpt(dentry, dir);
+		if (inode == ERR_PTR(-ENOENT))
+			inode = NULL;
+	} else {
+		dentry->d_fsdata =
+			(void *)(unsigned long)dvnode->status.data_version;
 	}
-	dentry->d_fsdata = (void *)(unsigned long)dvnode->status.data_version;
-
-	/* instantiate the dentry */
 	key_put(key);
-	if (IS_ERR(inode)) {
-		_leave(" = %ld", PTR_ERR(inode));
-		return ERR_CAST(inode);
-	}
-
-success:
-	d_add(dentry, inode);
-	_leave(" = 0 { ino=%lu v=%u }",
-	       d_inode(dentry)->i_ino,
-	       d_inode(dentry)->i_generation);
-
-	return NULL;
+	d = d_splice_alias(inode, dentry);
+	if (!IS_ERR_OR_NULL(d))
+		d->d_fsdata = dentry->d_fsdata;
+	return d;
 }
 
 /*
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] afs_try_auto_mntpt(): return NULL instead of ERR_PTR(-ENOENT)
  2018-08-03 16:51 [PATCHES] more d_splice_alias() in ->lookup() instances Al Viro
                   ` (2 preceding siblings ...)
  2018-08-03 16:51 ` [PATCH 3/5] afs_lookup(): switch " Al Viro
@ 2018-08-03 16:51 ` Al Viro
  2018-08-03 16:51 ` [PATCH 5/5] hpfs: fix an inode leak in lookup, switch to d_splice_alias() Al Viro
  4 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2018-08-03 16:51 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

simpler logics in callers that way

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/afs/dir.c     | 2 --
 fs/afs/dynroot.c | 5 +----
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 3099349cedfa..ff6738787fcd 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -865,8 +865,6 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
 	inode = afs_do_lookup(dir, dentry, key);
 	if (inode == ERR_PTR(-ENOENT)) {
 		inode = afs_try_auto_mntpt(dentry, dir);
-		if (inode == ERR_PTR(-ENOENT))
-			inode = NULL;
 	} else {
 		dentry->d_fsdata =
 			(void *)(unsigned long)dvnode->status.data_version;
diff --git a/fs/afs/dynroot.c b/fs/afs/dynroot.c
index 40fea59067b3..1e27a0171357 100644
--- a/fs/afs/dynroot.c
+++ b/fs/afs/dynroot.c
@@ -83,7 +83,7 @@ struct inode *afs_try_auto_mntpt(struct dentry *dentry, struct inode *dir)
 
 out:
 	_leave("= %d", ret);
-	return ERR_PTR(ret);
+	return ret == -ENOENT ? NULL : ERR_PTR(ret);
 }
 
 /*
@@ -160,9 +160,6 @@ static struct dentry *afs_dynroot_lookup(struct inode *dir, struct dentry *dentr
 		return afs_lookup_atcell(dentry);
 
 	inode = afs_try_auto_mntpt(dentry, dir);
-	if (inode == ERR_PTR(-ENOENT))
-		inode = NULL;
-
 	return d_splice_alias(inode, dentry);
 }
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] hpfs: fix an inode leak in lookup, switch to d_splice_alias()
  2018-08-03 16:51 [PATCHES] more d_splice_alias() in ->lookup() instances Al Viro
                   ` (3 preceding siblings ...)
  2018-08-03 16:51 ` [PATCH 4/5] afs_try_auto_mntpt(): return NULL instead of ERR_PTR(-ENOENT) Al Viro
@ 2018-08-03 16:51 ` Al Viro
  4 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2018-08-03 16:51 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel

From: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/hpfs/dir.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/fs/hpfs/dir.c b/fs/hpfs/dir.c
index c83ece7facc5..d85230c84ef2 100644
--- a/fs/hpfs/dir.c
+++ b/fs/hpfs/dir.c
@@ -244,6 +244,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, unsigned in
 	result = iget_locked(dir->i_sb, ino);
 	if (!result) {
 		hpfs_error(dir->i_sb, "hpfs_lookup: can't get inode");
+		result = ERR_PTR(-ENOMEM);
 		goto bail1;
 	}
 	if (result->i_state & I_NEW) {
@@ -266,6 +267,8 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, unsigned in
 
 	if (de->has_acl || de->has_xtd_perm) if (!sb_rdonly(dir->i_sb)) {
 		hpfs_error(result->i_sb, "ACLs or XPERM found. This is probably HPFS386. This driver doesn't support it now. Send me some info on these structures");
+		iput(result);
+		result = ERR_PTR(-EINVAL);
 		goto bail1;
 	}
 
@@ -301,29 +304,17 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, unsigned in
 		}
 	}
 
+bail1:
 	hpfs_brelse4(&qbh);
 
 	/*
 	 * Made it.
 	 */
 
-	end:
-	end_add:
+end:
+end_add:
 	hpfs_unlock(dir->i_sb);
-	d_add(dentry, result);
-	return NULL;
-
-	/*
-	 * Didn't.
-	 */
-	bail1:
-	
-	hpfs_brelse4(&qbh);
-	
-	/*bail:*/
-
-	hpfs_unlock(dir->i_sb);
-	return ERR_PTR(-ENOENT);
+	return d_splice_alias(result, dentry);
 }
 
 const struct file_operations hpfs_dir_ops =
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-08-03 18:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-03 16:51 [PATCHES] more d_splice_alias() in ->lookup() instances Al Viro
2018-08-03 16:51 ` [PATCH 1/5] hostfs_lookup: switch to d_splice_alias() Al Viro
2018-08-03 16:51 ` [PATCH 2/5] afs: switch dynroot lookups " Al Viro
2018-08-03 16:51 ` [PATCH 3/5] afs_lookup(): switch " Al Viro
2018-08-03 16:51 ` [PATCH 4/5] afs_try_auto_mntpt(): return NULL instead of ERR_PTR(-ENOENT) Al Viro
2018-08-03 16:51 ` [PATCH 5/5] hpfs: fix an inode leak in lookup, switch to d_splice_alias() Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).