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: <c95fb95d-f892-4dda-abb1-0b5ac98454c8@baylibre.com>
Date: Mon, 19 May 2025 10:18:11 -0500
From: David Lechner <dlechner@...libre.com>
To: Pop Ioan Daniel <pop.ioan-daniel@...log.com>,
 Lars-Peter Clausen <lars@...afoo.de>,
 Michael Hennerich <Michael.Hennerich@...log.com>,
 Jonathan Cameron <jic23@...nel.org>, Nuno Sá
 <nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>,
 Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
 Conor Dooley <conor+dt@...nel.org>,
 Sergiu Cuciurean <sergiu.cuciurean@...log.com>,
 Dragos Bogdan <dragos.bogdan@...log.com>,
 Antoniu Miclaus <antoniu.miclaus@...log.com>,
 Olivier Moysan <olivier.moysan@...s.st.com>,
 Javier Carrasco <javier.carrasco.cruz@...il.com>,
 Matti Vaittinen <mazziesaccount@...il.com>,
 Tobias Sperling <tobias.sperling@...ting.com>,
 Alisa-Dariana Roman <alisadariana@...il.com>,
 Marcelo Schmitt <marcelo.schmitt@...log.com>, linux-iio@...r.kernel.org,
 devicetree@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver

On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> Add support for the AD7405/ADUM770x, a high performance isolated ADC,
> 1-channel, 16-bit with a second-order Σ-Δ modulator that converts an
> analog input signal into a high speed, single-bit data stream.
> 
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@...log.com>
> ---

...

> +static int ad7405_set_dec_rate(struct iio_dev *indio_dev,
> +			       const struct iio_chan_spec *chan,
> +			       unsigned int dec_rate)
> +{
> +	struct ad7405_state *st = iio_priv(indio_dev);
> +	int ret;

We probably want some range checking here to make sure dec_rate is exactly one of
ad7405_dec_rates before passing it to the backend.

> +
> +	ret = iio_backend_oversampling_ratio_set(st->back, chan->scan_index, dec_rate);
> +	if (ret)
> +		return ret;
> +
> +	st->dec_rate = dec_rate;

Otherwise, this will report back a wrong value to userspace in ad7405_read_raw().

> +
> +	return 0;
> +}
> +
> +static int ad7405_get_scale(struct ad7405_state *st, int *val, int *val2)
> +{
> +	*val = st->info->full_scale_mv;
> +	*val2 = st->info->channel.scan_type.realbits - 1;
> +
> +	return IIO_VAL_FRACTIONAL_LOG2;

Probably not worth having a separate function for this. Can just do it inline.

> +}
> +
> +static int ad7405_read_raw(struct iio_dev *indio_dev,
> +			   const struct iio_chan_spec *chan, int *val,
> +			   int *val2, long info)
> +{
> +	struct ad7405_state *st = iio_priv(indio_dev);
> +
> +	switch (info) {
> +	case IIO_CHAN_INFO_SCALE:
> +		return ad7405_get_scale(st, val, val2);
> +	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> +		*val = st->dec_rate;
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_SAMP_FREQ:
> +		*val = DIV_ROUND_CLOSEST_ULL(st->ref_frequency, st->dec_rate);
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_OFFSET:
> +		*val = 2 << (st->info->channel.scan_type.realbits - 1);

Isn't this supposed to be:

		*val = -(1 << (st->info->channel.scan_type.realbits - 1));

2 was a typo by me, but hopefully, you are testing this and doing the
math to double-check it is correct! I.e. generate a constant voltage signal
and capture some data, then convert it to mV with (raw + offset) * scale to
make sure it matches the voltage being applied to the input.

(I'm only human, so believe the math if disagrees with what I say. :-p)

> +		return IIO_VAL_INT;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static int ad7405_write_raw(struct iio_dev *indio_dev,
> +			    struct iio_chan_spec const *chan, int val,
> +			    int val2, long info)
> +{
> +	switch (info) {
> +	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:

val can be negative here, which can cause it to turn into a large positive
number when it gets changed to unsigned since the last parameter of
ad7405_set_dec_rate has unsigned type. So we should either check for negative
first here or change the parameter to signed and check in the function.

> +		return ad7405_set_dec_rate(indio_dev, chan, val);
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ