From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: Re: [patch] perf/x86/intel/pt: cleanup error handling in pt_pmu_hw_init()
Date: Sat, 11 Apr 2015 11:03:05 +0000 [thread overview]
Message-ID: <20150411110305.GR10964@mwanda> (raw)
In-Reply-To: <20150409090805.GG17605@mwanda>
I used to use out: and err: labels but for the past few years my job has
been to look at error handling every day. I now believe very strongly
that do-nothing gotos are harmful. It's going to be my contribution to
computer engineering to persuade people to hate exit labels.
https://plus.google.com/106378716002406849458/posts/dnanfhQ4mHQ
1) "goto err;" is annoying to read because the name is meaningless.
2) Exit labels bad associations because code which uses err: or out:
labels is often buggy as we have seen in pt_event_add().
3) They don't do anything for return in the middle bugs. They only
discourage people from returning at the start of the function where
direct returns are fine.
In theory, one place where they might be useful is if we added
locking to a function later on. First of all, when we add locking no
one ever changes the out: label to out_unlock:. It never happens.
Also missing unlocks on error paths is sort of a sloppy/newbie
mistake. I have looked through the git log and newbies are just as
likely to get locking wrong when there is an exit label as when there
is not.
https://plus.google.com/106378716002406849458/posts/DfuAkt8szf2
4) Exit labels introduce a whole new class of "forgot to set the error
code" bugs which don't happen with direct returns.
regards,
dan carpenter
next prev parent reply other threads:[~2015-04-11 11:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-09 9:08 [patch] perf/x86/intel/pt: cleanup error handling in pt_pmu_hw_init() Dan Carpenter
2015-04-09 12:02 ` Ingo Molnar
2015-04-09 12:33 ` Dan Carpenter
2015-04-09 12:45 ` Peter Zijlstra
2015-04-09 12:47 ` Alexander Shishkin
2015-04-09 13:30 ` Dan Carpenter
2015-04-09 14:54 ` Ingo Molnar
2015-04-09 15:27 ` Dan Carpenter
2015-04-11 8:37 ` Ingo Molnar
2015-04-11 11:03 ` Dan Carpenter [this message]
2015-04-12 9:38 ` Ingo Molnar
2015-04-12 9:51 ` Julia Lawall
2015-04-12 10:18 ` Ingo Molnar
2015-04-15 10:10 ` Alexander Shishkin
2015-04-15 10:27 ` Dan Carpenter
2015-04-15 10:50 ` Alexander Shishkin
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=20150411110305.GR10964@mwanda \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).