Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1122073pxx; Tue, 27 Oct 2020 08:45:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx82nRNHQccNdLaonDdj1CuYy+rIgvuZQJGvYc397CjMBLLaOj59BU5XkzP5nzFvnIsiGYs X-Received: by 2002:a17:906:7016:: with SMTP id n22mr3128909ejj.402.1603813516690; Tue, 27 Oct 2020 08:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603813516; cv=none; d=google.com; s=arc-20160816; b=FDxI09FzYIyNC8NX2ll7Z6eYYReNoLq9cCQwxCZnFTr013Znwy/9RXFPRTI8MJRWfw x5hp1niEPEkEZMt3PQQlCz6yPCYLMAYii6PmsWxcmQBkTGoIB97loZqRaqileW7++Ckr fS+67zGHay+tfgfpJIqBPDzG/41S8hoKO/I8ayDeE6VNT4WDu0vRx7JxMpRkCgjFvvla wyKtGLZ7/Y1LsoxghS/WkZzuF0CGtq0Jtod+X5vHTT/vE/HhllmOZ7l+JG+MHTy074Q2 4zMsPPHG67GiBvHcnH3egDIg/0SAX/RutZXeglWVTG+9n2noH+DWi6nwm8FGPv+BrO9a Zbvw== 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=vXjdE6yNqdOrIN2K/FCJgFfbxppk7vvtMFh8OU9Yz0o=; b=RqizOw9ph5+uRVHR5P7GL5sbhTArWhuJvxvHKHwWudX24kyQhVdaNJ3T9fIO60FQsw 2ADb2t8GTWVJMRFvFTwZLIaCSUYu10U2xgH309FOXI+4kI4XI4E0ZcAQrKFLf3omK5kw lAiSLVEkAgz2t+aPiwEPxeXDngHGsM4FvoVFpbWDyGGgDinsaOmYOtLYws9JLRTAFmII l0iuPH5ZOymuBA2bCbI22FkrGIoKZgPAbIbBfwRGmvxKtMnG+xIyO9flC1RSHKlV1Ks2 3WqFxmNp0I1msLx6sLRzIS4mLPLQECa5C9/GbKz4UekPtqo5T+gkkf9WKvveeSUSQVoL 7Xmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rgXMAKiD; 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 x2si1502141ejy.740.2020.10.27.08.44.53; Tue, 27 Oct 2020 08:45:16 -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=rgXMAKiD; 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 S1763772AbgJ0Oou (ORCPT + 99 others); Tue, 27 Oct 2020 10:44:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:44006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762705AbgJ0OoI (ORCPT ); Tue, 27 Oct 2020 10:44:08 -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 19EC3206E5; Tue, 27 Oct 2020 14:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809847; bh=jTrFZs9DIx+gxbsNBqwlk6WWIe4DLgg7bsS91k+8FkU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rgXMAKiDrwmCzzq8Mp4uAh7eEyuSmE0YBWVD5Zfxbn5pHYsfXwB8aNRcaNjf9/fkd wGDllNswAU7urv3lTcssKiGSnF+PubNwAiI4eVpC6cHGSBkpYHwA+TEC5H3Bpk4aOK BFxy77SeolCKlr+LfQwaFys54NlJ9EiKvPBRo1c0= 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 5.4 340/408] media: media/pci: prevent memory leak in bttv_probe Date: Tue, 27 Oct 2020 14:54:38 +0100 Message-Id: <20201027135510.803288539@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 a359da7773a90..ff2962cea6164 100644 --- a/drivers/media/pci/bt8xx/bttv-driver.c +++ b/drivers/media/pci/bt8xx/bttv-driver.c @@ -4013,11 +4013,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), @@ -4025,7 +4027,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); @@ -4211,6 +4214,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