From patchwork Tue Feb 3 16:23:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 5770031 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 645C79F399 for ; Tue, 3 Feb 2015 16:24:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5BDA0201FE for ; Tue, 3 Feb 2015 16:24:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0206201FB for ; Tue, 3 Feb 2015 16:24:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965772AbbBCQYI (ORCPT ); Tue, 3 Feb 2015 11:24:08 -0500 Received: from mout.web.de ([212.227.17.11]:59021 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965534AbbBCQYF (ORCPT ); Tue, 3 Feb 2015 11:24:05 -0500 Received: from [192.168.1.2] ([78.49.19.127]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0MOzoR-1YGBQU1VRP-006O4K; Tue, 03 Feb 2015 17:23:29 +0100 Message-ID: <54D0F5FF.7060305@users.sourceforge.net> Date: Tue, 03 Feb 2015 17:23:27 +0100 From: SF Markus Elfring User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Mauro Carvalho Chehab , linux-media@vger.kernel.org CC: LKML , kernel-janitors@vger.kernel.org, Julia Lawall Subject: [PATCH 2/2] [media] DVB: Less function calls in dvb_ca_en50221_init() after error detection References: <5307CAA2.8060406@users.sourceforge.net> <530A086E.8010901@users.sourceforge.net> <530A72AA.3000601@users.sourceforge.net> <530B5FB6.6010207@users.sourceforge.net> <530C5E18.1020800@users.sourceforge.net> <530CD2C4.4050903@users.sourceforge.net> <530CF8FF.8080600@users.sourceforge.net> <530DD06F.4090703@users.sourceforge.net> <5317A59D.4@users.sourceforge.net> <54D0F4F3.1040405@users.sourceforge.net> In-Reply-To: <54D0F4F3.1040405@users.sourceforge.net> X-Provags-ID: V03:K0:OF7D6JVCkPUf+rvlA6eGR93Nr3IgrZopCQW2kAKb+SyEMw4zXDF 3CYYNMSXM+9/s0Dn8jxssA8HX/I9akA2Vm1ZR8fA68Tp6CnL4MwCCUoG2jHcu3AlOH/gb64 a4iy6NfTVREog+jhnzXJ0lmHXSNR21WhrKL14o/A/C+qo6BIg8NgILeT1ysEx2S2qICW/Tu f1e6C2RHR3XG9b3zv5xew== X-UI-Out-Filterresults: notjunk:1; Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Tue, 3 Feb 2015 16:47:48 +0100 The functions "dvb_unregister_device" and "kfree" could still be called by the dvb_ca_en50221_init() function in the case that a previous resource allocation failed. * Corresponding details could be improved by adjustments for jump targets. * Let us delete also an unnecessary check for the variable "ca" there. Signed-off-by: Markus Elfring --- drivers/media/dvb-core/dvb_ca_en50221.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c index b999689..9842fd1 100644 --- a/drivers/media/dvb-core/dvb_ca_en50221.c +++ b/drivers/media/dvb-core/dvb_ca_en50221.c @@ -1676,14 +1676,14 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, /* initialise the system data */ if ((ca = kzalloc(sizeof(struct dvb_ca_private), GFP_KERNEL)) == NULL) { ret = -ENOMEM; - goto error; + goto exit; } ca->pub = pubca; ca->flags = flags; ca->slot_count = slot_count; if ((ca->slot_info = kcalloc(slot_count, sizeof(struct dvb_ca_slot), GFP_KERNEL)) == NULL) { ret = -ENOMEM; - goto error; + goto free_ca; } init_waitqueue_head(&ca->wait_queue); ca->open = 0; @@ -1694,7 +1694,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, /* register the DVB device */ ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA); if (ret) - goto error; + goto free_slot_info; /* now initialise each slot */ for (i = 0; i < slot_count; i++) { @@ -1709,7 +1709,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, if (signal_pending(current)) { ret = -EINTR; - goto error; + goto unregister_device; } mb(); @@ -1720,16 +1720,17 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, ret = PTR_ERR(ca->thread); printk("dvb_ca_init: failed to start kernel_thread (%d)\n", ret); - goto error; + goto unregister_device; } return 0; -error: - if (ca != NULL) { - dvb_unregister_device(ca->dvbdev); - kfree(ca->slot_info); - kfree(ca); - } +unregister_device: + dvb_unregister_device(ca->dvbdev); +free_slot_info: + kfree(ca->slot_info); +free_ca: + kfree(ca); +exit: pubca->private = NULL; return ret; }