From patchwork Mon Nov 13 21:02:05 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: 10056679 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 6629160365 for ; Mon, 13 Nov 2017 21:02:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 572EB29613 for ; Mon, 13 Nov 2017 21:02:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BF1929620; Mon, 13 Nov 2017 21:02:28 +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 0CD3F29613 for ; Mon, 13 Nov 2017 21:02:26 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B822A267426; Mon, 13 Nov 2017 22:02:24 +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 ADC73267428; Mon, 13 Nov 2017 22:02:22 +0100 (CET) Received: from mout.web.de (mout.web.de [217.72.192.78]) by alsa0.perex.cz (Postfix) with ESMTP id D9AD3267422 for ; Mon, 13 Nov 2017 22:02:18 +0100 (CET) Received: from [192.168.1.3] ([92.228.193.202]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LfAsW-1eyjJR2uG8-00oqqZ; Mon, 13 Nov 2017 22:02:09 +0100 To: alsa-devel@alsa-project.org, Arvind Yadav , Bhumika Goyal , Jaroslav Kysela , Takashi Iwai , Takashi Sakamoto From: SF Markus Elfring Message-ID: <1780a481-5400-16db-8f09-26a4b6127c90@users.sourceforge.net> Date: Mon, 13 Nov 2017 22:02:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:zl0Q0272qNs0MliQweILL3TyHygRzvCAKw/kB+SBKofnRXtlH62 DDwlST9QE/ds9b5vx7d3mO54ZoWLL9NGdaXTj+iw3lWB84YGA4+7HNBKSNwdxfyYz0UJCXZ Rvl7bi4+G9N2GOckwyJnfH3hMVRR63Aw5cDVBLva4CPPNVMqTL0IBsAoNxubfuqqZ7/rwT0 f8apHxyQCJtZwrZvwWaEQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:jsoV/Ieghnc=:BTAK1G38FZykkMyosLd7Xg shldPMrNyTp+kRs4q/skPbXYHujolJQvGFhDrahpiLQLyf/Fj5mfQslTvKF+Z0cjif0dTjUID r0ODA/pVtCUbLaMoJQEf8YvB9iUPZmwyjzIuSnX29R6sPch9HO6ujRP6Q0Pg0mfppUp+ineC3 IOu+jnYJhYfbtBdRf7dhbsNe2CzzZ1Id1uD9zK03no+wLGioWSNX0SkbQy+6NNBBVi60Fz/Hj W7kEC5LR3/di5iJSJjIADsI6uFqC8+B3OU6jdZUrS1f4ZhiKFo3s6po7KCR1o1nnGOmp4eCOH f+p79RaLiXU6gSm6MoNZ2tx65BsJxxdN31TyXfd25H0mkx7gaXAaiGte4J38SUfbxkCNMFcjO ALkysUURzK9asaO0qRiuFzKF+FAp9GgUcP1C2evI81cAEK9AorFRvar6wvYxYTL8gQU/RotF9 zM8FrSRBy3aJ51obp5a44dEBIfoE0FjTj7js7SGmXHlj9DxnvILnCxWSQIQODPCcCBAMbiJnR GgwIcXY/NmgeK5V2JqjNDeYTYeJs5LlIdktFa4TUusRhmO1Jab7v/1qFS4dyNfHU6hjXx60oi qIh+SrnZVOJLqjfqjIsPOLMAEnuBSf+RnQ+jFDXFdbgi3KJAPCNWUFFB/1zaLF1kvMkl9ZBEj BvYxIj8tzix3u3n9VCWma6RV8uCTUvRXMGcr32Q5HYELEb1pV6z05trLCHFvU42RQhY1ETH63 7o0Sf4S7l69h6g+7Ootus4a6HGFoXeNIkb+pHAoDcLaWBlFTp643gNYahO+gy+uQosekb7cAN 4T3aqjnMEa0k4Jh5kKzgk8snZOOArVMEUykkFMehvJg9jJfcxM= Cc: kernel-janitors@vger.kernel.org, LKML Subject: [alsa-devel] [PATCH] ALSA: echoaudio: 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: Mon, 13 Nov 2017 21:57:57 +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. * The script "checkpatch.pl" pointed information out like the following. ERROR: do not use assignment in if condition Thus fix six affected source code places. Signed-off-by: Markus Elfring --- sound/pci/echoaudio/echoaudio.c | 55 ++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index d68f99e076a8..ae58c48aaaf9 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c @@ -1913,7 +1913,8 @@ static int snd_echo_create(struct snd_card *card, pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0); - if ((err = pci_enable_device(pci)) < 0) + err = pci_enable_device(pci); + if (err < 0) return err; pci_set_master(pci); @@ -1945,11 +1946,11 @@ static int snd_echo_create(struct snd_card *card, if (sz > PAGE_SIZE) sz = PAGE_SIZE; /* We map only the required part */ - if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz, - ECHOCARD_NAME)) == NULL) { + chip->iores = request_mem_region(chip->dsp_registers_phys, sz, + ECHOCARD_NAME); + if (!chip->iores) { dev_err(chip->card->dev, "cannot get memory region\n"); - snd_echo_free(chip); - return -EBUSY; + goto e_busy; } chip->dsp_registers = (volatile u32 __iomem *) ioremap_nocache(chip->dsp_registers_phys, sz); @@ -1957,8 +1958,7 @@ static int snd_echo_create(struct snd_card *card, if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(chip->card->dev, "cannot grab irq\n"); - snd_echo_free(chip); - return -EBUSY; + goto e_busy; } chip->irq = pci->irq; dev_dbg(card->dev, "pci=%p irq=%d subdev=%04x Init hardware...\n", @@ -1970,8 +1970,8 @@ static int snd_echo_create(struct snd_card *card, sizeof(struct comm_page), &chip->commpage_dma_buf) < 0) { dev_err(chip->card->dev, "cannot allocate the comm page\n"); - snd_echo_free(chip); - return -ENOMEM; + err = -ENOMEM; + goto free_sound_chip; } chip->comm_page_phys = chip->commpage_dma_buf.addr; chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area; @@ -1981,17 +1981,22 @@ static int snd_echo_create(struct snd_card *card, err = set_mixer_defaults(chip); if (err < 0) { dev_err(card->dev, "init_hw err=%d\n", err); - snd_echo_free(chip); - return err; + goto free_sound_chip; } - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { - snd_echo_free(chip); - return err; - } + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); + if (err < 0) + goto free_sound_chip; + *rchip = chip; /* Init done ! */ return 0; + +e_busy: + err = -EBUSY; +free_sound_chip: + snd_echo_free(chip); + return err; } @@ -2020,10 +2025,9 @@ static int snd_echo_probe(struct pci_dev *pci, return err; chip = NULL; /* Tells snd_echo_create to allocate chip */ - if ((err = snd_echo_create(card, pci, &chip)) < 0) { - snd_card_free(card); - return err; - } + err = snd_echo_create(card, pci, &chip); + if (err < 0) + goto free_card; strcpy(card->driver, "Echo_" ECHOCARD_NAME); strcpy(card->shortname, chip->card_name); @@ -2036,18 +2040,18 @@ static int snd_echo_probe(struct pci_dev *pci, card->shortname, pci_id->subdevice & 0x000f, dsp, chip->dsp_registers_phys, chip->irq); - if ((err = snd_echo_new_pcm(chip)) < 0) { + err = snd_echo_new_pcm(chip); + if (err < 0) { dev_err(chip->card->dev, "new pcm error %d\n", err); - snd_card_free(card); - return err; + goto free_card; } #ifdef ECHOCARD_HAS_MIDI if (chip->has_midi) { /* Some Mia's do not have midi */ - if ((err = snd_echo_midi_create(card, chip)) < 0) { + err = snd_echo_midi_create(card, chip); + if (err < 0) { dev_err(chip->card->dev, "new midi error %d\n", err); - snd_card_free(card); - return err; + goto free_card; } } #endif @@ -2152,6 +2156,7 @@ static int snd_echo_probe(struct pci_dev *pci, ctl_error: dev_err(card->dev, "new control error %d\n", err); +free_card: snd_card_free(card); return err; }