mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesper Juhl <juhl-lkml@dif.dk>
To: Jan Engelhardt <jengelh@linux01.gwdg.de>
Cc: Chris Friesen <cfriesen@nortelnetworks.com>,
	Oliver Neukum <oliver@neukum.org>,
	Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: question on common error-handling idiom
Date: Tue, 2 Nov 2004 22:48:39 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.61.0411022241160.3285@dragon.hygekrogen.localhost> (raw)
In-Reply-To: <Pine.LNX.4.53.0411022229070.6104@yvahk01.tjqt.qr>

On Tue, 2 Nov 2004, Jan Engelhardt wrote:

> >There are some places that do
> >
> >err = -SOMEERROR;
> >if (some_error)
> >	goto out;
> >if (some_other_error)
> >	goto out;
> >if (another_error)
> >	goto out;
> >
> >Let's see what other people think :)
> 
> err = -ESOME;
> if(some_error || some_other_error || another_error) {
> 	goto out;
> }
> 
> Best.
> 
Agreed, but that would potentially make something like the following (from 
fs/binfmt_elf.c::load_elf_binary) quite unreadable :

if (loc->elf_ex.e_type != ET_EXEC && loc->elf_ex.e_type != ET_DYN)
	goto out;
if (!elf_check_arch(&loc->elf_ex))
	goto out;
if (!bprm->file->f_op||!bprm->file->f_op->mmap)
	goto out;


But that's not even the most interresting case, the interresting one is 
the one that does

err = -ERR;
if (foo)
	goto out;

err = -ERROR;
if (bar)
	goto out;

where there's the potential to save an instruction by moving the err= into 
the error path.
But as Oliver Neukum pointed out gcc may not be smart enough for that to 
actually generate the best code.

Has anyone taken a look at what recent gcc's actually do with different 
variations of the constructs mentioned in this thread?


--
Jesper Juhl



  reply	other threads:[~2004-11-03  0:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-02 20:08 Chris Friesen
2004-11-02 20:58 ` Jan Engelhardt
2004-11-02 21:12   ` linux-os
2004-11-03 10:45     ` Ross Kendall Axe
2004-11-02 21:12   ` Russell Miller
2004-11-02 21:16 ` Jesper Juhl
2004-11-02 21:21   ` Oliver Neukum
2004-11-02 21:29   ` Jan Engelhardt
2004-11-02 21:48     ` Jesper Juhl [this message]
2004-11-03 16:49       ` Chris Friesen
2004-11-03  8:11 ` GNicz
2004-11-04 19:52 ` Linus Torvalds

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=Pine.LNX.4.61.0411022241160.3285@dragon.hygekrogen.localhost \
    --to=juhl-lkml@dif.dk \
    --cc=cfriesen@nortelnetworks.com \
    --cc=jengelh@linux01.gwdg.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oliver@neukum.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

all inboxes | Powered by JetHome®