From patchwork Wed Sep 20 12:40:28 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: 9961373 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 23CEB60234 for ; Wed, 20 Sep 2017 12:41:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16926290F9 for ; Wed, 20 Sep 2017 12:41:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B720290FC; Wed, 20 Sep 2017 12:41:15 +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 ACF4A290F9 for ; Wed, 20 Sep 2017 12:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751798AbdITMkg (ORCPT ); Wed, 20 Sep 2017 08:40:36 -0400 Received: from mout.web.de ([212.227.15.3]:64168 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751554AbdITMkf (ORCPT ); Wed, 20 Sep 2017 08:40:35 -0400 Received: from [192.168.1.2] ([77.181.108.184]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Mg7Zl-1dimDL2RCH-00NPRo; Wed, 20 Sep 2017 14:40:30 +0200 To: linux-media@vger.kernel.org, Mauro Carvalho Chehab Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] [media] Siano: Use common error handling code in smsusb_init_device() Message-ID: Date: Wed, 20 Sep 2017 14:40:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:h9VqVOR6135LmGl920NHIF1J9zTvxYa1THEG7jMWV/QrTBwUBHN DBGb9Ay1nTZ3yO/UTxV+jCKh0tkG1WmgDxFihepwQjHVFEO8jVPdD1sGrvJzdNzqHtYxgNs Hf+1jw7R4SN8rkT8KQx4eYSDc4o50VSaH7jimCcMFchMZUVKi+KDlY2g6BjJG2edremkoFH euPcB5N5nqOuegnZoV7Xg== X-UI-Out-Filterresults: notjunk:1; V01:K0:QMoZCh3S5kg=:Kwnfea0TDMxMr3jmxtARRc 1B9fBTa4Yzc4Y0fjLBNxI5yt3HaEiLwiXys5zQz4hJrJN8YwBjW3Dnx8kN3rlutJGYaI4lQ2p 31YBrnN+3P4cTUzyN6HnViFazdfiyFSsiChMSYCQx1t116mxOK4jssiGoguqfAPF6T6r1CjUO z4ouPbPgWX7LDhqJ7JX872PQPYQYBlyouh+MJNYz4lwe6xlDGjKmYguWsEMqs/qA38K/rB2Zx 6ng/QAqFJX6bdBs6vw84dawxj26tekNLij864AC2bDwf7cA7CoX/0Xd0a5lQwB2G+vDs7ukhX jSRxjR1BZ/bbBZyS4lE405Cw6f69FUD/85n2PZhNjsg0as1XpCB7k0kr4EPcWz4Vev0Mktifm Eqfy5qauRK05aPaHwZdR5hGtGQVVpkJT0Yf43bb0P3H0a/yfC2IsVHTLtRzBDQ93nDbEsbNcr /LSnY4HB2sMMOLntzU320NHUrT6xGbzTnMFQKgc0XnvuExHw2tzMQgscN2ALkbmjGB9MbkM0S ZNLLtHQmV7NgniE1Yq0Q6EEG8BMZLHM8U0ifnh1siWY4GcAo/27TaoDiY/90w3+YTqNg9TDMg Mg4OgImJdQ1Ud9aRjfokDYjqLDvAv8YCj72L/qwnpu7qaqFKk20F5+1LdBAkIcCYCam/KCjmC DN4p5/+nhSOdSwFmsaJlZvus2/8fqNMxGk9hsZPyadeL/YhCTsV9ah9FimCq3hSfW3NQuI3rW 6KV6p86ITXSkDCYJycRslGKGB2qpk2yt/jrd+NR44OY0LRsgv0gkx/MI4XAgFyPNbLQZCTJYZ Aa7Ofoa/rGHeMKobg+4X/jdoINeZBuqU73oTXoJVc+PvMu/OEo= 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: Wed, 20 Sep 2017 14:30:55 +0200 Add a jump target 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 "kfree" was not called after a software failure was noticed in two cases. Signed-off-by: Markus Elfring --- drivers/media/usb/siano/smsusb.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/siano/smsusb.c b/drivers/media/usb/siano/smsusb.c index 8c1f926567ec..b8e7b05cf6d0 100644 --- a/drivers/media/usb/siano/smsusb.c +++ b/drivers/media/usb/siano/smsusb.c @@ -458,12 +458,10 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id) rc = smscore_register_device(¶ms, &dev->coredev, mdev); if (rc < 0) { pr_err("smscore_register_device(...) failed, rc %d\n", rc); - smsusb_term_device(intf); #ifdef CONFIG_MEDIA_CONTROLLER_DVB media_device_unregister(mdev); #endif - kfree(mdev); - return rc; + goto terminate_device; } smscore_set_board_id(dev->coredev, board_id); @@ -480,8 +478,7 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id) rc = smsusb_start_streaming(dev); if (rc < 0) { pr_err("smsusb_start_streaming(...) failed\n"); - smsusb_term_device(intf); - return rc; + goto terminate_device; } dev->state = SMSUSB_ACTIVE; @@ -489,13 +486,17 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id) rc = smscore_start_device(dev->coredev); if (rc < 0) { pr_err("smscore_start_device(...) failed\n"); - smsusb_term_device(intf); - return rc; + goto terminate_device; } pr_debug("device 0x%p created\n", dev); return rc; + +terminate_device: + smsusb_term_device(intf); + kfree(mdev); + return rc; } static int smsusb_probe(struct usb_interface *intf,