Re: [PATCH v4] iio: adc: mcp3911: simplify code with guard macro

From: Marcus Folkesson
Date: Sun Dec 10 2023 - 08:40:13 EST


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@xxxxxxxxx> wrote:
>
> > Use the guard(mutex) macro for handle mutex lock/unlocks.
> >
> > Signed-off-by: Marcus Folkesson <marcus.folkesson@xxxxxxxxx>
> 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: signature.asc
Description: PGP signature