From patchwork Sat Nov 11 16:17: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: 10054411 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 EF70360632 for ; Sat, 11 Nov 2017 16:17:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF74429C1F for ; Sat, 11 Nov 2017 16:17:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A366829C22; Sat, 11 Nov 2017 16:17:19 +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 4B7C529C1F for ; Sat, 11 Nov 2017 16:17:17 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id AA91726717C; Sat, 11 Nov 2017 17:17:15 +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 4FD8E267193; Sat, 11 Nov 2017 17:17:14 +0100 (CET) Received: from mout.web.de (mout.web.de [212.227.15.4]) by alsa0.perex.cz (Postfix) with ESMTP id 39A6B266B67 for ; Sat, 11 Nov 2017 17:17:10 +0100 (CET) Received: from [192.168.1.3] ([77.181.92.20]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M5Jip-1f9GGM2GRb-00zXut; Sat, 11 Nov 2017 17:17:05 +0100 To: alsa-devel@alsa-project.org, Jaroslav Kysela , Takashi Iwai From: SF Markus Elfring Message-ID: <1af701eb-c379-336f-aa00-28c30cd33d51@users.sourceforge.net> Date: Sat, 11 Nov 2017 17:17:04 +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:h+Z0JUXVRojzU+3wamBpiBuyll8rvP7rmOp7LtjXURSRHgzUXRd +WCdUPbgR9GfnUeZbUWDNi6VHwZr7Avql3L8rwKzRdV6xbjEpaIwPFSToc/rHJW72n090RE P07J5giUsty8Y/eL2xTHB7gMiHhF1/cVNVD/EneRmpVg0owh0s78i+CMWsE/hTzjkR/Tzxy FRWmUmcWSnmweAmhS2yyQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:IXwlW7DEJpE=:X0vq7s7d2Z7NB5xI0Mzn90 UyL+2PdV8UMU2btta0v45eGoZLRFoX5xq4ogWhe2odKV3Tsl0HUXxw4NZ7WjqUYSNOp7fdkUO 371LnuSKTAh1sN5umm0uiCt1wXYzpabf7jR8AlQC4iiIXGPvxSgHaUmaRfy0vLC7JJa4FGejx EaRpm3sVLEDISrsx24NHW3LcqTrWrALf4vHebPQLXSDm0lkmS4BpKK9oUPnf4I+HV5jF8i2Lr UkTGXQ6t5MLoRUw1K8eP8avhasb2SS+prZUf2bsPUECWM5cdHGMs3+Prl9/qTcbMurRI8WBun kwPMlsfubXBl17/ftcNF89Us0m8NQatBfxNUofJ4bCPwG9JbXL8kVW3y1zGJue+tA1ccr8KlX kBsCfYR+AJHiOON7GmA5yiZT8CoAE6gdsiq89vqjLxFKEMcnO1dvcXikGy8aobq1UB7Iit0LW H9UDYVbzQAVu7hoeEhBAQzWBMaK50tQaaGtvR4tEjly0E9DGEHMCTe18l1xYcI22Z6My5sIWd QlmNbsgTgU/V02XMwR+udVNvs0DMhZE6SJjmuOQlJpLMC1Kz34OmXD6eyab3GiaYqTa2yBGow VnEpjz09Vw0nasWTnx7bokJOYdpPw0NmKf3o8aHUnMZti7BXnT7qaC1XjZJC8ELDjf8chhk2k KLLe4QhZxXG/1zriPxvJfWdVlhMeDqOCjAaCBeobNsyQV7HkO3PkvlHZiRwsF6K/HPdhNKJVE 5ux5AGYAVutEhLVWEmummfICR/1/e+VDeSHBPtB2ZSFOhHAcTxOJp01T5aAep0PO8Xu2lRN5w 2BKUnk0RjQVidDnRAlcTUUZxIQ4xpMy28d2M+S+9Ec+9bbiRsY= Cc: kernel-janitors@vger.kernel.org, LKML Subject: [alsa-devel] [PATCH] ALSA: i2c: 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, 11 Nov 2017 17:10:24 +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/i2c/i2c.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/sound/i2c/i2c.c b/sound/i2c/i2c.c index ef2a9afe9e19..9292aa60f3a2 100644 --- a/sound/i2c/i2c.c +++ b/sound/i2c/i2c.c @@ -282,20 +282,22 @@ static int snd_i2c_bit_sendbytes(struct snd_i2c_device *device, return -EIO; /* not yet implemented */ snd_i2c_bit_start(bus); err = snd_i2c_bit_sendbyte(bus, device->addr << 1); - if (err < 0) { - snd_i2c_bit_hw_stop(bus); - return err; - } + if (err < 0) + goto stop_bus; + while (count-- > 0) { err = snd_i2c_bit_sendbyte(bus, *bytes++); - if (err < 0) { - snd_i2c_bit_hw_stop(bus); - return err; - } + if (err < 0) + goto stop_bus; + res++; } snd_i2c_bit_stop(bus); return res; + +stop_bus: + snd_i2c_bit_hw_stop(bus); + return err; } static int snd_i2c_bit_readbytes(struct snd_i2c_device *device, @@ -308,21 +310,23 @@ static int snd_i2c_bit_readbytes(struct snd_i2c_device *device, return -EIO; /* not yet implemented */ snd_i2c_bit_start(bus); err = snd_i2c_bit_sendbyte(bus, (device->addr << 1) | 1); - if (err < 0) { - snd_i2c_bit_hw_stop(bus); - return err; - } + if (err < 0) + goto stop_bus; + while (count-- > 0) { err = snd_i2c_bit_readbyte(bus, count == 0); - if (err < 0) { - snd_i2c_bit_hw_stop(bus); - return err; - } + if (err < 0) + goto stop_bus; + *bytes++ = (unsigned char)err; res++; } snd_i2c_bit_stop(bus); return res; + +stop_bus: + snd_i2c_bit_hw_stop(bus); + return err; } static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)