public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] avoid unnecessary assignment in lookup_bdev()
@ 2008-12-14 18:33 Coly Li
  2008-12-14 19:12 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Coly Li @ 2008-12-14 18:33 UTC (permalink / raw)
  To: linux-kernel

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] avoid unnecessary assignment in lookup_bdev()
  2008-12-14 18:33 [PATCH] avoid unnecessary assignment in lookup_bdev() Coly Li
@ 2008-12-14 19:12 ` Greg KH
  2008-12-14 19:30   ` Coly Li
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2008-12-14 19:12 UTC (permalink / raw)
  To: Coly Li; +Cc: linux-kernel

On Mon, Dec 15, 2008 at 02:33:20AM +0800, Coly Li wrote:
> 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.

I don't understand, is there some way that the current code could
incorrectly return an error value?

Is your change somehow faster?  I don't think this is on any fast-path
code, right?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] avoid unnecessary assignment in lookup_bdev()
  2008-12-14 19:12 ` Greg KH
@ 2008-12-14 19:30   ` Coly Li
  0 siblings, 0 replies; 3+ messages in thread
From: Coly Li @ 2008-12-14 19:30 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel



Greg KH Wrote:
> On Mon, Dec 15, 2008 at 02:33:20AM +0800, Coly Li wrote:
>> 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.
> 
> I don't understand, is there some way that the current code could
> incorrectly return an error value?
> 
> Is your change somehow faster?  I don't think this is on any fast-path
> code, right?
For 1 or 2 lines to set error value before checking condition, that's a clean coding style. But for
more places in one function to set error value this way, I can't say that's perfect.

lookup_bdev() is just in my code review stack, the way to set error value just makes me
uncomfortable. Maybe it is because my threshold (>=3) is lower than others. This patch can not bring
up any *real* faster, but sending it out makes me feel better at least :)

-- 
Coly Li
SuSE PRC Labs

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-12-14 19:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-14 18:33 [PATCH] avoid unnecessary assignment in lookup_bdev() Coly Li
2008-12-14 19:12 ` Greg KH
2008-12-14 19:30   ` Coly Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox