mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Adam J. Richter" <adam@yggdrasil.com>
To: vandrove@vc.cvut.cz
Cc: akpm@digeo.com, alsa-devel@alsa-project.org, harinath@cs.umn.edu,
	linux-kernel@vger.kernel.org, perex@suse.cz
Subject: Re: Patch?: linux-2.5.59/sound/soundcore.c referenced non-existant errno variable
Date: Sat, 18 Jan 2003 20:14:39 -0800	[thread overview]
Message-ID: <200301190414.UAA10226@adam.yggdrasil.com> (raw)

>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;
			undo_step2();
		}
		undo_step1();
	}
	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
loop).

Adam J. Richter     __     ______________   575 Oroville Road
adam@yggdrasil.com     \ /                  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."

             reply	other threads:[~2003-01-19  4:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-19  4:14 Adam J. Richter [this message]
2003-01-20 15:27 ` Horst von Brand
2003-01-21 16:48   ` Bill Davidsen
2003-01-21 17:01     ` Horst von Brand
  -- strict thread matches above, loose matches on Subject: below --
2003-01-20 20:01 Adam J. Richter
2003-01-20 19:53 Adam J. Richter
2003-01-21  8:35 ` Horst von Brand
2003-01-17 23:57 Adam J. Richter
2003-01-18  2:49 ` Raja R Harinath
2003-01-18  3:13   ` Petr Vandrovec
2003-01-18 15:40     ` Raja R Harinath
2003-01-18 20:27       ` Petr Vandrovec
2003-01-18 20:40         ` Andrew Morton

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=200301190414.UAA10226@adam.yggdrasil.com \
    --to=adam@yggdrasil.com \
    --cc=akpm@digeo.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=harinath@cs.umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@suse.cz \
    --cc=vandrove@vc.cvut.cz \
    /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

all inboxes | Powered by JetHome®