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

Romain Gantois
2025-09-17T16:13:57Z

[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]

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,

--
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]