lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZXXAyEkA55MFw5iH@gmail.com>
Date:   Sun, 10 Dec 2023 14:44:40 +0100
From:   Marcus Folkesson <marcus.folkesson@...il.com>
To:     Jonathan Cameron <jic23@...nel.org>
Cc:     Kent Gustavsson <kent@...oris.se>,
        Lars-Peter Clausen <lars@...afoo.de>,
        linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4] iio: adc: mcp3911: simplify code with guard macro

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

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ