Re: [PATCH] Replaces two GOTO statements with one IF_ELSE statement in /fs/open.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Christoph Lameter <[email protected]> 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);
 
_

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux