[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250421133751.6fb5b4d4@jic23-huawei>
Date: Mon, 21 Apr 2025 13:37:51 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Gabriel Shahrouzi <gshahrouzi@...il.com>
Cc: gregkh@...uxfoundation.org, lars@...afoo.de, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-staging@...ts.linux.dev,
Michael.Hennerich@...log.com, sonic.zhang@...log.com, vapier@...too.org,
skhan@...uxfoundation.org, linux-kernel-mentees@...ts.linux.dev
Subject: Re: [PATCH v5 5/5] staging: iio: adc: ad7816: Simplify channel
validation using chip_info
On Sat, 19 Apr 2025 21:49:10 -0400
Gabriel Shahrouzi <gshahrouzi@...il.com> wrote:
> Refactor the channel validation logic within ad7816_store_channel() to
> leverage the max_channels field previously introduced in the
> ad7816_chip_info structure.
>
> Signed-off-by: Gabriel Shahrouzi <gshahrouzi@...il.com>
Carries forward the odd mask usage from patch 1. So fix that up and then
I think this is fine. Given you introduce max_channels just for this, ideal
would be to only introduce it in this patch (with a better name - see
earlier comment)
Jonathan
> ---
> drivers/staging/iio/adc/ad7816.c | 12 ++----------
> 1 file changed, 2 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
> index ab7520a8a3da9..7a59cfbcc6e33 100644
> --- a/drivers/staging/iio/adc/ad7816.c
> +++ b/drivers/staging/iio/adc/ad7816.c
> @@ -204,17 +204,9 @@ static ssize_t ad7816_store_channel(struct device *dev,
> if (ret)
> return ret;
>
> - if (data > AD7816_CS_MAX && data != AD7816_CS_MASK) {
> + if (data > chip->chip_info->max_channels && data != AD7816_CS_MASK) {
> dev_err(&chip->spi_dev->dev, "Invalid channel id %lu for %s.\n",
> - data, indio_dev->name);
> - return -EINVAL;
> - } else if (strcmp(indio_dev->name, "ad7818") == 0 && data > 1 && data != AD7816_CS_MASK) {
> - dev_err(&chip->spi_dev->dev,
> - "Invalid channel id %lu for ad7818.\n", data);
> - return -EINVAL;
> - } else if (strcmp(indio_dev->name, "ad7816") == 0 && data > 0 && data != AD7816_CS_MASK) {
> - dev_err(&chip->spi_dev->dev,
> - "Invalid channel id %lu for ad7816.\n", data);
> + data, chip->chip_info->name);
> return -EINVAL;
> }
>
Powered by blists - more mailing lists