ctl: use automatic variable instead of call of alloca(3)

Inner this library, layouts of all structures are public. At a compilation
time, each size of the structures can be calculated. It means that we can
use automatic variable instead of calling alloca(3) to program this
library because in both ways storages are kept on stack frame of process
VMA. Besides, the usage of automatic variables requires less instructions
than calls of alloca(3). Furthermore, alloca(3) is not described in any
C language standards.

This commit replaces calls of alloca(3) just for structures with automatic
variables, for control features.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Sakamoto 2016-06-27 23:37:36 +09:00 committed by Takashi Iwai
parent 7bc886584f
commit 06a51e29f4
5 changed files with 122 additions and 140 deletions

View file

@ -409,20 +409,19 @@ struct tlv_info {
static int get_tlv_info(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
struct tlv_info *rec)
{
snd_ctl_elem_info_t *info;
snd_ctl_elem_info_t info = {0};
int err;
snd_ctl_elem_info_alloca(&info);
snd_ctl_elem_info_set_id(info, id);
err = snd_ctl_elem_info(ctl, info);
snd_ctl_elem_info_set_id(&info, id);
err = snd_ctl_elem_info(ctl, &info);
if (err < 0)
return err;
if (!snd_ctl_elem_info_is_tlv_readable(info))
if (!snd_ctl_elem_info_is_tlv_readable(&info))
return -EINVAL;
if (snd_ctl_elem_info_get_type(info) != SND_CTL_ELEM_TYPE_INTEGER)
if (snd_ctl_elem_info_get_type(&info) != SND_CTL_ELEM_TYPE_INTEGER)
return -EINVAL;
rec->minval = snd_ctl_elem_info_get_min(info);
rec->maxval = snd_ctl_elem_info_get_max(info);
rec->minval = snd_ctl_elem_info_get_min(&info);
rec->maxval = snd_ctl_elem_info_get_max(&info);
err = snd_ctl_elem_tlv_read(ctl, id, rec->buf, sizeof(rec->buf));
if (err < 0)
return err;