Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: cs-amp-lib-test: Force test calibration blob entries to be valid

For a normal calibration blob the calTarget values must be non-zero and
unique, and the calTime values must be non-zero. Don't rely on
get_random_bytes() to be random enough to guarantee this. Force the
calTarget and calTime values to be valid while retaining randomness
in the values.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Fixes: 177862317a98 ("ASoC: cs-amp-lib: Add KUnit test for calibration helpers")
Link: https://patch.msgid.link/20240822115725.259568-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Richard Fitzgerald and committed by
Mark Brown
bff980d8 5f7c98b7

+9
+9
sound/soc/codecs/cs-amp-lib-test.c
··· 38 38 { 39 39 struct cs_amp_lib_test_priv *priv = test->priv; 40 40 unsigned int blob_size; 41 + int i; 41 42 42 43 blob_size = offsetof(struct cirrus_amp_efi_data, data) + 43 44 sizeof(struct cirrus_amp_cal_data) * num_amps; ··· 50 49 priv->cal_blob->count = num_amps; 51 50 52 51 get_random_bytes(priv->cal_blob->data, sizeof(struct cirrus_amp_cal_data) * num_amps); 52 + 53 + /* Ensure all timestamps are non-zero to mark the entry valid. */ 54 + for (i = 0; i < num_amps; i++) 55 + priv->cal_blob->data[i].calTime[0] |= 1; 56 + 57 + /* Ensure that all UIDs are non-zero and unique. */ 58 + for (i = 0; i < num_amps; i++) 59 + *(u8 *)&priv->cal_blob->data[i].calTarget[0] = i + 1; 53 60 } 54 61 55 62 static u64 cs_amp_lib_test_get_target_uid(struct kunit *test)