All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes-kernel@saeurebad.de>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: "Björn Steinbrink" <B.Steinbrink@gmx.de>,
	"Andrew Morton" <akpm@linux-foundation.org>
Subject: Re: [PATCH] Replace obscure constructs in fs/block_dev.c
Date: Sun, 17 Jun 2007 17:42:26 +0200	[thread overview]
Message-ID: <20070617154226.GB9489@saeurebad.de> (raw)
In-Reply-To: <20070617093855.GA30197@atjola.homenet>

[-- Attachment #1: Type: text/plain, Size: 385 bytes --]

Hi,

please ignore the last revision of this patch. There were some places where
semantics where changed instead of just presentation.  Also the bd_claim()
'fixup' was reverted, due to a misunderstanding of the code.


This patch replaces some funky codepaths in fs/block_dev.c with cleaner
versions of the affected places.

Signed-off-by: Johannes Weiner <hannes-kernel@saeurebad.de>

[-- Attachment #2: block_dev-anti-obscurity-r2.patch --]
[-- Type: text/x-diff, Size: 1910 bytes --]

diff --git a/fs/block_dev.c b/fs/block_dev.c
index ea1480a..710de2f 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -874,7 +874,7 @@ static struct bd_holder *find_bd_holder(struct block_device *bdev,
  */
 static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo)
 {
-	int ret;
+	int err;
 
 	if (!bo)
 		return -EINVAL;
@@ -882,15 +882,18 @@ static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo)
 	if (!bd_holder_grab_dirs(bdev, bo))
 		return -EBUSY;
 
-	ret = add_symlink(bo->sdir, bo->sdev);
-	if (ret == 0) {
-		ret = add_symlink(bo->hdir, bo->hdev);
-		if (ret)
-			del_symlink(bo->sdir, bo->sdev);
+	err = add_symlink(bo->sdir, bo->sdev);
+	if (err)
+		return err;
+
+	err = add_symlink(bo->hdir, bo->hdev);
+	if (err) {
+		del_symlink(bo->sdir, bo->sdev);
+		return err;
 	}
-	if (ret == 0)
-		list_add_tail(&bo->list, &bdev->bd_holder_list);
-	return ret;
+
+	list_add_tail(&bo->list, &bdev->bd_holder_list);
+	return err;
 }
 
 /**
@@ -948,7 +951,7 @@ static struct bd_holder *del_bd_holder(struct block_device *bdev,
 static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
 				struct kobject *kobj)
 {
-	int res;
+	int err;
 	struct bd_holder *bo, *found;
 
 	if (!kobj)
@@ -959,21 +962,24 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
 		return -ENOMEM;
 
 	mutex_lock(&bdev->bd_mutex);
-	res = bd_claim(bdev, holder);
-	if (res == 0) {
-		found = find_bd_holder(bdev, bo);
-		if (found == NULL) {
-			res = add_bd_holder(bdev, bo);
-			if (res)
-				bd_release(bdev);
-		}
-	}
 
-	if (res || found)
+	err = bd_claim(bdev, holder);
+	if (err)
+		goto out;
+
+	found = find_bd_holder(bdev, bo);
+	if (found)
+		goto out;
+
+	err = add_bd_holder(bdev, bo);
+	if (err)
+		bd_release(bdev);
+
+out:
+	if (err || found)
 		free_bd_holder(bo);
 	mutex_unlock(&bdev->bd_mutex);
-
-	return res;
+	return err;
 }
 
 /**

      parent reply	other threads:[~2007-06-17 15:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-15 13:46 [PATCH] Replace obscure constructs in fs/block_dev.c Johannes Weiner
2007-06-17  9:38 ` Björn Steinbrink
2007-06-17 12:52   ` Johannes Weiner
2007-06-17 15:42   ` Johannes Weiner [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=20070617154226.GB9489@saeurebad.de \
    --to=hannes-kernel@saeurebad.de \
    --cc=B.Steinbrink@gmx.de \
    --cc=akpm@linux-foundation.org \
    --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.