All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Jonathan Cameron <jic23@kernel.org>,
	linux-iio@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-input@vger.kernel.org,
	Nick Reitemeyer <nick.reitemeyer@web.de>,
	Stephan Gerhold <stephan@gerhold.net>
Subject: Re: [PATCH 2/3 v3] iio: magnetometer: ak8974: Break out measurement
Date: Fri, 17 Apr 2020 16:02:46 +0200	[thread overview]
Message-ID: <20200417140246.GA18337@qmqm.qmqm.pl> (raw)
In-Reply-To: <20200417114020.31291-2-linus.walleij@linaro.org>

On Fri, Apr 17, 2020 at 01:40:19PM +0200, Linus Walleij wrote:
> This breaks out the measurement code to its own function
> so we can handle this without swirling it up with the
> big switch() statement inside ak8974_read_raw().
> 
> Keep a local s16 helper variable for the signed value
> coming out of the measurement before assigning it to the
> integer *val. The local variable makes the code easier
> to read and the compiler will optimize it if possible.
[...]
> +static int ak8974_measure_channel(struct ak8974 *ak8974, unsigned long address,
> +				  int *val)
> +{
> +	__le16 hw_values[3];
> +	int ret;
> +	s16 outval;
[...]
> +	/*
> +	 * This explicit cast to (s16) is necessary as the measurement
> +	 * is done in 2's complement with positive and negative values.
> +	 * The follwing assignment to *val will then convert the signed
> +	 * s16 value to a signed int value.
> +	 */
> +	outval = (s16)le16_to_cpu(hw_values[address]);
> +	*val = outval;

The intermediate 'outval' is not needed. What you describe in the
comment is a normal C integer promotion rule, so I would leave the
comment out, too. IOW, this is equivalent to:

*val = (s16)le16_to_cpu(...);

Otherwise:
Reviewed-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>

  parent reply	other threads:[~2020-04-17 14:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-17 11:40 [PATCH 1/3 v3] iio: magnetometer: ak8974: Correct realbits Linus Walleij
2020-04-17 11:40 ` [PATCH 2/3 v3] iio: magnetometer: ak8974: Break out measurement Linus Walleij
2020-04-17 13:17   ` Andy Shevchenko
2020-04-17 14:02   ` Michał Mirosław [this message]
2020-04-17 11:40 ` [PATCH 3/3 v3] iio: magnetometer: ak8974: Provide scaling Linus Walleij
2020-04-17 14:11   ` Michał Mirosław
2020-04-17 14:05 ` [PATCH 1/3 v3] iio: magnetometer: ak8974: Correct realbits Michał Mirosław
2020-04-18 14:30   ` Jonathan Cameron

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=20200417140246.GA18337@qmqm.qmqm.pl \
    --to=mirq-linux@rere.qmqm.pl \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=nick.reitemeyer@web.de \
    --cc=pmeerw@pmeerw.net \
    --cc=stephan@gerhold.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.