All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Becker <Joel.Becker@oracle.com>
To: Akinobu Mita <akinobu.mita@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] configfs: add missing mutex_unlock()
Date: Mon, 5 Mar 2007 13:42:56 -0800	[thread overview]
Message-ID: <20070305214256.GC20528@ca-server1.us.oracle.com> (raw)
In-Reply-To: <20070304151659.GA19972@APFDCB5C>

	First, thank you Akinobu for discovering the bug.

On Mon, Mar 05, 2007 at 12:16:59AM +0900, Akinobu Mita wrote:
> On Sun, Mar 04, 2007 at 03:10:19PM +0100, Arnd Bergmann wrote:
> > This should be changed to jump to a new exit point, before the mutex_unlock
> > at the end of the function. Having multiple places in the function that
> > release the same lock easily leads to the kind of bug you are fixing here.
> 
> Agreed. Please see the patch below (untested).

	Jumping isn't always the solution.  The new patch, while better
than the first, still calls mutex_unlock() in two places.  The following
patch keeps it all in one code path, and keeps all dentry modification
underneath a single mutex_lock()/unlock() pair.  What do you think?  I'm
building it to test as we speak.

Joel

diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index 1814ba4..489c265 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -1142,25 +1142,22 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
 
 	err = -ENOMEM;
 	dentry = d_alloc(configfs_sb->s_root, &name);
-	if (!dentry)
-		goto out_release;
-
-	d_add(dentry, NULL);
+	if (dentry) {
+		d_add(dentry, NULL);
 
-	err = configfs_attach_group(sd->s_element, &group->cg_item,
-				    dentry);
-	if (!err)
-		dentry = NULL;
-	else
-		d_delete(dentry);
+		err = configfs_attach_group(sd->s_element, &group->cg_item,
+					    dentry);
+		if (err) {
+			d_delete(dentry);
+			dput(dentry);
+		}
+	}
 
 	mutex_unlock(&configfs_sb->s_root->d_inode->i_mutex);
 
-	if (dentry) {
-	    dput(dentry);
-out_release:
-	    unlink_group(group);
-	    configfs_release_fs();
+	if (err) {
+		unlink_group(group);
+		configfs_release_fs();
 	}
 
 	return err;

-- 

"Nobody loves me,
 Nobody seems to care.
 Troubles and worries, people,
 You know I've had my share."

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker@oracle.com
Phone: (650) 506-8127

      reply	other threads:[~2007-03-05 21:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-04 13:38 [PATCH] configfs: add missing mutex_unlock() Akinobu Mita
2007-03-04 14:10 ` Arnd Bergmann
2007-03-04 15:16   ` Akinobu Mita
2007-03-05 21:42     ` Joel Becker [this message]

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=20070305214256.GC20528@ca-server1.us.oracle.com \
    --to=joel.becker@oracle.com \
    --cc=akinobu.mita@gmail.com \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.