From: Dan Carpenter <dan.carpenter@oracle.com>
To: Antti Palosaari <crope@iki.fi>
Cc: "Michael Büsch" <m@bues.ch>,
"Federico Simoncelli" <fsimonce@redhat.com>,
"Mauro Carvalho Chehab" <mchehab@osg.samsung.com>,
"Linux Media Mailing List" <linux-media@vger.kernel.org>,
"Mauro Carvalho Chehab" <mchehab@infradead.org>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Hans Verkuil" <hverkuil@xs4all.nl>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
"Ondrej Zary" <linux@rainbow-software.org>,
"Ramakrishnan Muthukrishnan" <ramakrmu@cisco.com>,
"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
"Takashi Iwai" <tiwai@suse.de>,
"Amber Thrall" <amber.rose.thrall@gmail.com>,
"James Harper" <james.harper@ejbdigital.com.au>,
"Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com>
Subject: Re: [PATCH 2/2] drivers: Simplify the return code
Date: Tue, 19 May 2015 20:36:44 +0300 [thread overview]
Message-ID: <20150519173644.GP22558@mwanda> (raw)
In-Reply-To: <555B5E32.9060301@iki.fi>
On Tue, May 19, 2015 at 07:00:50PM +0300, Antti Palosaari wrote:
> I am also against that kind of simplifications. Even it reduces line
> or two, it makes code more inconsistent, which means you have to
> make extra thinking when reading that code. I prefer similar
> repeating patterns as much as possible.
>
> This is how I do it usually, even there is that extra last goto.
>
> ret = write_reg();
> if (ret)
> goto err;
>
> ret = write_reg();
> if (ret)
> goto err;
> err:
> return ret;
> };
>
I don't care too much about the original patch one way or the other.
The new code is more fashionable and fewer lines.
But these sorts of do-nothing returns are a blight.
They are misleading. You expect goto err to do something. You wander
what it is. The name tells you nothing. So you have to scroll down.
Oh crap, it's just a @#$@$@#$ waste of time do-nothing goto. It's the
travel through a door problem, you have completely forgotten what you
are doing.
http://www.scientificamerican.com/article/why-walking-through-doorway-makes-you-forget/
And also they are a total waste of time if you care about preventing
bugs.
Some people complain about "hidden return statements" but that is only
an issue if you don't have syntax highlighting. If you look through the
git logs it is full of places like 95f38411df055a0e ('netns: use a
spin_lock to protect nsid management') where the other coder had gotos
highlighted in the same color as regular code. If you actually measure
how common return with lock held bugs are the goto err and the direct
return style code have equal amount of bugs. (I have looked at this but
only briefly, so it would be interesting to see a thourough scientific
paper on it).
Also the goto err style code introduces a new class of "forgot to set
the error code" bugs which are not there in direct return code.
regards,
dan carpenter
next prev parent reply other threads:[~2015-05-19 17:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-19 11:00 [PATCH 1/2] usb drivers: use BUG_ON() instead of if () BUG Mauro Carvalho Chehab
2015-05-19 11:00 ` [PATCH 2/2] drivers: Simplify the return code Mauro Carvalho Chehab
2015-05-19 12:05 ` Federico Simoncelli
2015-05-19 12:17 ` Michael Büsch
2015-05-19 16:00 ` Antti Palosaari
2015-05-19 17:36 ` Dan Carpenter [this message]
2015-05-20 8:49 ` Mauro Carvalho Chehab
2015-05-20 8:39 ` Mauro Carvalho Chehab
2015-05-19 16:44 ` [PATCH 1/2] usb drivers: use BUG_ON() instead of if () BUG Lad, Prabhakar
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=20150519173644.GP22558@mwanda \
--to=dan.carpenter@oracle.com \
--cc=amber.rose.thrall@gmail.com \
--cc=crope@iki.fi \
--cc=fsimonce@redhat.com \
--cc=hverkuil@xs4all.nl \
--cc=james.harper@ejbdigital.com.au \
--cc=konrad.wilk@oracle.com \
--cc=lars@metafoo.de \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=linux@rainbow-software.org \
--cc=m@bues.ch \
--cc=mchehab@infradead.org \
--cc=mchehab@osg.samsung.com \
--cc=ramakrmu@cisco.com \
--cc=sakari.ailus@linux.intel.com \
--cc=tiwai@suse.de \
/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