Re: [PATCH 1/4] iio: inkern: Remove useless argument to iio_channel_read_max()
From: Jonathan Cameron
Date: Sun Jul 31 2022 - 12:57:09 EST
On Thu, 21 Jul 2022 20:15:23 +0100
Paul Cercueil <paul@xxxxxxxxxxxxxxx> wrote:
> The 'type' argument was passed by the only caller of the
> iio_channel_read_max() function as a pointer to return an extra value,
> but the value of the variable passed by the caller was never read
> afterwards.
>
> Signed-off-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx>
Curious. I'm playing guess the intent here and I suspect that what
we should really be doing is checking type in
iio_read_max_channel_raw() and returning an error if it is not IIO_VAL_INT
(can only get there for IIO_AVAIL_RANGE currently as there is a FIXME for
IIO_AVAIL_LIST for non IIO_VAL_INT types)
I'm not sure we've ever documented that _RAW can't be non integer even if
that makes relatively little sense most of the time..
Jonathan
> ---
> drivers/iio/inkern.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index df74765d33dc..e8a25852f0df 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -813,21 +813,22 @@ int iio_read_avail_channel_raw(struct iio_channel *chan,
> EXPORT_SYMBOL_GPL(iio_read_avail_channel_raw);
>
> static int iio_channel_read_max(struct iio_channel *chan,
> - int *val, int *val2, int *type,
> + int *val, int *val2,
> enum iio_chan_info_enum info)
> {
> int unused;
> const int *vals;
> int length;
> int ret;
> + int type;
>
> if (!val2)
> val2 = &unused;
>
> - ret = iio_channel_read_avail(chan, &vals, type, &length, info);
> + ret = iio_channel_read_avail(chan, &vals, &type, &length, info);
> switch (ret) {
> case IIO_AVAIL_RANGE:
> - switch (*type) {
> + switch (type) {
> case IIO_VAL_INT:
> *val = vals[2];
> break;
> @@ -840,7 +841,7 @@ static int iio_channel_read_max(struct iio_channel *chan,
> case IIO_AVAIL_LIST:
> if (length <= 0)
> return -EINVAL;
> - switch (*type) {
> + switch (type) {
> case IIO_VAL_INT:
> *val = vals[--length];
> while (length) {
> @@ -863,7 +864,6 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
> {
> struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
> int ret;
> - int type;
>
> mutex_lock(&iio_dev_opaque->info_exist_lock);
> if (!chan->indio_dev->info) {
> @@ -871,7 +871,7 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
> goto err_unlock;
> }
>
> - ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
> + ret = iio_channel_read_max(chan, val, NULL, IIO_CHAN_INFO_RAW);
> err_unlock:
> mutex_unlock(&iio_dev_opaque->info_exist_lock);
>