linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Ardelean <ardeleanalex@gmail.com>
To: Melissa Wen <melissa.srw@gmail.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Stefan Popa <stefan.popa@analog.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Barry Song <21cnbao@gmail.com>,
	linux-iio@vger.kernel.org, devel@driverdev.osuosl.org,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-usp@googlegroups.com
Subject: Re: [PATCH 3/4] staging: iio: ad7150: simplify i2c SMBus return treatment
Date: Sat, 4 May 2019 13:36:43 +0300	[thread overview]
Message-ID: <CA+U=DsoYaN_gCc=jcQ9nHHNpC+voPfHCc=RP_ZyQAC497Jx_7A@mail.gmail.com> (raw)
In-Reply-To: <18725f7ddc3ac42b1c781b1848b05fabd4bd8320.1556919363.git.melissa.srw@gmail.com>

On Sat, May 4, 2019 at 1:26 AM Melissa Wen <melissa.srw@gmail.com> wrote:
>
> Since i2c_smbus_write_byte_data returns no-positive value, this commit
> making the treatment of its return value less verbose.
>
> Signed-off-by: Melissa Wen <melissa.srw@gmail.com>
> ---
>  drivers/staging/iio/cdc/ad7150.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
> index 4ba46fb6ac02..3a4572a9e5ec 100644
> --- a/drivers/staging/iio/cdc/ad7150.c
> +++ b/drivers/staging/iio/cdc/ad7150.c
> @@ -201,16 +201,12 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev,
>         ret = i2c_smbus_write_byte_data(chip->client,
>                                         ad7150_addresses[chan][4],
>                                         sens);
> -       if (ret < 0)
> +       if (ret)

For i2c_smbus_write_byte_data(), checking "ret < 0" or non-zero, is the same.
Changing this doesn't have any added value.

>                 return ret;
> -
> -       ret = i2c_smbus_write_byte_data(chip->client,
> +       else
> +               return i2c_smbus_write_byte_data(chip->client,
>                                         ad7150_addresses[chan][5],
>                                         timeout);

The introduction of the "else" branch is a bit noisy.
The code was a bit neater (and readable) before the else branch, and
functionally identical.

Well, when I say neater before, you have to understand, that I (and I
assume that some other people who write drivers) have a slight
fixation for this pattern:

example1:
ret = fn1();

if (ret < 0)  // could also be just "if (ret)"
   return ret;

ret = fn2();
if (ret < 0)  // could also be just "if (ret)"
   return ret;

example1a:
+ret = fn3();
+if (ret < 0)  // could also be just "if (ret)"
+    return ret;


Various higher-level programming languages, will discourage this
pattern in favor of neater patterns.

I personally, have a few arguments in favor of this pattern:
1) it is closer to how the machine code ; so, closer to how a
low-level instruction looks like
2) if (ever) this needs to be patched, the patch could be neat (see
example1a) ; the examle assumes that it's been added via a patch at a
later point in time
3) it keeps indentation level to a minimum ; this also aligns with
kernel-coding guidelines
(https://www.kernel.org/doc/html/v4.10/process/coding-style.html )
    (indentation seems a bit OCD-like when someone points it out at a
review, but it has it's value over time)

> -       if (ret < 0)
> -               return ret;
> -
> -       return 0;
>  }
>
>  static int ad7150_write_event_config(struct iio_dev *indio_dev,
> --
> 2.20.1
>

  reply	other threads:[~2019-05-04 10:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 22:13 [PATCH 0/4] staging: iio: ad7150: improve driver readability Melissa Wen
2019-05-03 22:13 ` [PATCH 1/4] staging: iio: ad7150: organize registers definition Melissa Wen
2019-05-04 10:13   ` Alexandru Ardelean
2019-05-05 12:52     ` Jonathan Cameron
2019-05-03 22:14 ` [PATCH 2/4] staging: iio: ad7150: use FIELD_GET and GENMASK Melissa Wen
2019-05-04 10:43   ` Alexandru Ardelean
2019-05-06  6:51     ` Ardelean, Alexandru
2019-05-07 20:44       ` Melissa Wen
2019-05-08  7:50         ` Ardelean, Alexandru
2019-05-03 22:15 ` [PATCH 3/4] staging: iio: ad7150: simplify i2c SMBus return treatment Melissa Wen
2019-05-04 10:36   ` Alexandru Ardelean [this message]
2019-05-05 12:59     ` Jonathan Cameron
2019-05-03 22:16 ` [PATCH 4/4] staging: iio: ad7150: clean up of comments Melissa Wen
2019-05-04 11:12 ` [PATCH 0/4] staging: iio: ad7150: improve driver readability Alexandru Ardelean
2019-05-04 14:42   ` Alexandru Ardelean
2019-05-05 13:05   ` Jonathan Cameron
2019-05-07 20:35     ` Melissa Wen

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='CA+U=DsoYaN_gCc=jcQ9nHHNpC+voPfHCc=RP_ZyQAC497Jx_7A@mail.gmail.com' \
    --to=ardeleanalex@gmail.com \
    --cc=21cnbao@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=kernel-usp@googlegroups.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=melissa.srw@gmail.com \
    --cc=pmeerw@pmeerw.net \
    --cc=stefan.popa@analog.com \
    /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).