From patchwork Sun Sep 17 20:21:17 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: 9955075 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 396A16028A for ; Sun, 17 Sep 2017 20:22:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 304CF28AFE for ; Sun, 17 Sep 2017 20:22:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EE6D28B29; Sun, 17 Sep 2017 20:22:02 +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 8589F28B35 for ; Sun, 17 Sep 2017 20:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751457AbdIQUVq (ORCPT ); Sun, 17 Sep 2017 16:21:46 -0400 Received: from mout.web.de ([212.227.17.11]:59615 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751352AbdIQUVp (ORCPT ); Sun, 17 Sep 2017 16:21:45 -0400 Received: from [192.168.1.2] ([77.181.201.34]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0Lcxxc-1dBZs71laq-00i9eR; Sun, 17 Sep 2017 22:21:19 +0200 Subject: [PATCH 5/8] [media] cx231xx: Use common error handling code in dvb_init() 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: <3f4e988c-4552-11f4-29e8-7b5c537a910b@users.sourceforge.net> Date: Sun, 17 Sep 2017 22:21:17 +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:kceBw2HouQ76WO0o1S/MkFzgQGM2Umw65CCXZasUVbHQhIgb5al ROpU5iga815Q99u3gSXl7dql7tpPh9QOJ/RMyC01HrMucafjlFbUmzby5GjVpJTFsxu+2a4 WzcAU7VIKENtQmDIXnnY2S75EWW4TO7fxKwmhHe436NF/fVfnhMEBRzoy4D13LDJUCaArb8 i3fW8J/n75XqpImHHQVOQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:8DH2zTjFtss=:JuQ3nGxHb0wSAwO6HPJo0D u1icB1JCm1e5jDdFWBpOZ6OX9ONG3acaleR0mJytTAfz6b4yAgUpOdYYByadntoviM7EHAtii C0vl1hkf6e4eqxJXOGEUtL5iIn5/VExlp8/oiZXuWJhQDdYV9CMck98GITy1EI45hkUkiQKxo Gt+dF/izSlbixfYgx+rnci0PSCqGoSHuvr6HTP5t3iT1ums0Zn9vbXtaHIbO/KshdIInism59 Vk4BkoQjfXFMpj8n0eBDEB/TB4xvN7KMtJ+uUyr/nGO2SgJafGPhErXkVJox7Ns3pAECK/cQ/ 5Ch4B7VVbWd0Wh/bzxLZKGm1rHRYOsKIH0aRqj+qUrKWIkVSesK13an4ENj1crI4/8hHF/AkG brEJUt/QHsahc5OvkKG9B+M29GG+WimjEZPPLyoGyEqdFvazQfbUsbcJnSXLQmgfnJwCwoido RhtcmBVTMfy8u4gFP0D1GhpRLwumqfXVGsIhJ52jzUooChJtkqR6IFQkMXNhVRpvapUy/Uxt+ dBr1AzQsG312csxb4x04XG+B84e8nTvnE5wuUa5O1bW/Sohdd2VzmZHKHjWSrqCYD5WUIj9O2 uz0ekd5pPD5GEu9RKsb2TkyH7Fnj3TbrrcDhutOpB8Fu3h6pOc8FzaYJazQ2EvAicmQ0YREjW 0Ahz3iLknHc/U64FVMsQGfkmnzCa1KHdT3eQJ2dA2fm6TKWB/pmDymcRByKPgXH4BoSXVuRmm ToMbop0m4nz7Z2b4YNhAoSoV6mQDxga0zVTOL/hyP63m0E1ulLrMiAGSKcAE5QG4KPp5TVlAb 4w+Gl39qWQW72NxOB+LUGuufCjiB5I9D4IyuuZ+6WvcOT6pWaM= 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 20:10:34 +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-dvb.c | 135 +++++++++++++------------------- 1 file changed, 53 insertions(+), 82 deletions(-) diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c index 091ec0cf56a6..af51113b4a55 100644 --- a/drivers/media/usb/cx231xx/cx231xx-dvb.c +++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c @@ -635,19 +635,15 @@ static int dvb_init(struct cx231xx *dev) if (!dev->dvb->frontend) { dev_err(dev->dev, "Failed to attach s5h1432 front end\n"); - result = -EINVAL; - goto out_free; + goto e_inval; } /* define general-purpose callback pointer */ dvb->frontend->callback = cx231xx_tuner_callback; if (!dvb_attach(xc5000_attach, dev->dvb->frontend, - tuner_i2c, - &cnxt_rde250_tunerconfig)) { - result = -EINVAL; - goto out_free; - } + tuner_i2c, &cnxt_rde250_tunerconfig)) + goto e_inval; break; case CX231XX_BOARD_CNXT_SHELBY: @@ -659,19 +655,16 @@ static int dvb_init(struct cx231xx *dev) if (!dev->dvb->frontend) { dev_err(dev->dev, "Failed to attach s5h1411 front end\n"); - result = -EINVAL; - goto out_free; + goto e_inval; } /* define general-purpose callback pointer */ dvb->frontend->callback = cx231xx_tuner_callback; if (!dvb_attach(xc5000_attach, dev->dvb->frontend, - tuner_i2c, - &cnxt_rdu250_tunerconfig)) { - result = -EINVAL; - goto out_free; - } + tuner_i2c, &cnxt_rdu250_tunerconfig)) + goto e_inval; + break; case CX231XX_BOARD_CNXT_RDE_253S: @@ -681,19 +674,16 @@ static int dvb_init(struct cx231xx *dev) if (!dev->dvb->frontend) { dev_err(dev->dev, "Failed to attach s5h1432 front end\n"); - result = -EINVAL; - goto out_free; + goto e_inval; } /* define general-purpose callback pointer */ dvb->frontend->callback = cx231xx_tuner_callback; if (!dvb_attach(tda18271_attach, dev->dvb->frontend, - 0x60, tuner_i2c, - &cnxt_rde253s_tunerconfig)) { - result = -EINVAL; - goto out_free; - } + 0x60, tuner_i2c, &cnxt_rde253s_tunerconfig)) + goto e_inval; + break; case CX231XX_BOARD_CNXT_RDU_253S: case CX231XX_BOARD_KWORLD_UB445_USB_HYBRID: @@ -704,19 +694,16 @@ static int dvb_init(struct cx231xx *dev) if (!dev->dvb->frontend) { dev_err(dev->dev, "Failed to attach s5h1411 front end\n"); - result = -EINVAL; - goto out_free; + goto e_inval; } /* define general-purpose callback pointer */ dvb->frontend->callback = cx231xx_tuner_callback; if (!dvb_attach(tda18271_attach, dev->dvb->frontend, - 0x60, tuner_i2c, - &cnxt_rde253s_tunerconfig)) { - result = -EINVAL; - goto out_free; - } + 0x60, tuner_i2c, &cnxt_rde253s_tunerconfig)) + goto e_inval; + break; case CX231XX_BOARD_HAUPPAUGE_EXETER: @@ -730,8 +717,7 @@ static int dvb_init(struct cx231xx *dev) if (!dev->dvb->frontend) { dev_err(dev->dev, "Failed to attach LG3305 front end\n"); - result = -EINVAL; - goto out_free; + goto e_inval; } /* define general-purpose callback pointer */ @@ -763,14 +749,12 @@ static int dvb_init(struct cx231xx *dev) if (!client || !client->dev.driver || !dev->dvb->frontend) { dev_err(dev->dev, "Failed to attach SI2165 front end\n"); - result = -EINVAL; - goto out_free; + goto e_inval; } if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); - result = -ENODEV; - goto out_free; + goto e_nodev; } dvb->i2c_client_demod = client; @@ -810,14 +794,12 @@ static int dvb_init(struct cx231xx *dev) if (!client || !client->dev.driver || !dev->dvb->frontend) { dev_err(dev->dev, "Failed to attach SI2165 front end\n"); - result = -EINVAL; - goto out_free; + goto e_inval; } if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); - result = -ENODEV; - goto out_free; + goto e_nodev; } dvb->i2c_client_demod = client; @@ -845,17 +827,12 @@ static int dvb_init(struct cx231xx *dev) client = i2c_new_device( tuner_i2c, &info); - if (!client || !client->dev.driver) { - dvb_frontend_detach(dev->dvb->frontend); - result = -ENODEV; - goto out_free; - } + if (!client || !client->dev.driver) + goto detach_frontend; if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); - dvb_frontend_detach(dev->dvb->frontend); - result = -ENODEV; - goto out_free; + goto detach_frontend; } dev->cx231xx_reset_analog_tuner = NULL; @@ -878,8 +855,7 @@ static int dvb_init(struct cx231xx *dev) if (!dev->dvb->frontend) { dev_err(dev->dev, "Failed to attach LGDT3306A frontend.\n"); - result = -EINVAL; - goto out_free; + goto e_inval; } dev->dvb->frontend->ops.i2c_gate_ctrl = NULL; @@ -903,17 +879,12 @@ static int dvb_init(struct cx231xx *dev) client = i2c_new_device( tuner_i2c, &info); - if (!client || !client->dev.driver) { - dvb_frontend_detach(dev->dvb->frontend); - result = -ENODEV; - goto out_free; - } + if (!client || !client->dev.driver) + goto detach_frontend; if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); - dvb_frontend_detach(dev->dvb->frontend); - result = -ENODEV; - goto out_free; + goto detach_frontend; } dev->cx231xx_reset_analog_tuner = NULL; @@ -934,8 +905,7 @@ static int dvb_init(struct cx231xx *dev) if (!dev->dvb->frontend) { dev_err(dev->dev, "Failed to attach mb86a20s demod\n"); - result = -EINVAL; - goto out_free; + goto e_inval; } /* define general-purpose callback pointer */ @@ -966,15 +936,12 @@ static int dvb_init(struct cx231xx *dev) request_module(info.type); client = i2c_new_device(demod_i2c, &info); - if (!client || !client->dev.driver) { - result = -ENODEV; - goto out_free; - } + if (!client || !client->dev.driver) + goto e_nodev; if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); - result = -ENODEV; - goto out_free; + goto e_nodev; } dvb->i2c_client_demod = client; @@ -994,19 +961,12 @@ static int dvb_init(struct cx231xx *dev) request_module(info.type); client = i2c_new_device(tuner_i2c, &info); - if (!client || !client->dev.driver) { - module_put(dvb->i2c_client_demod->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod); - result = -ENODEV; - goto out_free; - } + if (!client || !client->dev.driver) + goto put_module; if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); - module_put(dvb->i2c_client_demod->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod); - result = -ENODEV; - goto out_free; + goto put_module; } dev->cx231xx_reset_analog_tuner = NULL; @@ -1030,15 +990,12 @@ static int dvb_init(struct cx231xx *dev) request_module(info.type); client = i2c_new_device(demod_i2c, &info); - if (!client || !client->dev.driver) { - result = -ENODEV; - goto out_free; - } + if (!client || !client->dev.driver) + goto e_nodev; if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); - result = -ENODEV; - goto out_free; + goto e_nodev; } dvb->i2c_client_demod = client; @@ -1061,8 +1018,7 @@ static int dvb_init(struct cx231xx *dev) if (!dvb->frontend) { dev_err(dev->dev, "%s/2: frontend initialization failed\n", dev->name); - result = -EINVAL; - goto out_free; + goto e_inval; } /* register everything */ @@ -1079,6 +1035,21 @@ static int dvb_init(struct cx231xx *dev) mutex_unlock(&dev->lock); return result; +put_module: + module_put(dvb->i2c_client_demod->dev.driver->owner); + i2c_unregister_device(dvb->i2c_client_demod); + goto e_nodev; + +detach_frontend: + dvb_frontend_detach(dev->dvb->frontend); + +e_nodev: + result = -ENODEV; + goto out_free; + +e_inval: + result = -EINVAL; + out_free: kfree(dvb); dev->dvb = NULL;