From patchwork Sat Sep 9 20:33:08 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: 9945445 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 E9D16604D7 for ; Sat, 9 Sep 2017 20:33:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEBF828A16 for ; Sat, 9 Sep 2017 20:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3D4128A38; Sat, 9 Sep 2017 20:33:33 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81FF628A16 for ; Sat, 9 Sep 2017 20:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751310AbdIIUdP (ORCPT ); Sat, 9 Sep 2017 16:33:15 -0400 Received: from mout.web.de ([217.72.192.78]:55373 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750940AbdIIUdO (ORCPT ); Sat, 9 Sep 2017 16:33:14 -0400 Received: from [192.168.1.2] ([78.49.13.42]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LsyRS-1dTFLo03WU-012Uxt; Sat, 09 Sep 2017 22:33:10 +0200 Subject: [PATCH 3/3] [media] xc2028: Use common error handling code in load_firmware() From: SF Markus Elfring To: linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: LKML , kernel-janitors@vger.kernel.org References: Message-ID: Date: Sat, 9 Sep 2017 22:33:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-GB X-Provags-ID: V03:K0:vFHqOrgHx++u9B3g08Lh932yLAwUBQD3XbpRQLXEd+bSrp8z77P xTFNc/DdCDeeoTYTAruIxVFwGGZhMDpsg7wdeK6iC3ZBSmG/7p31hyvtdNdNXVJQQM1E1B3 BBh+ZtQXPzRECbcCdbg4zaMlCKsVlUvfxU67tPIodEY8061kq6mx6xDn87Ps6k6KNL+kPmk UcZw7jT+UabRZZFM7NU6A== X-UI-Out-Filterresults: notjunk:1; V01:K0:UYbY/4+rdLY=:e7Zj4c8D/ysBZW3JpdFNq1 BLdf1ZcSMFX+C+FWCeyz5UUSM50kdqPdi8BtX+qNFq7eiRj5IbFlabRifl8ZFjvovasNY+6p9 Mdw9jtpxU2x3eOobhCUx1sZV78legbvaZbcnNPQY4nSrhqo0EeN5ntjktBInO5rtKS77QV/eu D61mmLC5WMNtNmTFCmB+TzGu1DfK8vguqFsgop2bBH1jVLzx3+YnoC5bcFJQtximGfwUVwVfu 3fl3LT/Xd9eppkJEOoBEVaLfQYbuYgFBG3SBuAhVrT2gzMuiDVXlsxrTa4a7KPkQJM2pIJ0eL VZn2DfnCQEjox97aX3aOgVUj3Rdil/KKWsvUU4xIo6N/+2A8+4GdrSqv6sVGBrHQNpMceQ4lZ pvJf9nb4FB4Ej/0yCAYZn/0NPMK0kwG26juytzNDD73diCYsxJcFz35HcSx9iSPTNan+SJWkv FKyyNDzMf12/sfhPf+wIt1pdbgsNc4k2I2UghZlqrCKUadXNTER34ylEu3QkjvP6avgdo9ccu ja33rYd9p8HY6XxDTmaP1KZp0NLTQtptslJ/5xvtJvtSu1k2GlavCuqsKTSn9mFjFTK/VynJZ vwYzN5o5y6Ru0n8vEGXU9pXeGtC68pvNeg4SXQBmUN3PpdJD+EWgcOZ9y64+4yBto4YAa7Djy fUkPwqrIxi9J0QUUXw7SSd/BWYXbYKwYgIYhzqmOVvHXb0wXV0rQpJ9nFFuvJ9pp76xWjB9RG 6yz+y3Os7YvmmhDmDYDKzFLA7MoRjoisc74dc4vu7pGqRMbjekWnQKhaBcWv1fDPGPBLbNjgR OQqv0+pw0XG+DlvTmwZUIQepo4/mxlsTyANCzTnPQuEbk4XAVI= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 9 Sep 2017 22:07:04 +0200 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 --- drivers/media/tuners/tuner-xc2028.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c index 90efe11aa0a8..4b617e09b81f 100644 --- a/drivers/media/tuners/tuner-xc2028.c +++ b/drivers/media/tuners/tuner-xc2028.c @@ -571,7 +571,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, /* Checks if there's enough bytes to read */ if (p + sizeof(size) > endp) { tuner_err("Firmware chunk size is wrong\n"); - return -EINVAL; + goto e_inval; } size = le16_to_cpu(*(__le16 *) p); @@ -583,28 +583,23 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, if (!size) { /* Special callback command received */ rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0); - if (rc < 0) { - tuner_err("Error at RESET code %d\n", - (*p) & 0x7f); - return -EINVAL; - } + if (rc < 0) + goto report_failure; + continue; } if (size >= 0xff00) { switch (size) { case 0xff00: rc = do_tuner_callback(fe, XC2028_RESET_CLK, 0); - if (rc < 0) { - tuner_err("Error at RESET code %d\n", - (*p) & 0x7f); - return -EINVAL; - } + if (rc < 0) + goto report_failure; + break; default: tuner_info("Invalid RESET code %d\n", size & 0x7f); - return -EINVAL; - + goto e_inval; } continue; } @@ -618,7 +613,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, if ((size + p > endp)) { tuner_err("missing bytes: need %d, have %d\n", size, (int)(endp - p)); - return -EINVAL; + goto e_inval; } buf[0] = *p; @@ -635,7 +630,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, rc = i2c_send(priv, buf, len + 1); if (rc < 0) { tuner_err("%d returned from send\n", rc); - return -EINVAL; + goto e_inval; } p += len; @@ -650,6 +645,11 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, } } return 0; + +report_failure: + tuner_err("Error at RESET code %d\n", (*p) & 0x7f); +e_inval: + return -EINVAL; } static int load_scode(struct dvb_frontend *fe, unsigned int type,