From patchwork Mon Sep 18 13:58:37 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: 9956785 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 A0DF2601E9 for ; Mon, 18 Sep 2017 13:59:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DBC628A44 for ; Mon, 18 Sep 2017 13:59:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8126728A23; Mon, 18 Sep 2017 13:59:54 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C11028A23 for ; Mon, 18 Sep 2017 13:59:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751861AbdIRN6p (ORCPT ); Mon, 18 Sep 2017 09:58:45 -0400 Received: from mout.web.de ([212.227.17.12]:52812 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751416AbdIRN6o (ORCPT ); Mon, 18 Sep 2017 09:58:44 -0400 Received: from [192.168.1.2] ([78.48.130.71]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MbQOe-1eANWU0bye-00Ijva; Mon, 18 Sep 2017 15:58:38 +0200 Subject: [PATCH 5/6] [media] go7007: Use common error handling code in go7007_snd_init() From: SF Markus Elfring To: linux-media@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab Cc: LKML , kernel-janitors@vger.kernel.org References: Message-ID: <05efac78-3a14-803c-5b4a-68670728628b@users.sourceforge.net> Date: Mon, 18 Sep 2017 15:58:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-GB X-Provags-ID: V03:K0:HcS+HrZwT7CyBhweFYbKt0GSgYc4Kw/IVNXqtpqIrO/voTMfGoy RbdwbD7vbh3JQASRowaiJ6iBeee9dT3cnVdRck1NPagwS1+fjNnQyPDX5/mus76Tvanc0UJ h+Go9SYUKl3UaeZ+1xggiaCzDGmnmXC+gGU6iBBRgDuRDPiIamcuVlTZ1JWvbJSEmKcbgxd 5vN8O1etHeTp+suYK3YgQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:qtqspPWbbkw=:S3wPFd+3Skxa7gxpCPckYI r3qdq8lJh5iH8Qy/WndMcz7BjlHsJDtFRPjeC3Yrup8RgdMrDG2iFJ2Sh9rpCTBxD2qfzBA8C 46ISVwr+ODxHnFv750QBjltsi/lWmuDkM/to3Q5Mdhi9+Zb2s7g5jWIIlV+i6SHfZrxsA7tub sSG790pUQrDcNGxYLnqcl08kGWXR4dOGJz38bqIKJqWAZ7Yum5Y+qYyDU0/cUezUmb1mUBu3C IrG4b0qnF8hF7mm5z1hNA8DyP5pjDwDCuzGiMofnTQoFgmuW0jlgNA+pXRUbDcFSZ3iQ8x/sW dx3Doo5dpSL/g7zEKCg994ELaYi8DDghRJj5+Pszv8ohJvCecTM0WKpQttCrFgQKH/10tRQ2c 4Lh8JugK16vleZnMG8MiOWXuuoxjY3M/De/ZEMCQD6jqNh35Owx7MJC8xNA02strnanKHKG5n HGV/B48R08/V0MVdAMe+jQarZ9cnnZYjO9ERqTGADUpXZJpNeIbY55vKYMbZ7zra0dL99oyiQ VrYieMnPBLD7BmiV7CmGhEE4A+KSCTqifG3hmk4kub42V561hys6HBb44eULhNW75ZmuQrg9O lt/P37QkYMKbQCyas+cI7VomhMw+ZDXL1h0eITBAA0M8eX3PjuUwYsbDj33ggsZBIi01aQhfO jURk+w988uRD5J3iFFTzYMC90kxN0ZhkPUVSQocFRz4DyCN+D4FTm0/S7GpC6ieEwR45eMD/D W2JcstilLdXnqZ2cdpCChDZXg8ZOq+4i0HSuWtS3lnA1aF6ryI4rgqrvtvszifhdFRWyJIySw xFKXFEj96l6qnwScDDFBLuOAj38jUFsDnURAfiEEvf6+R0fTKM= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Mon, 18 Sep 2017 14:28:59 +0200 Add jump targets so that a bit of exception handling can be better reused at the end of this function. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/media/usb/go7007/snd-go7007.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/media/usb/go7007/snd-go7007.c b/drivers/media/usb/go7007/snd-go7007.c index 68e421bf38e1..7ae4d03ed3f7 100644 --- a/drivers/media/usb/go7007/snd-go7007.c +++ b/drivers/media/usb/go7007/snd-go7007.c @@ -243,22 +243,18 @@ int go7007_snd_init(struct go7007 *go) gosnd->capturing = 0; ret = snd_card_new(go->dev, index[dev], id[dev], THIS_MODULE, 0, &gosnd->card); - if (ret < 0) { - kfree(gosnd); - return ret; - } + if (ret < 0) + goto free_snd; + ret = snd_device_new(gosnd->card, SNDRV_DEV_LOWLEVEL, go, &go7007_snd_device_ops); - if (ret < 0) { - kfree(gosnd); - return ret; - } + if (ret < 0) + goto free_snd; + ret = snd_pcm_new(gosnd->card, "go7007", 0, 0, 1, &gosnd->pcm); - if (ret < 0) { - snd_card_free(gosnd->card); - kfree(gosnd); - return ret; - } + if (ret < 0) + goto free_card; + strlcpy(gosnd->card->driver, "go7007", sizeof(gosnd->card->driver)); strlcpy(gosnd->card->shortname, go->name, sizeof(gosnd->card->driver)); strlcpy(gosnd->card->longname, gosnd->card->shortname, @@ -269,11 +265,8 @@ int go7007_snd_init(struct go7007 *go) &go7007_snd_capture_ops); ret = snd_card_register(gosnd->card); - if (ret < 0) { - snd_card_free(gosnd->card); - kfree(gosnd); - return ret; - } + if (ret < 0) + goto free_card; gosnd->substream = NULL; go->snd_context = gosnd; @@ -281,6 +274,12 @@ int go7007_snd_init(struct go7007 *go) ++dev; return 0; + +free_card: + snd_card_free(gosnd->card); +free_snd: + kfree(gosnd); + return ret; } EXPORT_SYMBOL(go7007_snd_init);