Re: [PATCH v2 5/9] iio: inkern: Add a helper to query an available minimum raw value

From: Herve Codina
Date: Mon Jun 05 2023 - 03:47:18 EST


On Sat, 3 Jun 2023 17:04:37 +0300
andy.shevchenko@xxxxxxxxx wrote:

> Tue, May 23, 2023 at 05:12:19PM +0200, Herve Codina kirjoitti:
> > A helper, iio_read_max_channel_raw() exists to read the available
> > maximum raw value of a channel but nothing similar exists to read the
> > available minimum raw value.
> >
> > This new helper, iio_read_min_channel_raw(), fills the hole and can be
> > used for reading the available minimum raw value of a channel.
> > It is fully based on the existing iio_read_max_channel_raw().
>
> ...
>
> > +static int iio_channel_read_min(struct iio_channel *chan,
> > + int *val, int *val2, int *type,
> > + enum iio_chan_info_enum info)
> > +{
> > + int unused;
> > + const int *vals;
> > + int length;
> > + int ret;
>
> > + if (!val2)
> > + val2 = &unused;
>
> It's a single place, where this is used, can you move it there?

I will do that in the next iteration.
Also, I will do the same modification in iio_channel_read_max() as it has
exactly the same code.

>
> > + ret = iio_channel_read_avail(chan, &vals, type, &length, info);
> > + if (ret < 0)
> > + return ret;
> > +
> > + switch (ret) {
> > + case IIO_AVAIL_RANGE:
> > + switch (*type) {
> > + case IIO_VAL_INT:
> > + *val = vals[0];
> > + break;
> > + default:
> > + *val = vals[0];
> > + *val2 = vals[1];
> > + }
> > + return 0;
> > +
> > + case IIO_AVAIL_LIST:
> > + if (length <= 0)
> > + return -EINVAL;
> > + switch (*type) {
> > + case IIO_VAL_INT:
> > + *val = vals[--length];
>
> > + while (length) {
>
> while (length--) {
>
> will do the job and at the same time...
>
>
> > + if (vals[--length] < *val)
> > + *val = vals[length];
>
> ...this construction becomes less confusing (easier to parse).

Indeed, I will change in the next iteration.

>
> > + }
> > + break;
> > + default:
> > + /* FIXME: learn about min for other iio values */
>
> I believe in a final version this comment won't be here.

We have the same FIXME comment in the iio_channel_read_max() function I
copied to create this iio_channel_read_min() and, to be honest, I
don't really know how to handle these other cases.

In this series, I would prefer to keep this FIXME.

>
> > + return -EINVAL;
> > + }
> > + return 0;
> > +
> > + default:
> > + return -EINVAL;
> > + }
> > +}
>

Thanks for the review,
Hervé