From: Jonathan Cameron <jic23@kernel.org>
To: Marcus Folkesson <marcus.folkesson@gmail.com>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Michael Welling <mwelling@ieee.org>
Subject: Re: [PATCH] iio: dac: mcp4922: fix error handling in mcp4922_write_raw
Date: Sat, 25 Aug 2018 09:47:41 +0100 [thread overview]
Message-ID: <20180825094741.4581deb0@archlinux> (raw)
In-Reply-To: <20180824202440.21754-1-marcus.folkesson@gmail.com>
On Fri, 24 Aug 2018 22:24:40 +0200
Marcus Folkesson <marcus.folkesson@gmail.com> wrote:
> Do not try to write negative values and make sure that the write goes well.
>
+CC Michael as it's his driver.
I'll take this as it 'appears' straight forward but I won't be pushing
it out as a non rebasing branch for a few days if I've missed anything.
Applied to the togreg branch of iio.git and pushed out for now as testing
for the autobuilders to play with it.
Thanks,
Jonathan
> Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
> ---
> drivers/iio/dac/mcp4922.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/dac/mcp4922.c b/drivers/iio/dac/mcp4922.c
> index bf9aa3fc0534..b5190d1dae8e 100644
> --- a/drivers/iio/dac/mcp4922.c
> +++ b/drivers/iio/dac/mcp4922.c
> @@ -94,17 +94,22 @@ static int mcp4922_write_raw(struct iio_dev *indio_dev,
> long mask)
> {
> struct mcp4922_state *state = iio_priv(indio_dev);
> + int ret;
>
> if (val2 != 0)
> return -EINVAL;
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - if (val > GENMASK(chan->scan_type.realbits-1, 0))
> + if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0))
> return -EINVAL;
> val <<= chan->scan_type.shift;
> - state->value[chan->channel] = val;
> - return mcp4922_spi_write(state, chan->channel, val);
> +
> + ret = mcp4922_spi_write(state, chan->channel, val);
> + if (!ret)
> + state->value[chan->channel] = val;
> + return ret;
> +
> default:
> return -EINVAL;
> }
prev parent reply other threads:[~2018-08-25 12:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-24 20:24 [PATCH] iio: dac: mcp4922: fix error handling in mcp4922_write_raw Marcus Folkesson
2018-08-25 8:47 ` Jonathan Cameron [this message]
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=20180825094741.4581deb0@archlinux \
--to=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcus.folkesson@gmail.com \
--cc=mwelling@ieee.org \
--cc=pmeerw@pmeerw.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.