Skip to content

Commit

Permalink
ASoC: cs-amp-lib-test: Force test calibration blob entries to be valid
Browse files Browse the repository at this point in the history
[ Upstream commit bff980d ]

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]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
rfvirgil authored and gregkh committed Sep 4, 2024
1 parent 294e649 commit 7c9d049
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sound/soc/codecs/cs-amp-lib-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static void cs_amp_lib_test_init_dummy_cal_blob(struct kunit *test, int num_amps
{
struct cs_amp_lib_test_priv *priv = test->priv;
unsigned int blob_size;
int i;

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

get_random_bytes(priv->cal_blob->data, sizeof(struct cirrus_amp_cal_data) * num_amps);

/* Ensure all timestamps are non-zero to mark the entry valid. */
for (i = 0; i < num_amps; i++)
priv->cal_blob->data[i].calTime[0] |= 1;

/* Ensure that all UIDs are non-zero and unique. */
for (i = 0; i < num_amps; i++)
*(u8 *)&priv->cal_blob->data[i].calTarget[0] = i + 1;
}

static u64 cs_amp_lib_test_get_target_uid(struct kunit *test)
Expand Down

0 comments on commit 7c9d049

Please sign in to comment.