lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5015441.GXAFRqVoOG@fw-rgant>
Date: Wed, 01 Oct 2025 09:19:37 +0200
From: Romain Gantois <romain.gantois@...tlin.com>
To: Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
 Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
 Conor Dooley <conor+dt@...nel.org>, Jonathan Cameron <jic23@...nel.org>,
 Nuno Sá <nuno.sa@...log.com>,
 Andy Shevchenko <andy@...nel.org>, David Lechner <dlechner@...libre.com>
Cc: Hans de Goede <hansg@...nel.org>,
 Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
 linux-kernel@...r.kernel.org, devicetree@...r.kernel.org,
 linux-iio@...r.kernel.org
Subject: Re: [PATCH v2 2/5] iio: add processed write API

Hello David,

On Thursday, 25 September 2025 23:10:14 CEST David Lechner wrote:
> On 9/25/25 7:37 AM, Romain Gantois wrote:
> > Add a function to allow IIO consumers to write a processed value to a
...
> > +static int iio_convert_processed_to_raw_unlocked(struct iio_channel
> > *chan,
> > +						 int processed, int *raw,
> > +						 unsigned int scale)
> > +{
> > +	int scale_type, scale_val, scale_val2;
> > +	int offset_type, offset_val, offset_val2;
> > +	int ret;
> > +
> > +	scale_type = iio_channel_read(chan, &scale_val, &scale_val2,
> > +				      IIO_CHAN_INFO_SCALE);
> > +	if (scale_type >= 0) {
> > +		ret = iio_divide_by_value(raw, processed, scale_type, 
scale_val,
> > scale_val2); +		if (ret < 0)
> > +			return ret;
> > +	} else {
> > +		*raw = processed;
> > +	}
> > +
> > +	if (!scale)
> > +		return -ERANGE;
> > +
> > +	*raw = div_s64(*raw, scale);
> > +
> > +	offset_type = iio_channel_read(chan, &offset_val, &offset_val2,
> > +				       IIO_CHAN_INFO_OFFSET);
> > +	if (offset_type >= 0) {
> > +		switch (offset_type) {
> > +		case IIO_VAL_INT:
> > +		case IIO_VAL_INT_PLUS_MICRO:
> > +		case IIO_VAL_INT_PLUS_NANO:
> > +			break;
> > +		case IIO_VAL_FRACTIONAL:
> > +			offset_val /= offset_val2;
> > +			break;
> > +		case IIO_VAL_FRACTIONAL_LOG2:
> > +			offset_val >>= offset_val2;
> > +			break;
> > +		default:
> > +			return -EINVAL;
> > +		}
> > +
> > +		*raw -= offset_val;
> > +	}
> 
> There are some rounding biases in this function, but I'm not sure if
> it is worth trying to make a perfectly fair function.

I'm unfamiliar with the notion of rounding bias, does it mean that nested 
calls of this function would tend to amplify rounding errors? In this case, 
would rounding to the nearest integer instead of whatever is being done by the 
integer division here be a good solution?

Maybe I'm misunderstanding what you mean, in that case please let me know.

Thanks,

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

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ