Skip to content

Commit bff980d

Browse files
rfvirgilbroonie
authored andcommitted
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 <[email protected]> Fixes: 1778623 ("ASoC: cs-amp-lib: Add KUnit test for calibration helpers") Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 5f7c98b commit bff980d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sound/soc/codecs/cs-amp-lib-test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static void cs_amp_lib_test_init_dummy_cal_blob(struct kunit *test, int num_amps
3838
{
3939
struct cs_amp_lib_test_priv *priv = test->priv;
4040
unsigned int blob_size;
41+
int i;
4142

4243
blob_size = offsetof(struct cirrus_amp_efi_data, data) +
4344
sizeof(struct cirrus_amp_cal_data) * num_amps;
@@ -49,6 +50,14 @@ static void cs_amp_lib_test_init_dummy_cal_blob(struct kunit *test, int num_amps
4950
priv->cal_blob->count = num_amps;
5051

5152
get_random_bytes(priv->cal_blob->data, sizeof(struct cirrus_amp_cal_data) * num_amps);
53+
54+
/* Ensure all timestamps are non-zero to mark the entry valid. */
55+
for (i = 0; i < num_amps; i++)
56+
priv->cal_blob->data[i].calTime[0] |= 1;
57+
58+
/* Ensure that all UIDs are non-zero and unique. */
59+
for (i = 0; i < num_amps; i++)
60+
*(u8 *)&priv->cal_blob->data[i].calTarget[0] = i + 1;
5261
}
5362

5463
static u64 cs_amp_lib_test_get_target_uid(struct kunit *test)

0 commit comments

Comments
 (0)