From patchwork Tue Aug 22 19:12:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9915951 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 8532860381 for ; Tue, 22 Aug 2017 19:12:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C2B628921 for ; Tue, 22 Aug 2017 19:12:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70DB32892D; Tue, 22 Aug 2017 19:12:29 +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 8E7AA28928 for ; Tue, 22 Aug 2017 19:12:28 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D35EE267019; Tue, 22 Aug 2017 21:12:26 +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 5FD7D267022; Tue, 22 Aug 2017 21:12:25 +0200 (CEST) Received: from mout.web.de (mout.web.de [212.227.15.4]) by alsa0.perex.cz (Postfix) with ESMTP id B5219266998 for ; Tue, 22 Aug 2017 21:12:21 +0200 (CEST) Received: from [192.168.1.2] ([77.181.75.183]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LqlAw-1d745v1Q94-00eORf; Tue, 22 Aug 2017 21:12:05 +0200 To: alsa-devel@alsa-project.org, Arnd Bergmann , Arvind Yadav , Dan Carpenter , Ingo Molnar , Jaroslav Kysela , Takashi Iwai , Takashi Sakamoto , Vegard Nossum From: SF Markus Elfring Message-ID: Date: Tue, 22 Aug 2017 21:12:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:6dTCj5MtGSpGCzxrr+M5MLECBrwMaF1CWC1dDH8t07sqyCImn0L mziM/e9TENarwZKfo4iNhLPWkgdef3wKukI81GN5lUqNRWVzLCF2ik7JNBLcaD90dvoDPXV b0PzaXPmcyMfgobNBHAO4AuNodElSIKeXY1e5eudiFSPhOIOWFDXoWhx+gkhWFoKqMO1nS2 ljsbPXIG5YDcIZWlsJ6pg== X-UI-Out-Filterresults: notjunk:1; V01:K0:/6Ox97Xzl5I=:3481e3BSEa5UhI9n3/FHwi fKrHQFmOg9RiEha34YvYiQzR8BtP3cMIWW0dBVZzANtyEx9SPBcL0ele5crz7utD9G2bcMaY2 ElVP3nebvhbziTe+skhTcSlTic2bOBJAU+vOEngjYb1bL0MM19VKpyrG6FRMbzf8OnaykxR5E YsOz9vqlqPbzQCm7QHA2cSwi3Q8eBRg99dTlWoVK33evjppqWZnTS3iKDM7oUzVrHQG704nGk nHYzDqjpSjBWgma4ypE/2jEcHTQK6M0cdkYptbNbUI9hNX3n6yQaJUam1KKJLo9UIvIRyCl2V 4OeBogDow4j55eMBBUNlsu5MyHRL/yIGmCMqXdPHI5CtsTYVaQX9sWTRGqry7gNVZzb4X3f1c EI43AZI0fVVIBwXU5sOFCjI1CnkE7hBkBROp7y75ZuaHDEhCvTkxBTbNT/Hubzlem08OgY/aX GexnJe0//mgoaBuUEPlSv+ClGeLXigsIZHxcacvq0uc819RsvDItAGjtos3CJ2Maml54LIUJj qpQzP5ZiB87YiiWMJWccjidCPgtWRUI2MxHiqywDF1DR3rOU0PtaGKTiGaXby+6GnioeSLiBj VRUoULeWLvBMU6bhwRvChOLORP+UlP2azIyT4ZIL9LEbJophuAYO983dXFkfoPgYYx076Qmq3 GRH8NrkpB/7rsRx7XARFQZQgEUgLWiggIQk9LN39y8YUNUJ0g/BQ8NuIixpQKF/v4Mk48+1BM MaVnAMvIRtNzHmCGkzZFGvThxWnNoVqXLTuY4N5BwpqKrY3yod8pNPWOpqjNe8EAnw4qYKgoj 4UA+l7qN/WXb9YBPYFYYwYI3nvD/rEDaSbvwPMYpBQjMX/he7q2oBL57w+vzwz25+a3twNM Cc: kernel-janitors@vger.kernel.org, LKML Subject: [alsa-devel] [PATCH] ALSA: core: Use common error handling code in two functions 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Tue, 22 Aug 2017 21:01:01 +0200 Add jump targets so that a bit of exception handling can be better reused at the end of these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- sound/core/pcm.c | 30 ++++++++++++++++++------------ sound/core/timer.c | 10 ++++++---- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 89c7485519cb..048df9658f50 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -783,21 +783,27 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device, INIT_LIST_HEAD(&pcm->list); if (id) strlcpy(pcm->id, id, sizeof(pcm->id)); - if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) { - snd_pcm_free(pcm); - return err; - } - if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) { - snd_pcm_free(pcm); - return err; - } - if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) { - snd_pcm_free(pcm); - return err; - } + + err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, + playback_count); + if (err < 0) + goto free_pcm; + + err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count); + if (err < 0) + goto free_pcm; + + err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops); + if (err < 0) + goto free_pcm; + if (rpcm) *rpcm = pcm; return 0; + +free_pcm: + snd_pcm_free(pcm); + return err; } /** diff --git a/sound/core/timer.c b/sound/core/timer.c index a9b9a277e00c..6d73a63f6e2b 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -2096,8 +2096,7 @@ static int __init alsa_timer_init(void) err = snd_timer_register_system(); if (err < 0) { pr_err("ALSA: unable to register system timer (%i)\n", err); - put_device(&timer_dev); - return err; + goto put_timer; } err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0, @@ -2105,12 +2104,15 @@ static int __init alsa_timer_init(void) if (err < 0) { pr_err("ALSA: unable to register timer device (%i)\n", err); snd_timer_free_all(); - put_device(&timer_dev); - return err; + goto put_timer; } snd_timer_proc_init(); return 0; + +put_timer: + put_device(&timer_dev); + return err; } static void __exit alsa_timer_exit(void)