From patchwork Sat Nov 18 19:12:33 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: 10064921 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 7FFA1602B8 for ; Sat, 18 Nov 2017 19:12:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 705AB29CA7 for ; Sat, 18 Nov 2017 19:12:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 654A129CB1; Sat, 18 Nov 2017 19:12:45 +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 745D129CA7 for ; Sat, 18 Nov 2017 19:12:44 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 57C9626739A; Sat, 18 Nov 2017 20:12:43 +0100 (CET) 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 07F6926739D; Sat, 18 Nov 2017 20:12:42 +0100 (CET) Received: from mout.web.de (mout.web.de [217.72.192.78]) by alsa0.perex.cz (Postfix) with ESMTP id 66FF7266EFA for ; Sat, 18 Nov 2017 20:12:39 +0100 (CET) Received: from [192.168.1.3] ([78.49.245.81]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LiCsx-1euTMf2qax-00nSiV; Sat, 18 Nov 2017 20:12:34 +0100 From: SF Markus Elfring To: alsa-devel@alsa-project.org, Arvind Yadav , Bhumika Goyal , Jaroslav Kysela , Takashi Iwai References: <498d6d73-2c62-178a-3c7a-b0fcb092d81e@users.sourceforge.net> Message-ID: <5fc2dcb3-3016-5a0a-62f4-5e873252677e@users.sourceforge.net> Date: Sat, 18 Nov 2017 20:12:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <498d6d73-2c62-178a-3c7a-b0fcb092d81e@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:wHseWI8BEi+U/1NIizPOJpVsELLGzezcHK2CjUku6Nq3YZ3yj46 QJ1vnZXopby/ijuZs+P8+xHRxaFh53yETxFr+zCk5lIBdFxXXoge/3971BafzfMuiUwN8bq dlbuYL6Osn+G/WkvJbpMlVnmF0ATqNj1DMBIYkJDEvEWXgIlyCVIWdvVbJpEtiv0UdNQkx4 CWcrTS68nd420oOXuFsfg== X-UI-Out-Filterresults: notjunk:1; V01:K0:pjhMZCY3evE=:YW5AKQRt5QSTNLvuOnEZOd dac7HJTBbfyhJ6eRd6hcna1vfKK0wv2OIoNQPvIOxNsWZdTk+/fQdzy3EEdFKMafrS8QNJa0u vLfHNtkY4GnK0sbzVtQyrbbIbvIJ3SfkylPH+pwk6cTCnMGMkPPR4NcDpSITvyTQqUWTIK6HD mwez8RAPjr9I1dHYYbxj72zRhaDTPQhC9coGQH3ExbwqLfAhVhJctoHqEp+3PM2wIIBviPAUg cUYGac3sD5W2bTPhU5r8gFlvFVC4lJVUTElKGQCnDPuqb5pw9BXZT065dG8GlndfEF420Hpnl db9yzbJoZKESwL+G14tscDI1LNEF/rry4ERsApUadDm0uuSdwiALIKrjqrrLs3k3besHV4KMb UWvnwXX+sXnTgflImSz8WjyBW+aDmzB1tmuUddgmQnqdnPYlaYN+/dhPKghAK8rAQ96n7iiAW XI0HGrvG0N+K7FihuOMroVYrOmCsHZhLq1YcnP7vFHUr267EPoojIrs4y7W/FfnQ+oME18amT qbEVC7eON9e2AGt9uWSt9kZK2GTrqgt+NK1h8ylY0wyg1MAmvgGWZGv5Sd9++YgWiEF6BeDQ1 l3uAbwcmonaNuMq+aqogaIQwEtQKoavE8+9i02KVhwtCFiY+VxhDkT7Kn9O/u7//cSOS/oOsN YfFQ7ynXhaUHR2EvnhcSEUKDWPm5rEi9SPp1QixkCZgQn6TNBe4fxIVGia4gWWc2qIJ3mztB9 QKYpyrpvjQkplWY4VQmDut6wmfUCT9v99SAlhRfiXIb269FO9UeGdZ4Fs1JGok9HC593wYxaB hiuT8qAdKqQ3ksnQWHDORUpCPyeTEwpPSr/4l+i4d39OFE+Vew= Cc: kernel-janitors@vger.kernel.org, LKML Subject: [alsa-devel] [PATCH 2/3] ALSA: trident: 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: Sat, 18 Nov 2017 19:29:35 +0100 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/pci/trident/trident.c | 54 +++++++++++++++++++--------------------- sound/pci/trident/trident_main.c | 41 +++++++++++++++--------------- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c index fd35f7826845..830402c32395 100644 --- a/sound/pci/trident/trident.c +++ b/sound/pci/trident/trident.c @@ -100,10 +100,9 @@ static int snd_trident_probe(struct pci_dev *pci, == TRIDENT_DEVICE_ID_SI7018 ? 1 : 2, wavetable_size[dev], &trident); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + card->private_data = trident; switch (trident->device) { @@ -130,47 +129,46 @@ static int snd_trident_probe(struct pci_dev *pci, card->shortname, trident->port, trident->irq); err = snd_trident_pcm(trident, pcm_dev++); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + switch (trident->device) { case TRIDENT_DEVICE_ID_DX: case TRIDENT_DEVICE_ID_NX: err = snd_trident_foldback_pcm(trident, pcm_dev++); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; break; } if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) { err = snd_trident_spdif_pcm(trident, pcm_dev++); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; } - if (trident->device != TRIDENT_DEVICE_ID_SI7018 && - (err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE, - trident->midi_port, - MPU401_INFO_INTEGRATED | - MPU401_INFO_IRQ_HOOK, - -1, &trident->rmidi)) < 0) { - snd_card_free(card); - return err; + + if (trident->device != TRIDENT_DEVICE_ID_SI7018) { + err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE, + trident->midi_port, + MPU401_INFO_INTEGRATED | + MPU401_INFO_IRQ_HOOK, + -1, &trident->rmidi); + if (err < 0) + goto free_card; } snd_trident_create_gameport(trident); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + pci_set_drvdata(pci, card); dev++; return 0; + +free_card: + snd_card_free(card); + return err; } static void snd_trident_remove(struct pci_dev *pci) diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c index 88d666cb3300..9843a61a8ead 100644 --- a/sound/pci/trident/trident_main.c +++ b/sound/pci/trident/trident_main.c @@ -3587,14 +3587,14 @@ int snd_trident_create(struct snd_card *card, dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(30)) < 0) { dev_err(card->dev, "architecture does not support 30bit PCI busmaster DMA\n"); - pci_disable_device(pci); - return -ENXIO; + err = -ENXIO; + goto disable_device; } trident = kzalloc(sizeof(*trident), GFP_KERNEL); if (trident == NULL) { - pci_disable_device(pci); - return -ENOMEM; + err = -ENOMEM; + goto disable_device; } trident->device = (pci->vendor << 16) | pci->device; trident->card = card; @@ -3617,16 +3617,15 @@ int snd_trident_create(struct snd_card *card, err = pci_request_regions(pci, "Trident Audio"); if (err < 0) { kfree(trident); - pci_disable_device(pci); - return err; + goto disable_device; } trident->port = pci_resource_start(pci, 0); if (request_irq(pci->irq, snd_trident_interrupt, IRQF_SHARED, KBUILD_MODNAME, trident)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_trident_free(trident); - return -EBUSY; + err = -EBUSY; + goto free_sound_chip; } trident->irq = pci->irq; @@ -3635,10 +3634,8 @@ int snd_trident_create(struct snd_card *card, trident->tlb.buffer.area = NULL; if (trident->device == TRIDENT_DEVICE_ID_NX) { err = snd_trident_tlb_alloc(trident); - if (err < 0) { - snd_trident_free(trident); - return err; - } + if (err < 0) + goto free_sound_chip; } trident->spdif_bits = trident->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF; @@ -3658,16 +3655,12 @@ int snd_trident_create(struct snd_card *card, snd_BUG(); break; } - if (err < 0) { - snd_trident_free(trident); - return err; - } + if (err < 0) + goto free_sound_chip; err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, trident, &ops); - if (err < 0) { - snd_trident_free(trident); - return err; - } + if (err < 0) + goto free_sound_chip; err = snd_trident_mixer(trident, pcm_spdif_device); if (err < 0) @@ -3693,6 +3686,14 @@ int snd_trident_create(struct snd_card *card, snd_trident_proc_init(trident); *rtrident = trident; return 0; + +disable_device: + pci_disable_device(pci); + return err; + +free_sound_chip: + snd_trident_free(trident); + return err; } /*---------------------------------------------------------------------------