From patchwork Fri Jul 15 00:23:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 9230921 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 A1ABB6075D for ; Fri, 15 Jul 2016 00:34:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 929DB24B5E for ; Fri, 15 Jul 2016 00:34:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86C8828325; Fri, 15 Jul 2016 00:34:30 +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 C3F4E24B5E for ; Fri, 15 Jul 2016 00:34:29 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id DDB68266DC6; Fri, 15 Jul 2016 02:34:28 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D04942668AE; Fri, 15 Jul 2016 02:24:30 +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 4A8262668A7; Fri, 15 Jul 2016 02:24:30 +0200 (CEST) Received: from smtp-proxy002.phy.lolipop.jp (smtp-proxy002.phy.lolipop.jp [157.7.104.43]) by alsa0.perex.cz (Postfix) with ESMTP id 70D182666C5 for ; Fri, 15 Jul 2016 02:23:41 +0200 (CEST) Received: from smtp-proxy002.phy.lolipop.lan (HELO smtp-proxy002.phy.lolipop.jp) (172.19.44.43) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp-proxy002.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Fri, 15 Jul 2016 09:23:38 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp-proxy002.phy.lolipop.jp (LOLIPOP-Fsecure); Fri, 15 Jul 2016 09:23:34 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: tiwai@suse.de, perex@perex.cz Date: Fri, 15 Jul 2016 09:23:33 +0900 Message-Id: <1468542213-24880-30-git-send-email-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468542213-24880-1-git-send-email-o-takashi@sakamocchi.jp> References: <1468542213-24880-1-git-send-email-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH 29/29] mixer: remove alloca() from simple_event_add() 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 keep 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/mixer/simple_none.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c index 9b0705c..e129514 100644 --- a/src/mixer/simple_none.c +++ b/src/mixer/simple_none.c @@ -1610,23 +1610,22 @@ static int simple_event_add(snd_mixer_class_t *class, snd_hctl_elem_t *helem) if (snd_hctl_elem_get_interface(helem) != SND_CTL_ELEM_IFACE_MIXER) return 0; if (strcmp(name, "Capture Source") == 0) { - snd_ctl_elem_info_t *info; + snd_ctl_elem_info_t info = {0}; unsigned int k, items; int err; - snd_ctl_elem_info_alloca(&info); - err = snd_hctl_elem_info(helem, info); + err = snd_hctl_elem_info(helem, &info); assert(err >= 0); - if (snd_ctl_elem_info_get_type(info) != + if (snd_ctl_elem_info_get_type(&info) != SND_CTL_ELEM_TYPE_ENUMERATED) return 0; - items = snd_ctl_elem_info_get_items(info); + items = snd_ctl_elem_info_get_items(&info); for (k = 0; k < items; ++k) { const char *n; - snd_ctl_elem_info_set_item(info, k); - err = snd_hctl_elem_info(helem, info); + snd_ctl_elem_info_set_item(&info, k); + err = snd_hctl_elem_info(helem, &info); if (err < 0) return err; - n = snd_ctl_elem_info_get_item_name(info); + n = snd_ctl_elem_info_get_item_name(&info); err = simple_add1(class, n, helem, CTL_CAPTURE_SOURCE, k); if (err < 0)