From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
To: Antti Palosaari <crope@iki.fi>
Cc: "Michael Büsch" <m@bues.ch>,
"Federico Simoncelli" <fsimonce@redhat.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>,
"Dan Carpenter" <dan.carpenter@oracle.com>,
"Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com>
Subject: Re: [PATCH 2/2] drivers: Simplify the return code
Date: Wed, 20 May 2015 05:49:28 -0300 [thread overview]
Message-ID: <20150520054928.3eb9f431@recife.lan> (raw)
In-Reply-To: <555B5E32.9060301@iki.fi>
Em Tue, 19 May 2015 19:00:50 +0300
Antti Palosaari <crope@iki.fi> escreveu:
> On 05/19/2015 03:17 PM, Michael Büsch wrote:
> > On Tue, 19 May 2015 08:05:56 -0400 (EDT)
> > Federico Simoncelli <fsimonce@redhat.com> wrote:
> >>> diff --git a/drivers/media/dvb-frontends/lgs8gxx.c
> >>> b/drivers/media/dvb-frontends/lgs8gxx.c
> >>> index 3c92f36ea5c7..9b0166cdc7c2 100644
> >>> --- a/drivers/media/dvb-frontends/lgs8gxx.c
> >>> +++ b/drivers/media/dvb-frontends/lgs8gxx.c
> >>> @@ -544,11 +544,7 @@ static int lgs8gxx_set_mpeg_mode(struct lgs8gxx_state
> >>> *priv,
> >>> t |= clk_pol ? TS_CLK_INVERTED : TS_CLK_NORMAL;
> >>> t |= clk_gated ? TS_CLK_GATED : TS_CLK_FREERUN;
> >>>
> >>> - ret = lgs8gxx_write_reg(priv, reg_addr, t);
> >>> - if (ret != 0)
> >>> - return ret;
> >>> -
> >>> - return 0;
> >>> + return lgs8gxx_write_reg(priv, reg_addr, t);
> >>> }
> >>
> >> Personally I prefer the current style because it's more consistent with all
> >> the other calls in the same function (return ret when ret != 0).
> >>
> >> It also allows you to easily add/remove calls without having to deal with
> >> the last special case return my_last_fun_call(...).
> >>
> >> Anyway it's not a big deal, I think it's your call.
> >
> >
> > I agree. I also prefer the current style for these reasons. The compiler will also generate the same code in both cases.
> > I don't think it really simplifies the code.
> > But if you really insist on doing this change, go for it. You get my ack for fc0011
>
>
> 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.
Actually, it simplifies the thinking: less lines to read and the function
return code is clearly defined.
> 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;
> };
Nah, the above sucks: it is just hiding the return if error. Having to
go until the end of a function to see what "err" would do is not good.
Ok, if you have to deallocate things, do mutex unlock, etc, it is
justifiable.
However, in this case, it is quite a deception to discover that,
after going all the way down the code, "err" is just
do-nothing-but-return.
The above code is exactly why several academic professors forbid the
usage of goto: the code can easily become hard to read if you use lots
of goto, instead of using structured loops and returns.
Regards,
Mauro
next prev parent reply other threads:[~2015-05-20 8:49 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
2015-05-20 8:49 ` Mauro Carvalho Chehab [this message]
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=20150520054928.3eb9f431@recife.lan \
--to=mchehab@osg.samsung.com \
--cc=amber.rose.thrall@gmail.com \
--cc=crope@iki.fi \
--cc=dan.carpenter@oracle.com \
--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=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