From patchwork Thu Jul 14 14:07:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 9229907 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 00C686075D for ; Thu, 14 Jul 2016 14:19:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E563F2808C for ; Thu, 14 Jul 2016 14:19:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA6C1281A7; Thu, 14 Jul 2016 14:19:00 +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 CF9122808C for ; Thu, 14 Jul 2016 14:18:59 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 9EB68266CB0; Thu, 14 Jul 2016 16:18:58 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 736F5266836; Thu, 14 Jul 2016 16:08:38 +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 A6BE02659EF; Thu, 14 Jul 2016 16:08:34 +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 4B7EF2659FE 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:06 +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:44 +0900 Message-Id: <1468505271-5769-28-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 27/34] conf: remove alloca() from snd_func_pcm_args_by_class() 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/confmisc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/confmisc.c b/src/confmisc.c index 2275ccd..99be48b 100644 --- a/src/confmisc.c +++ b/src/confmisc.c @@ -1053,7 +1053,7 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi { snd_config_t *n; snd_ctl_t *ctl = NULL; - snd_pcm_info_t *info; + snd_pcm_info_t info = {0}; const char *id; int card = -1, dev; long class, index; @@ -1091,7 +1091,6 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi goto __out; } - snd_pcm_info_alloca(&info); while(1) { err = snd_card_next(&card); if (err < 0) { @@ -1106,7 +1105,6 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi goto __out; } dev = -1; - memset(info, 0, snd_pcm_info_sizeof()); while(1) { err = snd_ctl_pcm_next_device(ctl, &dev); if (err < 0) { @@ -1115,11 +1113,11 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi } if (dev < 0) break; - snd_pcm_info_set_device(info, dev); - err = snd_ctl_pcm_info(ctl, info); + snd_pcm_info_set_device(&info, dev); + err = snd_ctl_pcm_info(ctl, &info); if (err < 0) continue; - if (snd_pcm_info_get_class(info) == (snd_pcm_class_t)class && + if (snd_pcm_info_get_class(&info) == (snd_pcm_class_t)class && index == idx++) goto __out; }