From patchwork Thu Jul 14 14:07:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 9229941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AB23760572 for ; Thu, 14 Jul 2016 14:24:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AB4127F94 for ; Thu, 14 Jul 2016 14:24:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F1FA281A7; Thu, 14 Jul 2016 14:24:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B0D427F94 for ; Thu, 14 Jul 2016 14:24:49 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 79AE9266EAF; Thu, 14 Jul 2016 16:24:48 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 9ABB42668AB; Thu, 14 Jul 2016 16:08:49 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0E6EF266893; Thu, 14 Jul 2016 16:08:48 +0200 (CEST) Received: from smtp-proxy003.phy.lolipop.jp (smtp-proxy003.phy.lolipop.jp [157.7.104.44]) by alsa0.perex.cz (Postfix) with ESMTP id B7788265AE8 for ; Thu, 14 Jul 2016 16:08:09 +0200 (CEST) Received: from smtp-proxy003.phy.lolipop.lan (HELO smtp-proxy003.phy.lolipop.jp) (172.19.44.44) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp-proxy003.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Thu, 14 Jul 2016 23:08:05 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp-proxy003.phy.lolipop.jp (LOLIPOP-Fsecure); Thu, 14 Jul 2016 23:07:52 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: tiwai@suse.de Date: Thu, 14 Jul 2016 23:07:37 +0900 Message-Id: <1468505271-5769-21-git-send-email-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468505271-5769-1-git-send-email-o-takashi@sakamocchi.jp> References: <1468505271-5769-1-git-send-email-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH 20/34] pcm: remove alloca() from softvol_load_control() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- src/pcm/pcm_softvol.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/pcm/pcm_softvol.c b/src/pcm/pcm_softvol.c index 4d2c62a..fc45d6d 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); } }