From patchwork Sat Dec 10 20:48:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9469481 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 7B13C60234 for ; Sat, 10 Dec 2016 20:48:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C7FD28417 for ; Sat, 10 Dec 2016 20:48:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D81F284E6; Sat, 10 Dec 2016 20:48:24 +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=ham 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 B82CF28417 for ; Sat, 10 Dec 2016 20:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752352AbcLJUsW (ORCPT ); Sat, 10 Dec 2016 15:48:22 -0500 Received: from mout.web.de ([212.227.15.14]:53175 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751989AbcLJUsV (ORCPT ); Sat, 10 Dec 2016 15:48:21 -0500 Received: from [192.168.1.2] ([77.181.156.58]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LwU2B-1ciBWg29ap-018N9U; Sat, 10 Dec 2016 21:48:09 +0100 Subject: [PATCH 1/4] [media] bt8xx: One function call less in bttv_input_init() after error detection To: linux-media@vger.kernel.org, Alexey Khoroshilov , Hans Verkuil , Mauro Carvalho Chehab References: Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: Date: Sat, 10 Dec 2016 21:48:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: X-Provags-ID: V03:K0:tjseqnPZLp1mmaxxdWCsuaCBqJB3Fi+DNjVDWt/RpJsDfHMLp9E gSB0h8lqiUbHNyWWWKAZF2V7OlrgUNQHjxI0WqvmINr99eOzNTY/wRj7YxKJJE+rfzI1ZOn WYBWrQzMEtuRkvnfbWltra93uQIOoVJGfFBi9RUfq0BF3QGtb8wlB5prRmRGwTPkEAuo+NH U6oJsMZgyCqJZ9sTnzZqg== X-UI-Out-Filterresults: notjunk:1; V01:K0:i1Hg2xPLFSo=:+3IailuRpGyVfd6r8IkZMJ hlXDsjQaONwwDcDA9E6Oo2jsGAd20r4zOXALkMu4B7SeEd7F/HctvdlqJJRjaEG95QGoUjFEb YXS+I3eEauiaKRqSX/E4aKqZ3T5lCYgFsM3gFaWewY+wnTlnYfA6vitY4W7L7MZ8SCQ9lclCz ayM+KL9fz/afZjF7zewuiJKTmkEhxNr/tR126mVJmiuSl8H5kZJ+vg+VO2akXZxkAkr1O9GUP TbPthqV7BK3XqvsQMBD+Qe5/EN0tKIlyvAqxW1+dVsIdUUZysIs2uy83rfQUxkdYNXP881v4F Jnu+si9kLDFACqfcJhPFwcdkEd1ZFPy73r9Szli8Sp6JZ/EXvUD6BcyTTp4uFvLuTn5ZqfObQ gUmAMR8j00wtdXg2vutI/0PzaS03rYDq1QZDL5/gPZTMKkNcfslJD7eb/EnCs5m0UX75nD6cY Q3yysfjvpFgg2IQTRN9xh+SBwGx00Xe/HoJbZFaFzlpTv8KBd2FgBB1/C1sKb9JI+uRaI5RJ6 WtjJqYGd9ZwpSPHZtCbnGYHisRoxRMWrmjOrBYjR6uQSqtVhYBzFVXQOQmeHKDU2iNjCjHlwO hnSxNi7Vv9D/25buhNTk51HeAyg+tR1we+Rwq8LcIP3rcAwOii+AVtjLsymrqfzeP1SQkgK9D I/sRndkfN0e/PSXAtODZACNkXsr1zXgJ3GcpwnvhUZhQRLKI2ExRIfhHBoaGmPe73rrbUhRj1 /K0+LYdx5ImQ9MyBtmbWMyBKcwVT8k3x4F73ByuKSB0bP0oH1TZtKTb/m1tAYRattbnXjQilF e7EwgOG 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: Sat, 10 Dec 2016 09:29:24 +0100 The kfree() function was called in one case by the bttv_input_init() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software. * Split a condition check for resource allocation failures so that each pointer from these function calls will be checked immediately. See also background information: Topic "CWE-754: Improper check for unusual or exceptional conditions" Link: https://cwe.mitre.org/data/definitions/754.html Fixes: d8b4b5822f51e2142b731b42c81e3f03eec475b2 ("[media] ir-core: make struct rc_dev the primary interface") * Adjust a jump target according to the Linux coding style convention. * Delete an initialisation for the variable "err" at the beginning which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/media/pci/bt8xx/bttv-input.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/media/pci/bt8xx/bttv-input.c b/drivers/media/pci/bt8xx/bttv-input.c index 4da720e4867e..9187993d23ea 100644 --- a/drivers/media/pci/bt8xx/bttv-input.c +++ b/drivers/media/pci/bt8xx/bttv-input.c @@ -418,15 +418,20 @@ int bttv_input_init(struct bttv *btv) struct bttv_ir *ir; char *ir_codes = NULL; struct rc_dev *rc; - int err = -ENOMEM; + int err; if (!btv->has_remote) return -ENODEV; - ir = kzalloc(sizeof(*ir),GFP_KERNEL); + ir = kzalloc(sizeof(*ir), GFP_KERNEL); + if (!ir) + return -ENOMEM; + rc = rc_allocate_device(); - if (!ir || !rc) - goto err_out_free; + if (!rc) { + err = -ENOMEM; + goto free_ir; + } /* detect & configure */ switch (btv->c.type) { @@ -569,6 +574,7 @@ int bttv_input_init(struct bttv *btv) btv->remote = NULL; err_out_free: rc_free_device(rc); +free_ir: kfree(ir); return err; }