From patchwork Tue Aug 22 13:43:03 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: 9915231 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 70DA7600C5 for ; Tue, 22 Aug 2017 13:43:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B33128793 for ; Tue, 22 Aug 2017 13:43:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FE982887E; Tue, 22 Aug 2017 13:43:20 +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 844EA28793 for ; Tue, 22 Aug 2017 13:43:19 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E3BBD266F6D; Tue, 22 Aug 2017 15:43:14 +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 2F47B266F78; Tue, 22 Aug 2017 15:43:13 +0200 (CEST) Received: from mout.web.de (mout.web.de [212.227.15.3]) by alsa0.perex.cz (Postfix) with ESMTP id 6D2AC266812 for ; Tue, 22 Aug 2017 15:43:11 +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 0LtFEp-1da9yd3bQZ-012n4Z; Tue, 22 Aug 2017 15:43:04 +0200 To: alsa-devel@alsa-project.org, Jaroslav Kysela , Julia Lawall , Takashi Iwai From: SF Markus Elfring Message-ID: Date: Tue, 22 Aug 2017 15:43:03 +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:EBMJ2pNff1pvCrLoHYGOCjw46i+obUPF8uOsURrMQCrDXGdIVD7 sqW72HdTGizXhPnyW8POkH0fRyFfhoNmV3d7UHVYDTXsBPpypUeClHDLSrae72NuuSWyEO5 q9n5hTWVHnEbyEBpnPizQoNVcwRKylLTXGFsI6V5T3xGk9vIX+GTHKClwTq5Dh1KgWmQaHx yZq2TiniFPQWcF2ckOkCQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:IAsnoihLXsY=:QHUp5JLGgQ6RFlcqAfyjzx Wq0okHN5CbfMIEycY5IAJs5BQwTcFgvwg5p8g9Wd8aA3VoEjKA04KqjKO9ai7W+x1NXGgkHm1 kI+tsTkPO+tRVb+EwIXk6t3s4c1kn2T6Z6aF+ckVHbQXJo86PwezaVcF5QnH/5Qi6fERIP+2E eT6G/QndhgQxigX8I5O/kt/jLXrRPk6LSA+xs4Y8oxiGheFLpmbfKGNtCNov6CCu7E7SeWgG9 2V15bPx175bqkLXU8/5eimw1Gb2aoGH/M2cB/1ADuqTXjjAHcIh+0uJWPl9BfPxYyF/AHmeeA ZhOJyp2AK5zkb481P6oeaKRWV+TnLX+uPOWxcpbgBXRsqqt28eFr2zOnuHc0OyvCc64J/9YsN yuCzhlXsb1C/9RDsDHv88PrIWhiEQrOno70GU7crs0hGAyKAQOKJTTqq5+dMtgMcuYdPA1JXt nqta3noXXXax4zAljASXOIJmVx+3sVLOYtXMdze51srHSiKS3Lf7FH6dihlj3y+17bk5deuue Qv9I3qk36IhiGKpNFD9GFh3LKzXTThXR209ZeUw9aO8yw+bTU/wgiT5nQRImKhM8ipTijGrJ9 U++9dqhFMXBn6g7fwfVKsoEhieeMTjpMm2AiwWRttzg05ZlW5hEIGdd+pbjhIcRNmq1JBeNjU VB72SZA1TCaA6rfickfOI/9M2TkyshtZnXBwsfGtug9sctMkJ85gEI3KEoa8WJWryscgr0lkj nCetLVYmRnrsFrdJnhP3Ow5qLdnQA8/1qfVgGst5dPP5Mhh3vYJ3QKnnyhQeMk20ThDlEaay6 tVDzswWjO9ip47thnpx0Li4U8udzndEkOPy2fvSau5TvC7EJVZnGmNBk+efPLmB1PRY7iBK Cc: kernel-janitors@vger.kernel.org, LKML Subject: [alsa-devel] [PATCH] ALSA: maestro3: 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 15:00:27 +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/pci/maestro3.c | 55 +++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c index cafea6dc5c01..759c3f6ad7aa 100644 --- a/sound/pci/maestro3.c +++ b/sound/pci/maestro3.c @@ -2622,22 +2622,18 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, err = request_firmware(&chip->assp_kernel_image, "ess/maestro3_assp_kernel.fw", &pci->dev); - if (err < 0) { - snd_m3_free(chip); - return err; - } + if (err) + goto free_chip; err = request_firmware(&chip->assp_minisrc_image, "ess/maestro3_assp_minisrc.fw", &pci->dev); - if (err < 0) { - snd_m3_free(chip); - return err; - } + if (err) + goto free_chip; + + err = pci_request_regions(pci, card->driver); + if (err) + goto free_chip; - if ((err = pci_request_regions(pci, card->driver)) < 0) { - snd_m3_free(chip); - return err; - } chip->iobase = pci_resource_start(pci, 0); /* just to be sure */ @@ -2655,8 +2651,8 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_m3_free(chip); - return -ENOMEM; + err = -ENOMEM; + goto free_chip; } chip->irq = pci->irq; @@ -2666,10 +2662,9 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, dev_warn(card->dev, "can't allocate apm buffer\n"); #endif - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { - snd_m3_free(chip); - return err; - } + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); + if (err) + goto free_chip; if ((err = snd_m3_mixer(chip)) < 0) return err; @@ -2699,6 +2694,9 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, *chip_ret = chip; return 0; +free_chip: + snd_m3_free(chip); + return err; } /* @@ -2741,23 +2739,19 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) break; } - if ((err = snd_m3_create(card, pci, - external_amp[dev], - amp_gpio[dev], - &chip)) < 0) { - snd_card_free(card); - return err; - } + err = snd_m3_create(card, pci, external_amp[dev], amp_gpio[dev], &chip); + if (err) + goto free_card; + card->private_data = chip; sprintf(card->shortname, "ESS %s PCI", card->driver); sprintf(card->longname, "%s at 0x%lx, irq %d", card->shortname, chip->iobase, chip->irq); - if ((err = snd_card_register(card)) < 0) { - snd_card_free(card); - return err; - } + err = snd_card_register(card); + if (err) + goto free_card; #if 0 /* TODO: not supported yet */ /* TODO enable MIDI IRQ and I/O */ @@ -2772,6 +2766,9 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) pci_set_drvdata(pci, card); dev++; return 0; +free_card: + snd_card_free(card); + return err; } static void snd_m3_remove(struct pci_dev *pci)