Skip to content

Commit

Permalink
kselftest: alsa: Validate values read from enumerations
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Mark Brown authored and Takashi Iwai committed Dec 25, 2021
1 parent 3f48b13 commit 10f2f19
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/testing/selftests/alsa/mixer-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 10f2f19

Please sign in to comment.