[igt-dev] [PATCH i-g-t] lib/igt_audio: make audio_signal_detect take const data

Arkadiusz Hiler arkadiusz.hiler at intel.com
Tue May 14 11:40:11 UTC 2019


On Mon, May 13, 2019 at 04:53:06PM +0300, Simon Ser wrote:
> audio_signal_detect uses gsl_fft_real_radix2_transform which mutates the data
> array. This can be surprising when calling audio_signal_detect and then read
> again the data (e.g. for another check).
> 
> Instead of mutating the array, make audio_signal_detect less error-prone by
> taking a const parameter. Do an internal copy before calling the gsl function.
> 
> Signed-off-by: Simon Ser <simon.ser at intel.com>
> ---
>  lib/igt_audio.c | 13 +++++++++++--
>  lib/igt_audio.h |  2 +-
>  2 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/igt_audio.c b/lib/igt_audio.c
> index fd8cf07c0de3..a1dda50a3c09 100644
> --- a/lib/igt_audio.c
> +++ b/lib/igt_audio.c
> @@ -251,11 +251,14 @@ void audio_signal_fill(struct audio_signal *signal, int16_t *buffer,
>   * Checks that frequencies specified in signal, and only those, are included
>   * in the input data.
>   *
> - * sampling_rate is given in Hz. data_len is the number of elements in data.
> + * sampling_rate is given in Hz. samples_len is the number of elements in
> + * samples.
>   */
>  bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,
> -			 int channel, double *data, size_t data_len)
> +			 int channel, const double *samples, size_t samples_len)
>  {
> +	double *data;
> +	size_t data_len = samples_len;
>  	size_t bin_power_len = data_len / 2 + 1;
>  	double bin_power[bin_power_len];
>  	bool detected[FREQS_MAX];

	ret = gsl_fft_real_radix2_transform(data, 1, data_len);
-	igt_assert(ret == 0);
+	if (ret != 0) {
+		free(data);
+		igt_assert(ret == 0);
+	}

or so...
to make valgrind et al. happy by covering every function exit


More information about the igt-dev mailing list