public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruen@suse.de>
To: jblunck@suse.de
Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
	hch@lst.de, tiwai@suse.de
Subject: [patch] Combine path_put and path_put_conditional
Date: Fri, 28 Sep 2007 22:43:50 +0200	[thread overview]
Message-ID: <200709282243.51243.agruen@suse.de> (raw)
In-Reply-To: <20070927141200.820970144@X40.localnet>

Here is another cleanup on top of Jan's set. Comments?


The name path_put_conditional (formerly, dput_path) is a little unclear.
Replace (path_put_conditional + path_put) with path_walk_put_both,
"put a pair of paths after a path_walk" (see the kerneldoc).

Signed-off-by: Andreas Gruenbacher <agruen@suse.de>

Index: linux-2.6/fs/namei.c
===================================================================
--- linux-2.6.orig/fs/namei.c
+++ linux-2.6/fs/namei.c
@@ -582,11 +582,22 @@ fail:
 	return PTR_ERR(link);
 }
 
-static void path_put_conditional(struct path *path, struct nameidata *nd)
-{
-	dput(path->dentry);
-	if (path->mnt != nd->path.mnt)
-		mntput(path->mnt);
+/**
+ * path_walk_put_both - put a pair of paths after a path_walk
+ * @path1:	first path to put
+ * @path2:	second path to put
+ *
+ * When walking a path we keep the same vfsmnt reference while on the same
+ * filesystem, and grab a reference to the new vfsmnt when crossing mount
+ * points. Put both @path1 and @path2 under this assumption.
+ */
+static void path_walk_put_both(struct path *path1, struct path *path2)
+{
+	dput(path1->dentry);
+	dput(path2->dentry);
+	mntput(path1->mnt);
+	if (path1->mnt != path2->mnt)
+		mntput(path2->mnt);
 }
 
 static inline void path_to_nameidata(struct path *path, struct nameidata *nd)
@@ -654,8 +665,7 @@ static inline int do_follow_link(struct 
 	nd->depth--;
 	return err;
 loop:
-	path_put_conditional(path, nd);
-	path_put(&nd->path);
+	path_walk_put_both(path, &nd->path);
 	return err;
 }
 
@@ -996,8 +1006,8 @@ return_reval:
 return_base:
 		return 0;
 out_dput:
-		path_put_conditional(&next, nd);
-		break;
+		path_walk_put_both(&next, &nd->path);
+		goto return_err;
 	}
 	path_put(&nd->path);
 return_err:
@@ -1777,11 +1787,15 @@ ok:
 	return 0;
 
 exit_dput:
-	path_put_conditional(&path, nd);
+	path_walk_put_both(&path, &nd->path);
+	goto exit_intent;
+
 exit:
+	path_put(&nd->path);
+
+exit_intent:
 	if (!IS_ERR(nd->intent.open.file))
 		release_open_intent(nd);
-	path_put(&nd->path);
 	return error;
 
 do_link:

  parent reply	other threads:[~2007-09-28 20:43 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-27 14:12 [patch 00/10] Use struct path in struct nameidata jblunck
2007-09-27 14:12 ` [patch 01/10] Dont touch fs_struct in drivers jblunck
2007-09-28 18:33   ` Christoph Hellwig
2007-09-27 14:12 ` [patch 02/10] Dont touch fs_struct in usermodehelper jblunck
2007-09-27 17:46   ` Greg KH
2007-09-27 20:39     ` Christoph Hellwig
2007-09-27 21:36       ` Greg KH
2007-09-28 18:33   ` Christoph Hellwig
2007-09-27 14:12 ` [patch 03/10] Remove path_release_on_umount() jblunck
2007-09-28 18:34   ` Christoph Hellwig
2007-09-27 14:12 ` [patch 04/10] Move struct path into its own header jblunck
2007-09-28 18:35   ` Christoph Hellwig
2007-09-27 14:12 ` [patch 05/10] Embed a struct path into struct nameidata instead of nd->{dentry,mnt} jblunck
2007-09-28 18:36   ` Christoph Hellwig
2007-09-27 14:12 ` [patch 06/10] Introduce path_put() jblunck
2007-09-28 18:37   ` Christoph Hellwig
2007-09-27 14:12 ` [patch 07/10] Use path_put() in a few places instead of {mnt,d}put() jblunck
2007-09-28 18:37   ` Christoph Hellwig
2007-09-27 14:12 ` [patch 08/10] Introduce path_get() jblunck
2007-09-28 18:40   ` Christoph Hellwig
2007-09-27 14:12 ` [patch 09/10] Use struct path in fs_struct jblunck
2007-09-28 18:42   ` Christoph Hellwig
2007-09-28 20:39     ` Andreas Gruenbacher
2007-09-29  9:24       ` Christoph Hellwig
2007-09-29  9:31         ` Christoph Hellwig
2007-09-27 14:12 ` [patch 10/10] Make set_fs_{root,pwd} take a struct path jblunck
2007-09-28 18:42   ` Christoph Hellwig
2007-09-28 20:43 ` Andreas Gruenbacher [this message]
2007-09-29  9:25   ` [patch] Combine path_put and path_put_conditional Christoph Hellwig
2007-09-29 12:36   ` Jan Blunck
2007-09-29 22:21   ` Ingo Oeser
2007-10-09  9:16 ` [patch 00/10] Use struct path in struct nameidata Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200709282243.51243.agruen@suse.de \
    --to=agruen@suse.de \
    --cc=hch@lst.de \
    --cc=jblunck@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tiwai@suse.de \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox