summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2021-12-17 13:02:13 +0000
committerTakashi Iwai <tiwai@suse.de>2021-12-25 09:13:28 +0100
commit10f2f194663af178f32aeb4086fc3f6687d25056 (patch)
tree2e433517e5bc68344a3f29c81a0850481fa5acf8 /tools
parent3f48b137d88e710b67b2bcc01aa3d77b4db610c4 (diff)
downloadlinux-10f2f194663af178f32aeb4086fc3f6687d25056.tar.bz2
kselftest: alsa: Validate values read from enumerations
Enumerations should return a value between 0 and items-1, check that this is the case. Signed-off-by: Mark Brown <broonie@kernel.org> Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com> Link: https://lore.kernel.org/r/20211217130213.3893415-3-broonie@kernel.org Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/alsa/mixer-test.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c
index b009fc5df605..17f158d7a767 100644
--- a/tools/testing/selftests/alsa/mixer-test.c
+++ b/tools/testing/selftests/alsa/mixer-test.c
@@ -276,6 +276,23 @@ bool ctl_value_index_valid(struct ctl_data *ctl, snd_ctl_elem_value_t *val,
}
break;
+ case SND_CTL_ELEM_TYPE_ENUMERATED:
+ int_val = snd_ctl_elem_value_get_enumerated(val, index);
+
+ if (int_val < 0) {
+ ksft_print_msg("%s.%d negative value %ld for enumeration\n",
+ ctl->name, index, int_val);
+ return false;
+ }
+
+ if (int_val >= snd_ctl_elem_info_get_items(ctl->info)) {
+ ksft_print_msg("%s.%d value %ld more than item count %ld\n",
+ ctl->name, index, int_val,
+ snd_ctl_elem_info_get_items(ctl->info));
+ return false;
+ }
+ break;
+
default:
/* No tests for other types */
break;