Re: oom() _still_ killing init

Oliver Xymoron (oxymoron@waste.org)
Thu, 17 Jun 1999 17:18:31 -0500 (CDT)


On Thu, 17 Jun 1999, Matthew Wilcox wrote:

> On Thu, Jun 17, 1999 at 10:05:52AM -0500, Oliver Xymoron wrote:
> > You're kidding. Tell me you're joking, please. This is the most
> > superfluous use of a goto I've ever seen. There are good reasons not to
> > use gotos, such as readability, maintainability, reliability, and the
> > like. While performance may take precedence in schedule (at least until we
> > make the compiler smarter), the same is certainly not true here.
>
> On the other hand, there are good reasons to use gotos, such as
> readability, maintainability and the like (reliability? My code is
> less reliable if I use a goto? huh?). While I agree that those don't
> really apply to a 5 line function, this is a common idiom within the
> linux kernel for very good reasons.
>
> Try tidying up some of the functions in the vfs to not use goto and watch
> your indentation disappear off the end of your screen, your neighbour's
> screen and out of the window. I tried this once and came out a changed
> man, convinced of the usefulness of goto.
>
> Yes, of course you can make a mess with goto. Don't do that.

The appropriate uses of goto are rare enough that it's good practice to
avoid it where reasonable.. My claim about reliability is that it's
correlated with readability and maintainability.

And I don't believe removing gotos from VFS is as hard as you say. Almost
all of the code is of the form

foo(<vars>)
{
....
if(something_bad)
goto fail;
....
fail:
/* do cleanup */
}

...with lots of failure modes. These can be trivially transformed to:

foo(<vars>)
{
int cleanup_var;

if(!bar(<vars>,&cleanup_var))
/* do cleanup */
}

int bar(...)
{
int local_vars_we_don't_need_to_clean_up;
...
if(something_bad)
return 0;
...

return 1; /* success */
}

Throw inline in front of foo_attempt() and you do away with the call
overhead. I'm not presenting this as an ideal approach, just an existence
proof that eliminating gotos is not necessarily hard, nor need it result
in ridiculous nesting. It may in fact result in smaller and simpler
functions.

--
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.." 

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/