lkml.org 
[lkml]   [2008]   [Dec]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] avoid unnecessary assignment in lookup_bdev()
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

\
 
 \ /
  Last update: 2008-12-14 19:29    [from the cache]
©2003-2011 Jasper Spaans. Advertise on this site