From patchwork Sat Nov 18 15:33:04 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: 10064889 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 326D460230 for ; Sat, 18 Nov 2017 15:33:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2334E29FAC for ; Sat, 18 Nov 2017 15:33:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 165272A003; Sat, 18 Nov 2017 15:33:21 +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 3965829FAC for ; Sat, 18 Nov 2017 15:33:20 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id F17DE267358; Sat, 18 Nov 2017 16:33:18 +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 09B10267358; Sat, 18 Nov 2017 16:33:17 +0100 (CET) Received: from mout.web.de (mout.web.de [217.72.192.78]) by alsa0.perex.cz (Postfix) with ESMTP id 90D26267353 for ; Sat, 18 Nov 2017 16:33:13 +0100 (CET) Received: from [192.168.1.3] ([78.49.245.81]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0Lz3FM-1fBMaP3Tlo-014GWa; Sat, 18 Nov 2017 16:33:06 +0100 From: SF Markus Elfring To: alsa-devel@alsa-project.org, Bhumika Goyal , David Howells , Jaroslav Kysela , Takashi Iwai References: <663ac54c-baf9-ac11-50fd-d8b407d1eacf@users.sourceforge.net> Message-ID: <2aa5fdc3-de4d-54f2-2d3e-ae5e4f87153d@users.sourceforge.net> Date: Sat, 18 Nov 2017 16:33:04 +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: <663ac54c-baf9-ac11-50fd-d8b407d1eacf@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:jhUZewNTNQELtSlxTkYanFb9sGgvvMofejpQPDtV49KfAL4qM+y xcD6NOGiih/qDq+V6OtO1h5KcWjYjY6/2MV2ngwSJO7NvSRlzisJJ1c+FA3XPgIaFdRdLhZ g7A9MV5wjxyjPOLD+jHGDB8lBDVvE9ZoMimiIfH5bxA87Aqh4h8muybDdJrFfbanbFMjNWp iUNu4cLfhx3WCtVbj+t1w== X-UI-Out-Filterresults: notjunk:1; V01:K0:IcSRl6Zh+SI=:kMNOdZuJ0R7ZBIJFHtsXks AAECEkyNAHdBbtHdy2t9S0sh5TI8xTc9KlNED7Wt2BfF5xX3xcrvAlC6Z9Wna581jbi4lD85B Djxu9xI5QxkRpZiitGjHE3tCRiFbQ1DE/G/tAa5tWNLBz1RrFFxxe/I2ocpb+zkFd5YVnzFV2 cR13kkMQcgD1ZrRrC0atwPsTjN/pvJuVqZpAJN69B3oFueHY8eB3MIz3PZjqFF5Y3tiZtg+pM 66mPa/orua4e5tZxeHHzynMkvEqFxi3nv1SBZvilnNgCcfJwCoSK+FK9CtZ8Apo/5+Wiqc33T txUbx7nxpwsPx9rvGbL9Um152L+V9xFBKA3S1FwDtyb392/0qr1FKc+rYl3lcCy1KNl+4LhfI 1HgFyqhmTD2m0TwSDv8DdZdoE6j6/cPcU+aBj3owQEvzOITxCxbJ1bGFPnBIH58TcOfEwmhFe 4AFQ/UX7iu3CzuBTJRNuwP5hAfbt/zfOj2fvP+AEZPvQ0cG5w+D5E4jqIKkbCeGZvqaSTuunH 4DeTSzbTdyQ6vTXmKVlLkuxXwlo8609p5Kp0fgoQJXa4ZDyQzo6qJXXIwuEy+wK6ITfoCGKnO MJGHMNuUq/KWV6t1/N3tbcIQKq4NJxsWNLnMPxiO1S0edGLp09ArPhxpaUU+EB3jAR+BzJ1fQ 7Odb+U0N+QaZIV8PQH7QpmSNC/eoRaCYsZ+Yb6EUP/hnaBKhTaTiFJ9Na3BHBioJlsBiercR4 6ii/301lA+B1vPN9H68GevFJV79xbd76r+zHFb1yBYns6ALrKyDaxVLoJTCte0cvNj4R02lY3 UMW4n4+fQ/w9+De4fkWAwdO6i+/zwO2UsjK1PnV5hCqfV48Ia0= Cc: kernel-janitors@vger.kernel.org, LKML Subject: [alsa-devel] [PATCH 3/3] ALSA: sonicvibes: Use common error handling code in snd_sonicvibes_create() 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 16:12:12 +0100 Add jump targets so that a bit of exception handling can be better reused at the end of this function. Signed-off-by: Markus Elfring --- sound/pci/sonicvibes.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c index 75fc64839df0..c2147484c95d 100644 --- a/sound/pci/sonicvibes.c +++ b/sound/pci/sonicvibes.c @@ -1266,14 +1266,14 @@ static int snd_sonicvibes_create(struct snd_card *card, dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { dev_err(card->dev, "architecture does not support 24bit PCI busmaster DMA\n"); - pci_disable_device(pci); - return -ENXIO; + err = -ENXIO; + goto disable_device; } sonic = kzalloc(sizeof(*sonic), GFP_KERNEL); if (sonic == NULL) { - pci_disable_device(pci); - return -ENOMEM; + err = -ENOMEM; + goto disable_device; } spin_lock_init(&sonic->reg_lock); sonic->card = card; @@ -1283,8 +1283,7 @@ static int snd_sonicvibes_create(struct snd_card *card, err = pci_request_regions(pci, "S3 SonicVibes"); if (err < 0) { kfree(sonic); - pci_disable_device(pci); - return err; + goto disable_device; } sonic->sb_port = pci_resource_start(pci, 0); @@ -1296,8 +1295,7 @@ static int snd_sonicvibes_create(struct snd_card *card, if (request_irq(pci->irq, snd_sonicvibes_interrupt, IRQF_SHARED, KBUILD_MODNAME, sonic)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_sonicvibes_free(sonic); - return -EBUSY; + goto e_busy; } sonic->irq = pci->irq; @@ -1325,20 +1323,18 @@ static int snd_sonicvibes_create(struct snd_card *card, sonic->res_dmaa = request_region(dmaa, 0x10, "S3 SonicVibes DDMA-A"); if (!sonic->res_dmaa) { - snd_sonicvibes_free(sonic); dev_err(card->dev, "unable to grab DDMA-A port at 0x%x-0x%x\n", dmaa, dmaa + 0x10 - 1); - return -EBUSY; + goto e_busy; } sonic->res_dmac = request_region(dmac, 0x10, "S3 SonicVibes DDMA-C"); if (!sonic->res_dmac) { - snd_sonicvibes_free(sonic); dev_err(card->dev, "unable to grab DDMA-C port at 0x%x-0x%x\n", dmac, dmac + 0x10 - 1); - return -EBUSY; + goto e_busy; } pci_read_config_dword(pci, 0x40, &sonic->dmaa_port); @@ -1395,15 +1391,23 @@ static int snd_sonicvibes_create(struct snd_card *card, #endif sonic->revision = snd_sonicvibes_in(sonic, SV_IREG_REVISION); err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, sonic, &ops); - if (err < 0) { - snd_sonicvibes_free(sonic); - return err; - } + if (err < 0) + goto free_sound_chip; snd_sonicvibes_proc_init(sonic); *rsonic = sonic; return 0; + +disable_device: + pci_disable_device(pci); + return err; + +e_busy: + err = -EBUSY; +free_sound_chip: + snd_sonicvibes_free(sonic); + return err; } /*