Re: [PATCH 2/4] iio: add processed write API

Jonathan Cameron
2025-09-20T11:56:10Z

On Wed, 17 Sep 2025 17:46:00 +0200
Romain Gantois <romain.gantois@bootlin.com> wrote:

> Hello David,
>
> On Tuesday, 16 September 2025 21:23:04 CEST David Lechner wrote:
> > On 9/16/25 5:24 AM, Romain Gantois wrote:
> > > Add a function to allow IIO consumers to write a processed value to a
> ...
> > > + case IIO_VAL_FRACTIONAL:
> > > + tmp_num = (s64)processed * (s64)scale_val2;
> > > + tmp_den = scale_val;
> > > + break;
> > > + case IIO_VAL_FRACTIONAL_LOG2:
> > > + tmp_num = (s64)processed << scale_val2;
> > > + tmp_den = scale_val;
> > > + break;
> > > + default:
> > > + return -EINVAL;
> > > + }
> > > +
> > > + tmp_den *= scale;
> > > +
> > > + *raw = div64_s64(tmp_num, tmp_den);
> > > + }
> >
> > It can be quite tricky to get all of these combinations right. I would
> > prefer if added some unit tests like we did in [1].
> >
> > [1]:
> > https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=tes
> > ting&id=c732e60ee10ed0611a59513cbf9c8d35fbe7cf65
>
> Agreed, that would be nice, I'll look into it.
>
> Thanks,
>

Overall code looks fine to me but unit tests would indeed be great.
Thanks,

Jonathan