[lkml]   [2003]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Patch?: linux-2.5.59/sound/soundcore.c referenced non-existant errno variable
>In original message I asked whether I should convert firmware loader to 
>the "if (error) goto quit;" style to move error handling to one place,
>but only answer I got was 'Ask Rob' ;-)

To my knowledge, a goto in this case is not necessary for
avoiding code duplication. If there are a small number of failable
steps that may need to be unwound, you could adopt the style of my patch
(which shortened the code slightly):

if (step1() == ok) {
if (step2() == ok) {
if (strep3() == ok)
return OK;
return failure;

If the nesting gets any deeper than this, then a more
understandable solution for readability than using goto would be to
define a separate inline routine.

In general, I recommend using goto only when it is
topologically necessary to avoid code duplication or due to some
compiler quirk where you want to sqeeze a few more cycles out of code
in a critical path. That way, the use of goto basically flags these
unusual cases for other programmers.

Examples of cases where a goto really is needed to avoid code
duplication include a switch() or a group of if() branches need to
flow back together after starting out by doing different things, and
where you want to break from an outer loop and for some reason don't
want to write the outer loop as an inline routine (for example, you
also have a "return" statement for the existing subroutine in this

Adam J. Richter __ ______________ 575 Oroville Road \ / Milpitas, California 95035
+1 408 309-6081 | g g d r a s i l United States of America
"Free Software For The Rest Of Us."
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:32    [W:0.039 / U:0.488 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site