From patchwork Mon Sep 18 13:57:21 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: 9956775 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 3C4D6601E9 for ; Mon, 18 Sep 2017 13:58:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E05D28A12 for ; Mon, 18 Sep 2017 13:58:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22C8A28A23; Mon, 18 Sep 2017 13:58: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 CC8C628A12 for ; Mon, 18 Sep 2017 13:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755983AbdIRN5e (ORCPT ); Mon, 18 Sep 2017 09:57:34 -0400 Received: from mout.web.de ([212.227.17.12]:59123 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755980AbdIRN52 (ORCPT ); Mon, 18 Sep 2017 09:57:28 -0400 Received: from [192.168.1.2] ([78.48.130.71]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MbyIM-1e9pVU18D8-00JMuB; Mon, 18 Sep 2017 15:57:22 +0200 Subject: [PATCH 4/6] [media] go7007: Use common error handling code in s2250_probe() From: SF Markus Elfring To: linux-media@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab Cc: LKML , kernel-janitors@vger.kernel.org References: Message-ID: Date: Mon, 18 Sep 2017 15:57:21 +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:/0qOwjzjGjFx1ad5yq+VJ8cPQ/oVLJH3Ka4PWR5SRKIiECtkua9 PFtB+R793SHXvD0eSWEp9L3ReSVrnDMIDyzhBYTKltRt2JIZF/T+cS2XcL4dOA3qbYuLS3/ 0mstBXQyqleY5NTNbLDHAPLf+OFYyd7DAKkK4f3MmlXpvWA/SLX/jtnzXK0vLtZGld+YdM0 e9AJnM2G8hTV408rSMcRg== X-UI-Out-Filterresults: notjunk:1; V01:K0:/xo/oqH3tF0=:BogufC9v9Lp89L3Mm/Rlsk Aa8KgjvumvYu/qXz9cSvfDCQDfz7RMEM+U+4ZqsQS7egMoxJW3i/PrcDaqf2x0fpwlYdlwvVm 5Rz2DLubKmUQ7qIfJAg/StfC8flyY5kZepCq38yFiQ5B0+nYcFYBGBTLJtLfNtea9HWUN0D8B 1sYXy1MWYlDVQqU4Mulz0fINTXB+JWidbx66o5v95Gm+/ePLSW92hIs/cus6UyR578XOb0QWw XSXo+bLB84NPPfTRRuhkuarDBdvVKC36Rbb0+svQDjnYQgiMHdBTRJ4gUeVvwTQOFeKkUkVZt gNEtONScw1OyQd85wo02nAzGKu5bobKF8uyItk5SgvJgsKu+QkScSVZ76DRg8Xb4MZNobCUQW XZXu4ZYdIw/e9hiBfMMiWbliyd6L2w5hYfH8ZO0mkaT3S/wa2Cn5w3RXDNVoQGezW5TNHk3r3 3wIr+bevqbY+4ZNrjWUpWWeZ0PadghTH8O9bKAmWpzdUCcPUtt+4HkoPZ60TuFmIyQpun8MeI WcGKRCDjaD0NI2Dq1rvDkivAuXBW4mbDWZn4SV2JPQWms/DIsCA1i8K1LE5Es3WxiOaWAK8TF MLyZIinLvFIuR/aQixFsskEkVW19zNO5iq+QLzdtKAQ4iel8sFUAPc7zUs9HmrrAoEJjWGjhJ dFwn3mhbTzYr2h7KKEjZOngiS829dzI0BzEnBmvNYz1LhFuQrDGX2fcvBIzLPLxyMEop7dQSU FaWD70vgyW+IVjlZ/nboRhJr84dK32nyozhCb+BxsVhoLU92RwVh/IeYdygBkv+p07o144mPk +kpB5yPx08pVeuTMy3NWITwcvo8L03MK7ZMhvSWhH934F5HlKU= 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: Mon, 18 Sep 2017 13:50:45 +0200 Adjust jump targets so that a bit of exception handling can be better reused at the end of this function. This refactoring might fix also an error situation where the function "i2c_unregister_device" was not called after a software failure was noticed by the data member "hdl.error". Signed-off-by: Markus Elfring --- drivers/media/usb/go7007/s2250-board.c | 37 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/media/usb/go7007/s2250-board.c b/drivers/media/usb/go7007/s2250-board.c index 1fd4c09dd516..1bd9a7f2e7a3 100644 --- a/drivers/media/usb/go7007/s2250-board.c +++ b/drivers/media/usb/go7007/s2250-board.c @@ -510,6 +510,7 @@ static int s2250_probe(struct i2c_client *client, u8 *data; struct go7007 *go = i2c_get_adapdata(adapter); struct go7007_usb *usb = go->hpi_context; + int code; audio = i2c_new_dummy(adapter, TLV320_ADDRESS >> 1); if (!audio) @@ -517,8 +518,8 @@ static int s2250_probe(struct i2c_client *client, state = kzalloc(sizeof(*state), GFP_KERNEL); if (!state) { - i2c_unregister_device(audio); - return -ENOMEM; + code = -ENOMEM; + goto unregister_device; } sd = &state->sd; @@ -538,11 +539,8 @@ static int s2250_probe(struct i2c_client *client, V4L2_CID_HUE, -512, 511, 1, 0); sd->ctrl_handler = &state->hdl; if (state->hdl.error) { - int err = state->hdl.error; - - v4l2_ctrl_handler_free(&state->hdl); - kfree(state); - return err; + code = state->hdl.error; + goto free_handler; } state->std = V4L2_STD_NTSC; @@ -555,17 +553,13 @@ static int s2250_probe(struct i2c_client *client, /* initialize the audio */ if (write_regs(audio, aud_regs) < 0) { dev_err(&client->dev, "error initializing audio\n"); - goto fail; + goto e_io; } - if (write_regs(client, vid_regs) < 0) { - dev_err(&client->dev, "error initializing decoder\n"); - goto fail; - } - if (write_regs_fp(client, vid_regs_fp) < 0) { - dev_err(&client->dev, "error initializing decoder\n"); - goto fail; - } + if (write_regs(client, vid_regs) < 0 || + write_regs_fp(client, vid_regs_fp) < 0) + goto report_write_failure; + /* set default channel */ /* composite */ write_reg_fp(client, 0x20, 0x020 | 1); @@ -602,11 +596,16 @@ static int s2250_probe(struct i2c_client *client, v4l2_info(sd, "initialized successfully\n"); return 0; -fail: - i2c_unregister_device(audio); +report_write_failure: + dev_err(&client->dev, "error initializing decoder\n"); +e_io: + code = -EIO; +free_handler: v4l2_ctrl_handler_free(&state->hdl); kfree(state); - return -EIO; +unregister_device: + i2c_unregister_device(audio); + return code; } static int s2250_remove(struct i2c_client *client)