From patchwork Sun Sep 17 20:24:16 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: 9955087 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 3B3CF6028A for ; Sun, 17 Sep 2017 20:25:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FEFD28969 for ; Sun, 17 Sep 2017 20:25:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2476528A8E; Sun, 17 Sep 2017 20:25:06 +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=unavailable 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 A0C3728969 for ; Sun, 17 Sep 2017 20:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbdIQUYp (ORCPT ); Sun, 17 Sep 2017 16:24:45 -0400 Received: from mout.web.de ([212.227.17.12]:59310 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751807AbdIQUYo (ORCPT ); Sun, 17 Sep 2017 16:24:44 -0400 Received: from [192.168.1.2] ([77.181.201.34]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0M1o3y-1dZ7G73EyY-00toT4; Sun, 17 Sep 2017 22:24:17 +0200 Subject: [PATCH 8/8] [media] cx231xx: Use common error handling code in cx231xx_load_firmware() From: SF Markus Elfring To: linux-media@vger.kernel.org, Bhumika Goyal , Hans Verkuil , Johan Hovold , Julia Lawall , Matthias Schwarzott , Mauro Carvalho Chehab , Oleh Kravchenko , Peter Rosin , Sakari Ailus Cc: LKML , kernel-janitors@vger.kernel.org References: Message-ID: <57f0d209-1b87-690c-589a-bff8e0ffe24f@users.sourceforge.net> Date: Sun, 17 Sep 2017 22:24:16 +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:LR84+MHc/8+o/rv+d75r68fAElZEnvN/ytJxmMy3vY1yPxrOdqg nw4fyCevRXNIW5NmwFpWhhlGDSG9SLfPOc+s4RPDntY+phFfk/Cl2vFBYiRr7dntePdWjIl Wwy9gS9qIHA5ytto25Pm1pnXxnNhGAgKDH6z0VUsYKj2J5UM/FRlEJaKjmMgHd3sSa8jlia Vx8kWv3ovaXGMYmne7HIw== X-UI-Out-Filterresults: notjunk:1; V01:K0:SSeJMuDdFNE=:lk/dH6RcaxXBOK5L3oWbVX R+RQPK76TOxf23vChr6ni7HjHxts9IE8mFFQDWhGn/K6LY3X5cZhM1QAjapwYY1bl/wbx/hlK BOZL0HDKCnFCIEKKZDgFMuUG/pxyiTY3y0NlPKDT12LKAa5tBwGAwbR4p+ITyaOnZgkoXecCb 6zLlzNVlU1BSgmH0IfD//6RATvI7w2pqSj4gidLPas0vvSiiRArX7coogQv1bF6+dzgmKTf6d 2D0wmTqxCZ+VODq6jF7RLSh5Ep0Bu0sa/mKJwXA3EHvRluQjHmrcEjREiXTW5q3q6dg6sDHnO yTClEkE8dz8/wwduALzuCRPq7XK6i2vgOO7H2tioU+tjRARV+wuzHZSMldIrc5r2+8oOUwL5Y NV4Z5+uDmUGxvjqghnLlQPQJ2C1wHPioEP0l15syqwgfBLHofw6r8IqjlKZCOINFq6VbxuNed kL7A1t/uliB67k7ygTl0a9Q8SutncBeqo8fVja+3FCg9eMDeO7a1sP01bt6hOSKfKu+GDiUxt mE4l6p23368gBHFdfMAwYPZKsaoDd1rsrS9RQy8cJRKWh+uDdBeB+tGbWBcMon2ZLwyLFkjfV iZohe4y0NGjyD2FtWwsAv6/SLyhbcu08jU4x+17UW0PcdGE6sUG3WEpPqblCYIQGyAQL1QumD b3FD6dehKQSAsvvUDCdXaSB2Xq/TGWobfWxwRBezJoaQimBLqEVqbe5fkBINCeiWh4GKk9VeZ NB7y4ZTVX8KVX8PmCuSGLnok8Jbap89Q+SOOMfwyTjmQJ09dnJW5KnVallRlgJlMSiUV1OsR/ +gOvAFT2ZK/QRgl6csK7jo/scPwMU1btb7xoB7SRidCo/ql0Yc= 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: Sun, 17 Sep 2017 21:07:39 +0200 Add jump targets so that a bit of exception handling can be better reused at the end of this function. Signed-off-by: Markus Elfring --- drivers/media/usb/cx231xx/cx231xx-417.c | 61 ++++++++++++++++----------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c index d43345593172..88aac129b678 100644 --- a/drivers/media/usb/cx231xx/cx231xx-417.c +++ b/drivers/media/usb/cx231xx/cx231xx-417.c @@ -954,16 +954,13 @@ static int cx231xx_load_firmware(struct cx231xx *dev) p_current_fw = vmalloc(1884180 * 4); p_fw = p_current_fw; - if (!p_current_fw) { - dprintk(2, "FAIL!!!\n"); - return -ENOMEM; - } + if (!p_current_fw) + goto e_nomem; p_buffer = vmalloc(4096); if (!p_buffer) { - dprintk(2, "FAIL!!!\n"); vfree(p_current_fw); - return -ENOMEM; + goto e_nomem; } dprintk(2, "%s()\n", __func__); @@ -986,9 +983,7 @@ static int cx231xx_load_firmware(struct cx231xx *dev) if (retval != 0) { dev_err(dev->dev, "%s: Error with mc417_register_write\n", __func__); - vfree(p_current_fw); - vfree(p_buffer); - return retval; + goto free_fw; } retval = request_firmware(&firmware, CX231xx_FIRM_IMAGE_NAME, @@ -1000,28 +995,20 @@ static int cx231xx_load_firmware(struct cx231xx *dev) CX231xx_FIRM_IMAGE_NAME); dev_err(dev->dev, "Please fix your hotplug setup, the board will not work without firmware loaded!\n"); - vfree(p_current_fw); - vfree(p_buffer); - return retval; + goto free_fw; } if (firmware->size != CX231xx_FIRM_IMAGE_SIZE) { dev_err(dev->dev, "ERROR: Firmware size mismatch (have %zd, expected %d)\n", firmware->size, CX231xx_FIRM_IMAGE_SIZE); - release_firmware(firmware); - vfree(p_current_fw); - vfree(p_buffer); - return -EINVAL; + goto e_inval; } if (0 != memcmp(firmware->data, magic, 8)) { dev_err(dev->dev, "ERROR: Firmware magic mismatch, wrong file?\n"); - release_firmware(firmware); - vfree(p_current_fw); - vfree(p_buffer); - return -EINVAL; + goto e_inval; } initGPIO(dev); @@ -1065,26 +1052,36 @@ static int cx231xx_load_firmware(struct cx231xx *dev) retval |= mc417_register_write(dev, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST); - if (retval < 0) { - dev_err(dev->dev, - "%s: Error with mc417_register_write\n", - __func__); - return retval; - } + if (retval < 0) + goto report_write_failure; + /* F/W power up disturbs the GPIOs, restore state */ retval |= mc417_register_write(dev, 0x9020, gpio_output); retval |= mc417_register_write(dev, 0x900C, value); retval |= mc417_register_read(dev, IVTV_REG_VPU, &value); retval |= mc417_register_write(dev, IVTV_REG_VPU, value & 0xFFFFFFE8); + if (retval < 0) + goto report_write_failure; - if (retval < 0) { - dev_err(dev->dev, - "%s: Error with mc417_register_write\n", - __func__); - return retval; - } return 0; + +e_nomem: + dprintk(2, "FAIL!!!\n"); + return -ENOMEM; + +e_inval: + retval = -EINVAL; + release_firmware(firmware); + +free_fw: + vfree(p_current_fw); + vfree(p_buffer); + return retval; + +report_write_failure: + dev_err(dev->dev, "%s: Error with mc417_register_write\n", __func__); + return retval; } static void cx231xx_417_check_encoder(struct cx231xx *dev)