Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp164936pxx; Wed, 28 Oct 2020 01:17:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgzIGIsnXj1h1psoTHttbWedVRPXznoe/IIMMQlQxXBFeUgtwxunHwhHsql3aG2EktvXHp X-Received: by 2002:a50:d805:: with SMTP id o5mr6567084edj.142.1603873053213; Wed, 28 Oct 2020 01:17:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603873053; cv=none; d=google.com; s=arc-20160816; b=RqU7yliWwgioA4Ng/c/nu28VMKqLG8G/nJTlB7ZjtnMx3vg/oHDaihco2kObvrNm70 UNUAi42oJAqaLowuaMX6iKAu1DVdXWvEx/Bt6sDhlBGupOsUl69GYaksY1V4JhKYhMqa sCtiOZd+BEbQiywQ170A/ay7D/b18Hv97eDa86pvGJ3gbYzW3EXMUAg0TWpxzhtlmWS0 R6A5JtnvFy518cvykbWrTIt+vQKdonOQm2uoQPhRlpUg8mqf9gwCBNRDFGiMzDCMq19C YVMDrIQC4h4F9EymLX2yjQZrkeGZYqHr6oSE11O3dI8XZnNGD9dCZ+1HvOHjU0aCIqXR ag/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uLxoYj3wXel3fWOx8+VqT1uxf84AEuH8J/FcgrPW4/4=; b=i8UbBsn1by5kkAaztUPjyc8ntbrvlubftBkIaijGuviSLyC3ZwPS0J8qtK3EgnaQ3l /USphHHlkFkzfmLGPFyqmDySv2KcA1AdKzUDKKnTyd8H67vdJfXqPw9hCJ7d3yGAISQ2 VlUG1FWN2L2gVIhYhfuNQPeKy09TgUdG4MRCO0fTziRvu4E9rhktgyr+ckho8WpzJMR0 MGyui1y6iFSlHllyUi8JTMgiuOhI1p2D3dzj54xvpC6mXhdVf1CMG4u4s4mPlv8sjqmG tXvbtHNDS5Iqcg35OZW+CwZOtNZf3Z7ozyDR3AvDYu/m3jBij3ToPxQ09ncTLY+wMYvI Kz3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R3+JHsIw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gf17si2900638ejb.226.2020.10.28.01.17.10; Wed, 28 Oct 2020 01:17:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R3+JHsIw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753654AbgJ0OBT (ORCPT + 99 others); Tue, 27 Oct 2020 10:01:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:47666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2411651AbgJ0OAM (ORCPT ); Tue, 27 Oct 2020 10:00:12 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7F7392068D; Tue, 27 Oct 2020 14:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807212; bh=48/ROL0ZxjWmq5FTb8/M9d7rMnjGK4fTPh4kuFxn3Mo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R3+JHsIwN17hp3MyAniRAHkheCEx2WgxrTfBTIEKFKzNMP2e6s5doqHzmqbf1msZO aoXBeZUxhXy1dmD54FCSwWfV0X2WW5N0+ah2c7vfTzN+TjZkYyeNfBknHqVtVdmgoC 1m6BEcNqMDIgU/JVcXnaXyOjCaQwDNBX4u06eRlc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaolong Huang , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.4 083/112] media: media/pci: prevent memory leak in bttv_probe Date: Tue, 27 Oct 2020 14:49:53 +0100 Message-Id: <20201027134904.474055851@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaolong Huang [ Upstream commit 7b817585b730665126b45df5508dd69526448bc8 ] In bttv_probe if some functions such as pci_enable_device, pci_set_dma_mask and request_mem_region fails the allocated memory for btv should be released. Signed-off-by: Xiaolong Huang Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/pci/bt8xx/bttv-driver.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c index 51dbef2f9a489..10c9c078af014 100644 --- a/drivers/media/pci/bt8xx/bttv-driver.c +++ b/drivers/media/pci/bt8xx/bttv-driver.c @@ -4053,11 +4053,13 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) btv->id = dev->device; if (pci_enable_device(dev)) { pr_warn("%d: Can't enable device\n", btv->c.nr); - return -EIO; + result = -EIO; + goto free_mem; } if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) { pr_warn("%d: No suitable DMA available\n", btv->c.nr); - return -EIO; + result = -EIO; + goto free_mem; } if (!request_mem_region(pci_resource_start(dev,0), pci_resource_len(dev,0), @@ -4065,7 +4067,8 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) pr_warn("%d: can't request iomem (0x%llx)\n", btv->c.nr, (unsigned long long)pci_resource_start(dev, 0)); - return -EBUSY; + result = -EBUSY; + goto free_mem; } pci_set_master(dev); pci_set_command(dev); @@ -4251,6 +4254,10 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) release_mem_region(pci_resource_start(btv->c.pci,0), pci_resource_len(btv->c.pci,0)); pci_disable_device(btv->c.pci); + +free_mem: + bttvs[btv->c.nr] = NULL; + kfree(btv); return result; } -- 2.25.1