public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Coly Li <coly.li@suse.de>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] avoid unnecessary assignment in lookup_bdev()
Date: Mon, 15 Dec 2008 02:33:20 +0800	[thread overview]
Message-ID: <49455170.6080307@suse.de> (raw)

In normal cases, lookup_bdev() should return successfully, therefore it's not a good idea to always
assign error values before checking truth/false conditions. This patch modifies code to only assign
error value in necessary false conditions.

If I missed something, please correct me.

Signed-off-by: Coly Li <coly.li@suse.de>
---
 fs/block_dev.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 99e0ae1..10b656f 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1282,16 +1282,19 @@ struct block_device *lookup_bdev(const char *pathname)
 		return ERR_PTR(error);

 	inode = path.dentry->d_inode;
-	error = -ENOTBLK;
-	if (!S_ISBLK(inode->i_mode))
+	if (!S_ISBLK(inode->i_mode)) {
+		error = -ENOTBLK;
 		goto fail;
-	error = -EACCES;
-	if (path.mnt->mnt_flags & MNT_NODEV)
+	}
+	if (path.mnt->mnt_flags & MNT_NODEV) {
+		error = -EACCES;
 		goto fail;
-	error = -ENOMEM;
+	}
 	bdev = bd_acquire(inode);
-	if (!bdev)
+	if (!bdev) {
+		error = -ENOMEM;
 		goto fail;
+	}
 out:
 	path_put(&path);
 	return bdev;
-- 
Coly Li
SuSE PRC Labs

             reply	other threads:[~2008-12-14 18:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-14 18:33 Coly Li [this message]
2008-12-14 19:12 ` [PATCH] avoid unnecessary assignment in lookup_bdev() Greg KH
2008-12-14 19:30   ` Coly Li

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=49455170.6080307@suse.de \
    --to=coly.li@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox