summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2016-07-14 23:07:37 +0900
committerTakashi Iwai <tiwai@suse.de>2016-07-14 16:33:50 +0200
commit349920f93dc6e8be54e0fa21a0b2a31a412ccc1e (patch)
treeae0509ed21b42b5c97683b7e8c85913b18d2a458
parent8306bb2b6a68c2fdfa406ac07091309e8e65041c (diff)
downloadalsa-lib-349920f93dc6e8be54e0fa21a0b2a31a412ccc1e.tar.gz
pcm: remove alloca() from softvol_load_control()
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures. This commit obsolete usages of alloca() with automatic variables. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--src/pcm/pcm_softvol.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/pcm/pcm_softvol.c b/src/pcm/pcm_softvol.c
index 4d2c62a2..fc45d6db 100644
--- a/src/pcm/pcm_softvol.c
+++ b/src/pcm/pcm_softvol.c
@@ -702,17 +702,16 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol,
int resolution)
{
char tmp_name[32];
- snd_pcm_info_t *info;
- snd_ctl_elem_info_t *cinfo;
+ snd_pcm_info_t info = {0};
+ snd_ctl_elem_info_t cinfo = {0};
int err;
unsigned int i;
if (ctl_card < 0) {
- snd_pcm_info_alloca(&info);
- err = snd_pcm_info(pcm, info);
+ err = snd_pcm_info(pcm, &info);
if (err < 0)
return err;
- ctl_card = snd_pcm_info_get_card(info);
+ ctl_card = snd_pcm_info_get_card(&info);
if (ctl_card < 0) {
SNDERR("No card defined for softvol control");
return -EINVAL;
@@ -737,46 +736,45 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol,
svol->zero_dB_val = (min_dB / (min_dB - max_dB)) *
svol->max_val;
- snd_ctl_elem_info_alloca(&cinfo);
- snd_ctl_elem_info_set_id(cinfo, ctl_id);
- if ((err = snd_ctl_elem_info(svol->ctl, cinfo)) < 0) {
+ snd_ctl_elem_info_set_id(&cinfo, ctl_id);
+ if ((err = snd_ctl_elem_info(svol->ctl, &cinfo)) < 0) {
if (err != -ENOENT) {
SNDERR("Cannot get info for CTL %s", tmp_name);
return err;
}
- err = add_user_ctl(svol, cinfo, cchannels);
+ err = add_user_ctl(svol, &cinfo, cchannels);
if (err < 0) {
SNDERR("Cannot add a control");
return err;
}
} else {
- if (! (cinfo->access & SNDRV_CTL_ELEM_ACCESS_USER)) {
+ if (! (cinfo.access & SNDRV_CTL_ELEM_ACCESS_USER)) {
/* hardware control exists */
return 1; /* notify */
- } else if ((cinfo->type != SND_CTL_ELEM_TYPE_INTEGER &&
- cinfo->type != SND_CTL_ELEM_TYPE_BOOLEAN) ||
- cinfo->count != (unsigned int)cchannels ||
- cinfo->value.integer.min != 0 ||
- cinfo->value.integer.max != resolution - 1) {
- err = snd_ctl_elem_remove(svol->ctl, &cinfo->id);
+ } else if ((cinfo.type != SND_CTL_ELEM_TYPE_INTEGER &&
+ cinfo.type != SND_CTL_ELEM_TYPE_BOOLEAN) ||
+ cinfo.count != (unsigned int)cchannels ||
+ cinfo.value.integer.min != 0 ||
+ cinfo.value.integer.max != resolution - 1) {
+ err = snd_ctl_elem_remove(svol->ctl, &cinfo.id);
if (err < 0) {
SNDERR("Control %s mismatch", tmp_name);
return err;
}
/* reset numid */
- snd_ctl_elem_info_set_id(cinfo, ctl_id);
- if ((err = add_user_ctl(svol, cinfo, cchannels)) < 0) {
+ snd_ctl_elem_info_set_id(&cinfo, ctl_id);
+ if ((err = add_user_ctl(svol, &cinfo, cchannels)) < 0) {
SNDERR("Cannot add a control");
return err;
}
} else if (svol->max_val > 1) {
/* check TLV availability */
unsigned int tlv[4];
- err = snd_ctl_elem_tlv_read(svol->ctl, &cinfo->id, tlv,
+ err = snd_ctl_elem_tlv_read(svol->ctl, &cinfo.id, tlv,
sizeof(tlv));
if (err < 0)
- add_tlv_info(svol, cinfo);
+ add_tlv_info(svol, &cinfo);
}
}