From patchwork Thu Nov 16 21:28:11 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: 10062125 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 F03626023A for ; Thu, 16 Nov 2017 21:28:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E15B22AC08 for ; Thu, 16 Nov 2017 21:28:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D683D2AC0C; Thu, 16 Nov 2017 21:28:34 +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 297E32AC08 for ; Thu, 16 Nov 2017 21:28:34 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E8B812677A3; Thu, 16 Nov 2017 22:28:28 +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 3355E2677A5; Thu, 16 Nov 2017 22:28:28 +0100 (CET) Received: from mout.web.de (mout.web.de [212.227.17.12]) by alsa0.perex.cz (Postfix) with ESMTP id 9BCA126779C for ; Thu, 16 Nov 2017 22:28:26 +0100 (CET) Received: from [192.168.1.3] ([78.50.159.33]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MhleR-1ebFoG2utn-00Muyh; Thu, 16 Nov 2017 22:28:20 +0100 From: SF Markus Elfring To: alsa-devel@alsa-project.org, Arnd Bergmann , Bhumika Goyal , Jaroslav Kysela , Takashi Iwai References: Message-ID: <5860adfd-3357-68ba-5508-96fde59faf5f@users.sourceforge.net> Date: Thu, 16 Nov 2017 22:28:11 +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: Content-Language: en-GB X-Provags-ID: V03:K0:lDuWgmFW/jJNxBnzUog8agwWcKlpULKxfnzfTrNYXaJhizDUmwp 4m03dFtNVyRj1S2yfglvootbWz+errG8DJ3eglmksJeJT4JJkPLo4X5TZCuu5uBfUM+m602 YAjXW+9o1N5IOjmNWXnhgR0cKl6qyZk/7Yda5r1eOgtVVadIo2qzKoSbB7H2cEuVzlCLQAI O/iTrSeLztaCMwObDNeGg== X-UI-Out-Filterresults: notjunk:1; V01:K0:5QwX7jcpAfE=:W3sD44xwDTs0NY9pdgpfWS OF5nFNIlup+wqbINWrvs5LycESplzfHmkqvadE9cGpeyfG0Zye+hDkZyL5SsMe/ybzc5D+jL9 i7D6J2Q+bBJvR9IZfFEXnSODaKgsiMJj8D8OWIuHnzGu91eX/aTcHeJKCFr6glfee/ixcvPwj R7whtbM0alaeofzx6l582Ba3iryq4/ZY7+3x/cskeUeNgIxBhUf1NZK4ji/YMe7jSJSojvivz 8VYQoQ9h6sfZa/eQgg35VGa70h58psjhwlzcNQ33BdQkiUlkUVWLfRpXOKo88vOfmwelqD/Re 7Ax8OC7J7d8IywxwM4lDXt3R+sdkZyYy8yQ/6kKbu3JkcXRWXW+dYvlADWGv4zwfuiaL3N4LO vOHAEGjZygK1TeOOoWEfO47HPmUi6+AOahgAUGiK6X0BhtGqfACf8ZXT8eskoJwaprdaCNy84 NN+nnZuO/TF4lRni1NT/IvLPvbFdAjL1X6nRMOxDmCmBBES57L/YgNMf8wthswdZGPvg5kS9A LV7jSljQJur3IbHex98W9/msPZk2/KDbbtetDi1H+z5Wb5norGd9nt9l2rgdoWd2wqCzwddos JaP+XujqgaTTz+V8bvr0roDIfmOm1UGOuqITWjwoiOn0Cgaw88XV3ViZGQVIVN7t6Qasa+VgR j2r+RmL0rPThElYNj/T4Wa6+qD8C8UAlVIAQb5VdwGa5wbRNTHkLh6hZU3Qllq8LfrjGJ9QA1 EpEiC/EMaz1leoGvckXGVr/uhQWa/xfrpX4rvG2mHI57ex9/SuWJjGiN/zHO3T6HCLWL4GB7o kXAtiWsnhwqT0/9XBz7uGZPbYyO1knPx+HuDCtZymMNw+bWCrE= Cc: kernel-janitors@vger.kernel.org, LKML Subject: [alsa-devel] [PATCH 2/2] ALSA: pcxhr: Use common error handling code in pcxhr_probe() 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: Thu, 16 Nov 2017 22:11:52 +0100 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 --- sound/pci/pcxhr/pcxhr.c | 62 ++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c index c490d7e57ff7..f05c6a042890 100644 --- a/sound/pci/pcxhr/pcxhr.c +++ b/sound/pci/pcxhr/pcxhr.c @@ -1541,21 +1541,21 @@ static int pcxhr_probe(struct pci_dev *pci, if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { dev_err(&pci->dev, "architecture does not support 32bit PCI busmaster DMA\n"); - pci_disable_device(pci); - return -ENXIO; + err = -ENXIO; + goto disable_device; } /* alloc card manager */ mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); - if (! mgr) { - pci_disable_device(pci); - return -ENOMEM; + if (!mgr) { + err = -ENOMEM; + goto disable_device; } if (snd_BUG_ON(pci_id->driver_data >= PCI_ID_LAST)) { kfree(mgr); - pci_disable_device(pci); - return -ENODEV; + err = -ENODEV; + goto disable_device; } card_name = pcxhr_board_params[pci_id->driver_data].board_name; @@ -1581,8 +1581,7 @@ static int pcxhr_probe(struct pci_dev *pci, err = pci_request_regions(pci, card_name); if (err < 0) { kfree(mgr); - pci_disable_device(pci); - return err; + goto disable_device; } for (i = 0; i < 3; i++) mgr->port[i] = pci_resource_start(pci, i); @@ -1594,8 +1593,8 @@ static int pcxhr_probe(struct pci_dev *pci, pcxhr_threaded_irq, IRQF_SHARED, KBUILD_MODNAME, mgr)) { dev_err(&pci->dev, "unable to grab IRQ %d\n", pci->irq); - pcxhr_free(mgr); - return -EBUSY; + err = -EBUSY; + goto free_manager; } mgr->irq = pci->irq; @@ -1614,10 +1613,8 @@ static int pcxhr_probe(struct pci_dev *pci, sizeof(u32) * (PCXHR_SIZE_MAX_LONG_STATUS - PCXHR_SIZE_MAX_STATUS), GFP_KERNEL); - if (! mgr->prmh) { - pcxhr_free(mgr); - return -ENOMEM; - } + if (!mgr->prmh) + goto e_nomem; for (i=0; i < PCXHR_MAX_CARDS; i++) { struct snd_card *card; @@ -1640,8 +1637,7 @@ static int pcxhr_probe(struct pci_dev *pci, if (err < 0) { dev_err(&pci->dev, "cannot allocate the card %d\n", i); - pcxhr_free(mgr); - return err; + goto free_manager; } strcpy(card->driver, DRIVER_NAME); @@ -1653,8 +1649,7 @@ static int pcxhr_probe(struct pci_dev *pci, err = pcxhr_create(mgr, card, i); if (err < 0) { snd_card_free(card); - pcxhr_free(mgr); - return err; + goto free_manager; } if (i == 0) @@ -1662,32 +1657,37 @@ static int pcxhr_probe(struct pci_dev *pci, pcxhr_proc_init(mgr->chip[i]); err = snd_card_register(card); - if (err < 0) { - pcxhr_free(mgr); - return err; - } + if (err < 0) + goto free_manager; } /* create hostport purgebuffer */ size = PAGE_ALIGN(sizeof(struct pcxhr_hostport)); if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), - size, &mgr->hostport) < 0) { - pcxhr_free(mgr); - return -ENOMEM; - } + size, &mgr->hostport) < 0) + goto e_nomem; + /* init purgebuffer */ memset(mgr->hostport.area, 0, size); /* create a DSP loader */ err = pcxhr_setup_firmware(mgr); - if (err < 0) { - pcxhr_free(mgr); - return err; - } + if (err < 0) + goto free_manager; pci_set_drvdata(pci, mgr); dev++; return 0; + +disable_device: + pci_disable_device(pci); + return err; + +e_nomem: + err = -ENOMEM; +free_manager: + pcxhr_free(mgr); + return err; } static void pcxhr_remove(struct pci_dev *pci)