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: <187e480d5732818bfd97c54820b0ae0aa2d53b1d.camel@gmail.com>
Date: Tue, 11 Mar 2025 09:29:30 +0000
From: Nuno Sá <noname.nuno@...il.com>
To: David Lechner <dlechner@...libre.com>, Lars-Peter Clausen
 <lars@...afoo.de>,  Michael Hennerich <Michael.Hennerich@...log.com>, Nuno
 Sá <nuno.sa@...log.com>, Esteban Blanc	
 <eblanc@...libre.com>, Jonathan Cameron <jic23@...nel.org>
Cc: linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/5] iio: adc: ad4030: don't store scan_type in state

On Mon, 2025-03-10 at 15:43 -0500, David Lechner wrote:
> Move getting the scan_type to ad4030_conversion(). Previously, we were
> getting the scan_type in two other places, then storing it in the
> state struct before using it in ad4030_conversion(). This was a bit
> fragile against potential future changes since it isn't obvious that
> anything that could potentially change the scan_type would need to
> also update the state struct. Also, the non-obviousness of this led to
> a redundant call to iio_get_current_scan_type() in
> ad4030_single_conversion() since it also calls ad4030_set_mode() which
> in turn calls ad4030_conversion().
> 
> To simplify things, just call iio_get_current_scan_type() in
> ad4030_conversion() where the returned struct is actually used and
> don't bother storing it in the state struct.
> 
> Signed-off-by: David Lechner <dlechner@...libre.com>
> ---

Reviewed-by: Nuno Sá <nuno.sa@...log.com>

>  drivers/iio/adc/ad4030.c | 24 +++++++++---------------
>  1 file changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c
> index
> c2117c7a296f22aeeec6911c8a8c74ed576296a0..54ad74b96c9f256a67848330f875379edc82
> 8b0b 100644
> --- a/drivers/iio/adc/ad4030.c
> +++ b/drivers/iio/adc/ad4030.c
> @@ -147,7 +147,6 @@ struct ad4030_state {
>  	struct spi_device *spi;
>  	struct regmap *regmap;
>  	const struct ad4030_chip_info *chip;
> -	const struct iio_scan_type *current_scan_type;
>  	struct gpio_desc *cnv_gpio;
>  	int vref_uv;
>  	int vio_uv;
> @@ -562,11 +561,6 @@ static int ad4030_set_mode(struct iio_dev *indio_dev,
> unsigned long mask)
>  		st->mode = AD4030_OUT_DATA_MD_DIFF;
>  	}
>  
> -	st->current_scan_type = iio_get_current_scan_type(indio_dev,
> -							  st->chip-
> >channels);
> -	if (IS_ERR(st->current_scan_type))
> -		return PTR_ERR(st->current_scan_type);
> -
>  	return regmap_update_bits(st->regmap, AD4030_REG_MODES,
>  				  AD4030_REG_MODES_MASK_OUT_DATA_MODE,
>  				  st->mode);
> @@ -614,15 +608,20 @@ static void ad4030_extract_interleaved(u8 *src, u32
> *ch0, u32 *ch1)
>  static int ad4030_conversion(struct iio_dev *indio_dev)
>  {
>  	struct ad4030_state *st = iio_priv(indio_dev);
> -	unsigned char diff_realbytes =
> -		BITS_TO_BYTES(st->current_scan_type->realbits);
> -	unsigned char diff_storagebytes =
> -		BITS_TO_BYTES(st->current_scan_type->storagebits);
> +	const struct iio_scan_type *scan_type;
> +	unsigned char diff_realbytes, diff_storagebytes;
>  	unsigned int bytes_to_read;
>  	unsigned long cnv_nb = BIT(st->avg_log2);
>  	unsigned int i;
>  	int ret;
>  
> +	scan_type = iio_get_current_scan_type(indio_dev, st->chip->channels);
> +	if (IS_ERR(scan_type))
> +		return PTR_ERR(scan_type);
> +
> +	diff_realbytes = BITS_TO_BYTES(scan_type->realbits);
> +	diff_storagebytes = BITS_TO_BYTES(scan_type->storagebits);
> +
>  	/* Number of bytes for one differential channel */
>  	bytes_to_read = diff_realbytes;
>  	/* Add one byte if we are using a differential + common byte mode */
> @@ -673,11 +672,6 @@ static int ad4030_single_conversion(struct iio_dev
> *indio_dev,
>  	if (ret)
>  		return ret;
>  
> -	st->current_scan_type = iio_get_current_scan_type(indio_dev,
> -							  st->chip-
> >channels);
> -	if (IS_ERR(st->current_scan_type))
> -		return PTR_ERR(st->current_scan_type);
> -
>  	ret = ad4030_conversion(indio_dev);
>  	if (ret)
>  		return ret;
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ