Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp584350pxx; Wed, 28 Oct 2020 11:42:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLV2kLy47yPyLxK7kIFbRKi2oHFUt3vM7bW3sGt/7aTUvt0wVeVnmfnP1vO2VW1/u0pzdH X-Received: by 2002:aa7:c815:: with SMTP id a21mr275929edt.166.1603910559097; Wed, 28 Oct 2020 11:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603910559; cv=none; d=google.com; s=arc-20160816; b=xGr3Dw4joDqCBDeRc5yuvf5UwKnHkq5bCVawNRvygjHxUjJiratgplSbL/1TNdcp9U 6DLWrPt/OUR8D0f7F4k0egzJhAY411CGbq1DrV9wClWl7eSisuHKN0T5sg4zqW9lFlJh y0KPORe1oLeSH5L4IVvHOogwy9Wy6MPar1+YZGDwbPqgyB55RSuZNJ7fzZI+ljku6wIr IDfXx1p8NsI+WlIU4tKkSsahHP/kSVVcPcGcx/51FJ/slELb+DPdDytQWiOhVp6U1m12 C+dqMD7szr4uh0SJ3K4AbhMrOqXdgoeGlYAOmOmDD0PnjNluSnZfHTFb9sZk4vr521Bb uWlQ== 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=UezpLXFi+6vl2ICkYXj0im1ANmL9nVBbrhanF6UiobY=; b=On6D+ETl3Zsl30oOvwSA06lRrg1FOOLbwL/v6RwG8wc+InnLFLOBaPPdkT0GyxMqWD pSCJ2bMAyOYMveHCw5W5utByMW+CoG2hvNtVF/5C4sL5Jm0cgm/qCGXA72HN9w4e04fb 10CLOoE+bvX/SWy0AOdR8Gn8RZs6qsViIXEUbATRBeZ3purepL25nPhmGu5tmDyu8QDg Oe6kYu/Nimez7ASprePJxqncmNN+QdgIFVcA7vNuzAtD+xqlgSkV39L3WlUhkfYvFn+n DqI2btLV3h/PngfnB1XIuYdAZFSrVzfdVQKbsi0tZxXaA4EEguAStTDfO+fkgD5feLOP H4vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GkoPPJ3O; 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 x19si30189edq.122.2020.10.28.11.42.16; Wed, 28 Oct 2020 11:42:39 -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=GkoPPJ3O; 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 S1825723AbgJ0SNC (ORCPT + 99 others); Tue, 27 Oct 2020 14:13:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:36216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756623AbgJ0OOh (ORCPT ); Tue, 27 Oct 2020 10:14:37 -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 5B22122265; Tue, 27 Oct 2020 14:14:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603808075; bh=xVDHc69iXsYbLU/rVvI+TzvkH9zIEGHQK0rAHhXPLG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GkoPPJ3OIkQmxKZBOAi3Nv7BU9uw1jdJlrLLHFJCG1YJM8BakKGpXdJ0FY7FxjbP2 5f8BrtAtTMwUGh8QSUbxlzOAbFitZWrzQS8JVwwahoDasRBOxUr28tPhjyoFhjCtoO S1SmC5KCF4ZCA0KYhBwZjVxsnbii4LZkJFJDyT+4= 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.14 148/191] media: media/pci: prevent memory leak in bttv_probe Date: Tue, 27 Oct 2020 14:50:03 +0100 Message-Id: <20201027134916.829636028@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@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 227086a2e99c8..9e38c8b3ea762 100644 --- a/drivers/media/pci/bt8xx/bttv-driver.c +++ b/drivers/media/pci/bt8xx/bttv-driver.c @@ -4055,11 +4055,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), @@ -4067,7 +4069,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); @@ -4253,6 +4256,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