From: Marcus Folkesson <marcus.folkesson@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Kent Gustavsson <kent@minoris.se>,
Lars-Peter Clausen <lars@metafoo.de>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] iio: adc: mcp3911: simplify code with guard macro
Date: Sun, 10 Dec 2023 14:44:40 +0100 [thread overview]
Message-ID: <ZXXAyEkA55MFw5iH@gmail.com> (raw)
In-Reply-To: <20231210113632.7880e730@jic23-huawei>
[-- Attachment #1: Type: text/plain, Size: 2928 bytes --]
On Sun, Dec 10, 2023 at 11:36:32AM +0000, Jonathan Cameron wrote:
> On Wed, 06 Dec 2023 19:39:04 +0100
> Marcus Folkesson <marcus.folkesson@gmail.com> wrote:
>
> > Use the guard(mutex) macro for handle mutex lock/unlocks.
> >
> > Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
> Various changes inline - most are focused around simplifying the
> path for any given flow through the code.
>
> Rather than going for a v5 - I've applied this with the following diff on top
> diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c
> index dfcb6cb7570f..7a32e7a1be9d 100644
> --- a/drivers/iio/adc/mcp3911.c
> +++ b/drivers/iio/adc/mcp3911.c
> @@ -317,7 +317,7 @@ static int mcp3911_read_raw(struct iio_dev *indio_dev,
> int *val2, long mask)
> {
> struct mcp3911 *adc = iio_priv(indio_dev);
> - int ret = -EINVAL;
> + int ret;
>
> guard(mutex)(&adc->lock);
> switch (mask) {
> @@ -331,17 +331,23 @@ static int mcp3911_read_raw(struct iio_dev *indio_dev,
> return IIO_VAL_INT;
> case IIO_CHAN_INFO_OFFSET:
> ret = adc->chip->get_offset(adc, channel->channel, val);
> - return (ret) ? ret : IIO_VAL_INT;
> + if (ret)
> + return ret;
> +
> + return IIO_VAL_INT;
> case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> ret = adc->chip->get_osr(adc, val);
> - return (ret) ? ret : IIO_VAL_INT;
> + if (ret)
> + return ret;
> +
> + return IIO_VAL_INT;
> case IIO_CHAN_INFO_SCALE:
> *val = mcp3911_scale_table[ilog2(adc->gain[channel->channel])][0];
> *val2 = mcp3911_scale_table[ilog2(adc->gain[channel->channel])][1];
> return IIO_VAL_INT_PLUS_NANO;
> + default:
> + return -EINVAL;
> }
> -
> - return ret;
> }
>
> static int mcp3911_write_raw(struct iio_dev *indio_dev,
> @@ -361,7 +367,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,
> return adc->chip->set_scale(adc, channel->channel, i);
> }
> }
> - break;
> + return -EINVAL;
> case IIO_CHAN_INFO_OFFSET:
> if (val2 != 0)
> return -EINVAL;
> @@ -373,9 +379,10 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,
> return adc->chip->set_osr(adc, i);
> }
> }
> - break;
> + return -EINVAL;
> + default:
> + return -EINVAL;
> }
> - return -EINVAL;
> }
>
> hope that's ok with you!
Thank you Jonathan
Best regards
Marcus Folkesson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2023-12-10 13:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-06 18:39 [PATCH v4] iio: adc: mcp3911: simplify code with guard macro Marcus Folkesson
2023-12-10 11:36 ` Jonathan Cameron
2023-12-10 13:44 ` Marcus Folkesson [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=ZXXAyEkA55MFw5iH@gmail.com \
--to=marcus.folkesson@gmail.com \
--cc=jic23@kernel.org \
--cc=kent@minoris.se \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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.