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: <20230423121815.6d7c8039@jic23-huawei>
Date:   Sun, 23 Apr 2023 12:18:15 +0100
From:   Jonathan Cameron <jic23@...nel.org>
To:     Matti Vaittinen <mazziesaccount@...il.com>
Cc:     Matti Vaittinen <matti.vaittinen@...rohmeurope.com>,
        Lars-Peter Clausen <lars@...afoo.de>,
        linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] iio: gts-helpers: fix integration time units

On Mon, 17 Apr 2023 12:20:18 +0300
Matti Vaittinen <mazziesaccount@...il.com> wrote:

> The IIO ABI mandates expressing integration times in seconds. The GTS
> helper errorneously uses micro seconds in integration_times_available.
> Fix this by converting the lists to IIO_VAL_INT_PLUS_MICRO.
> 
> Signed-off-by: Matti Vaittinen <mazziesaccount@...il.com>
> ---
>  drivers/iio/industrialio-gts-helper.c | 43 ++++++++++++++++++++-------
>  1 file changed, 33 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c
> index 8bb68975b259..2ab8d2dce019 100644
> --- a/drivers/iio/industrialio-gts-helper.c
> +++ b/drivers/iio/industrialio-gts-helper.c
> @@ -337,6 +337,17 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts)
>  	return ret;
>  }
>  
> +static void iio_gts_us_to_int_micro(int *time_us, int *int_micro_times,
> +				    int num_times)
> +{
> +	int i;
> +
> +	for (i = 0; i < num_times; i++) {
> +		int_micro_times[i * 2] = time_us[i] / 1000000;
> +		int_micro_times[i * 2 + 1] = time_us[i] % 1000000;
> +	}
> +}
> +
>  /**
>   * iio_gts_build_avail_time_table - build table of available integration times
>   * @gts:	Gain time scale descriptor
> @@ -351,7 +362,7 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts)
>   */
>  static int iio_gts_build_avail_time_table(struct iio_gts *gts)
>  {
> -	int *times, i, j, idx = 0;
> +	int *times, i, j, idx = 0, *int_micro_times;
>  
>  	if (!gts->num_itime)
>  		return 0;
> @@ -360,6 +371,7 @@ static int iio_gts_build_avail_time_table(struct iio_gts *gts)
>  	if (!times)
>  		return -ENOMEM;
>  
> +

Grumble.

If nothing else comes up I'll tidy that stray line up when applying.

Note that these will need to wait for after rc1 now so my fixes branch
has moved on to include the code being fixed.

>  	/* Sort times from all tables to one and remove duplicates */
>  	for (i = gts->num_itime - 1; i >= 0; i--) {
>  		int new = gts->itime_table[i].time_us;
> @@ -378,13 +390,24 @@ static int iio_gts_build_avail_time_table(struct iio_gts *gts)
>  			}
>  		}
>  	}
> -	gts->avail_time_tables = times;
> -	/*
> -	 * This is just to survive a unlikely corner-case where times in the
> -	 * given time table were not unique. Else we could just trust the
> -	 * gts->num_itime.
> -	 */
> -	gts->num_avail_time_tables = idx;
> +
> +	/* create a list of times formatted as list of IIO_VAL_INT_PLUS_MICRO */
> +	int_micro_times = kcalloc(idx, sizeof(int) * 2, GFP_KERNEL);
> +	if (int_micro_times) {
> +		/*
> +		 * This is just to survive a unlikely corner-case where times in
> +		 * the given time table were not unique. Else we could just
> +		 * trust the gts->num_itime.
> +		 */
> +		gts->num_avail_time_tables = idx;
> +		iio_gts_us_to_int_micro(times, int_micro_times, idx);
> +	}
> +
> +	gts->avail_time_tables = int_micro_times;
> +	kfree(times);
> +
> +	if (!int_micro_times)
> +		return -ENOMEM;
>  
>  	return 0;
>  }
> @@ -683,8 +706,8 @@ int iio_gts_avail_times(struct iio_gts *gts,  const int **vals, int *type,
>  		return -EINVAL;
>  
>  	*vals = gts->avail_time_tables;
> -	*type = IIO_VAL_INT;
> -	*length = gts->num_avail_time_tables;
> +	*type = IIO_VAL_INT_PLUS_MICRO;
> +	*length = gts->num_avail_time_tables * 2;
>  
>  	return IIO_AVAIL_LIST;
>  }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ