public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Christoph Lameter <christoph@lameter.com>
Cc: jgarzik@pobox.com, telendiz@eircom.net, torvalds@osdl.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Replaces two GOTO statements with one IF_ELSE statement in /fs/open.c
Date: Mon, 20 Jun 2005 13:38:00 -0700	[thread overview]
Message-ID: <20050620133800.0dac1d97.akpm@osdl.org> (raw)
In-Reply-To: <Pine.LNX.4.62.0506201154300.2245@graphe.net>

Christoph Lameter <christoph@lameter.com> wrote:
>
> On Mon, 20 Jun 2005, Jeff Garzik wrote:
> 
> > If you don't like goto, don't read kernel code!
> 
> But his patch also cleans up a code quit a bit.

Yes, it is cleaner that way.

The old trick to make the error-handling code out-of-line shouldn't be
needed nowadays - IS_ERR uses unlikely(), which is supposed to handle that
stuff.

We can go a bit further and remove local variable `error'.

Code size is the same before and after, and the assembly very similar.

diff -puN fs/open.c~sys_open-cleanup fs/open.c
--- 25/fs/open.c~sys_open-cleanup	Mon Jun 20 13:31:54 2005
+++ 25-akpm/fs/open.c	Mon Jun 20 13:33:37 2005
@@ -934,7 +934,7 @@ EXPORT_SYMBOL(fd_install);
 asmlinkage long sys_open(const char __user * filename, int flags, int mode)
 {
 	char * tmp;
-	int fd, error;
+	int fd;
 
 	if (force_o_largefile())
 		flags |= O_LARGEFILE;
@@ -945,20 +945,16 @@ asmlinkage long sys_open(const char __us
 		fd = get_unused_fd();
 		if (fd >= 0) {
 			struct file *f = filp_open(tmp, flags, mode);
-			error = PTR_ERR(f);
-			if (IS_ERR(f))
-				goto out_error;
-			fd_install(fd, f);
+			if (IS_ERR(f)) {
+				put_unused_fd(fd);
+				fd = PTR_ERR(f);
+			} else {
+				fd_install(fd, f);
+			}
 		}
-out:
 		putname(tmp);
 	}
 	return fd;
-
-out_error:
-	put_unused_fd(fd);
-	fd = error;
-	goto out;
 }
 EXPORT_SYMBOL_GPL(sys_open);
 
_


  parent reply	other threads:[~2005-06-20 21:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-20 18:18 [PATCH] Replaces two GOTO statements with one IF_ELSE statement in /fs/open.c Telemaque Ndizihiwe
2005-06-20 18:43 ` Jeff Garzik
2005-06-20 18:54   ` Christoph Lameter
2005-06-20 19:51     ` Joel Schopp
2005-06-20 20:38     ` Andrew Morton [this message]
2005-06-21  8:57       ` Martin Waitz
2005-06-21 16:05         ` Linus Torvalds
2005-06-20 19:07 ` Richard B. Johnson
2005-06-20 20:34   ` Mitchell Blank Jr
2005-06-20 22:06 ` Bill Davidsen
     [not found] <Pine.LNX.4.62.0506201834460.5008@localhost.localdomain.suse.lists.linux.kernel>
     [not found] ` <42B70E62.5070704@pobox.com.suse.lists.linux.kernel>
     [not found]   ` <Pine.LNX.4.62.0506201154300.2245@graphe.net.suse.lists.linux.kernel>
     [not found]     ` <20050620133800.0dac1d97.akpm@osdl.org.suse.lists.linux.kernel>
2005-06-21 11:27       ` Andi Kleen

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=20050620133800.0dac1d97.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=christoph@lameter.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=telendiz@eircom.net \
    --cc=torvalds@osdl.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