control: use position offset macro of TLV data

A series of SNDRV_CTL_TLVO_XXX macro was introduced for position offset
of TLV data. This commit applies a code optimization.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Sakamoto 2018-05-15 21:36:35 +09:00 committed by Takashi Iwai
parent 5eb78219f6
commit f61193c96c
4 changed files with 51 additions and 40 deletions

View file

@ -240,11 +240,13 @@ static int snd_ctl_hw_elem_tlv(snd_ctl_t *handle, int op_flag,
return -errno;
}
if (op_flag == 0) {
if (xtlv->tlv[1] + 2 * sizeof(unsigned int) > tlv_size) {
unsigned int size;
size = xtlv->tlv[SNDRV_CTL_TLVO_LEN] + 2 * sizeof(unsigned int);
if (size > tlv_size) {
free(xtlv);
return -EFAULT;
}
memcpy(tlv, xtlv->tlv, xtlv->tlv[1] + 2 * sizeof(unsigned int));
memcpy(tlv, xtlv->tlv, size);
}
free(xtlv);
return 0;