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.

firmware: cs_dsp: Add some sanity-checking to test harness

Add sanity checking to some test harness functions to help catch bugs
in the test code. This consists of checking the range of some arguments
and checking that reads from the dummy regmap succeed.

Most of the harness code already had sanity-checking but there were a
few places where it was missing or was assumed that the test could be
trusted to pass valid values.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20250416122422.783215-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Richard Fitzgerald and committed by
Mark Brown
4308487b 9b62b7a6

+16 -6
+3
drivers/firmware/cirrus/test/cs_dsp_mock_bin.c
··· 176 176 struct cs_dsp_mock_bin_builder *builder; 177 177 struct wmfw_coeff_hdr *hdr; 178 178 179 + KUNIT_ASSERT_LE(priv->test, format_version, 0xff); 180 + KUNIT_ASSERT_LE(priv->test, fw_version, 0xffffff); 181 + 179 182 builder = kunit_kzalloc(priv->test, sizeof(*builder), GFP_KERNEL); 180 183 KUNIT_ASSERT_NOT_ERR_OR_NULL(priv->test, builder); 181 184 builder->test_priv = priv;
+9 -6
drivers/firmware/cirrus/test/cs_dsp_mock_mem_maps.c
··· 535 535 * Could be one 32-bit register or two 16-bit registers. 536 536 * A raw read will read the requested number of bytes. 537 537 */ 538 - regmap_raw_read(priv->dsp->regmap, 539 - xm + (offsetof(struct wmfw_adsp2_id_hdr, n_algs) / 2), 540 - &num_algs_be32, sizeof(num_algs_be32)); 538 + KUNIT_ASSERT_GE(priv->test, 0, 539 + regmap_raw_read(priv->dsp->regmap, 540 + xm + 541 + (offsetof(struct wmfw_adsp2_id_hdr, n_algs) / 2), 542 + &num_algs_be32, sizeof(num_algs_be32))); 541 543 num_algs = be32_to_cpu(num_algs_be32); 542 544 bytes = sizeof(struct wmfw_adsp2_id_hdr) + 543 545 (num_algs * sizeof(struct wmfw_adsp2_alg_hdr)) + ··· 548 546 regcache_drop_region(priv->dsp->regmap, xm, xm + (bytes / 2) - 1); 549 547 break; 550 548 case WMFW_HALO: 551 - regmap_read(priv->dsp->regmap, 552 - xm + offsetof(struct wmfw_halo_id_hdr, n_algs), 553 - &num_algs); 549 + KUNIT_ASSERT_GE(priv->test, 0, 550 + regmap_read(priv->dsp->regmap, 551 + xm + offsetof(struct wmfw_halo_id_hdr, n_algs), 552 + &num_algs)); 554 553 bytes = sizeof(struct wmfw_halo_id_hdr) + 555 554 (num_algs * sizeof(struct wmfw_halo_alg_hdr)) + 556 555 4 /* terminator word */;
+4
drivers/firmware/cirrus/test/cs_dsp_mock_wmfw.c
··· 178 178 size_t bytes_needed, name_len, description_len; 179 179 int offset; 180 180 181 + KUNIT_ASSERT_LE(builder->test_priv->test, alg_id, 0xffffff); 182 + 181 183 /* Bytes needed for region header */ 182 184 bytes_needed = offsetof(struct wmfw_region, data); 183 185 ··· 436 434 int format_version) 437 435 { 438 436 struct cs_dsp_mock_wmfw_builder *builder; 437 + 438 + KUNIT_ASSERT_LE(priv->test, format_version, 0xff); 439 439 440 440 /* If format version isn't given use the default for the target core */ 441 441 if (format_version < 0) {