Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2903382pxb; Tue, 24 Aug 2021 10:14:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9Yq2WCwnlcrg45oH2FSKqppCAwpKyeWjdGXbqyKruJmGqcuQnmC4uW6yUjEMJXRf25xUY X-Received: by 2002:aa7:db8b:: with SMTP id u11mr43599483edt.362.1629825276802; Tue, 24 Aug 2021 10:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825276; cv=none; d=google.com; s=arc-20160816; b=qaxFZRubnEKIyRE4TxYqBtmOnSqgKwGhtOe2C31DV9fPAi71GyOI2mbMQ5aQ0QNHp6 0VJDftzaFNkNE+El++vGy1RLOl1cDvvRf3uZLufubVjkZ6j4PvIbkItDpJNkbo9ik9So q7tkFPU3KSof/qNWUCAA4/qN/5ZAeE17CZqZI67nNRRgAyZgkCX5iaQ1L2qlfThEq7vP LWisRabhg5830Ps4r/EC6cTM9ClVo4N8pxXDiKFmKdD9DWUUwrLrz+fs2lc+OeZder2m N5Fz6g54+gFtVIeghupaT9zbMUMYBYt1Fwud+4QG5mwtJ0RZLR1QkW26GU2rYlcC9pRv I3Dg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4rRAPCUFZ2boFCTBcQ2CUEYtRwHUGpTDcix7As1qhOY=; b=uS1zDK+kavMJqbL0hDZNb2nJjBkmIAFOX6LGbXKC6Pze///wRnKdXjuwE84/5eiuyM B615OM0kiUzCOCSgFPIYStmqRwT0vmG3/H7vJcwt2up6f/ZKSzZWWHIRib2+1SwrIi70 Td1KtXB7Xs+ZH6bu23HOKTr0E9jRT90EIPH8z64N2MI2G2O/cwYKL6M1Zg5yqLlKFf9+ ZN1/wwNCEchXVITorT0uinUIwQUZz4mXDKfOKyKKZ8/OQAR1hkPcf8dK+kUyVXDfZ854 X7dfONYpq4ZJuH7ymkAEvrw4DmPyEYsFQgHz2PGWzpD55I813IAzZBM3Xc0tQw/WspB+ PlHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X3A4qkdT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e12si16950290ejk.703.2021.08.24.10.14.10; Tue, 24 Aug 2021 10:14:36 -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=k20201202 header.b=X3A4qkdT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239981AbhHXRNY (ORCPT + 99 others); Tue, 24 Aug 2021 13:13:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:52016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240177AbhHXRKM (ORCPT ); Tue, 24 Aug 2021 13:10:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9A20861452; Tue, 24 Aug 2021 17:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824433; bh=IBS659XqIUQKtV/xJFd6tq5k6v9GnO8pnjpKLmyx/g8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X3A4qkdTATHqOkC9QsqXpfW3cM0zLu4mSJ3WJgqbCTJIGocWuFTvi5s3HnH1p9KQb iVUSTLr467bXUcJJ8I5A84FPZqXvAIKRB0vWQ5DZqr5G8ZNV5bPLW2RzrRgRBcyfMX yhq/C9gSOjM7ZGtxM59IZtgXXUsVHwNIYMhe6ZZWDV5ABKMCRDoq5onGBLyHSGuIDn EV70ldZVmsLjxIS6bdbvtC4wYwfXGMBQ9rVc3HsZd5T9EFqePV56hfc4pG/zI4oI4P dC1lr9sw4Tm1dY3WIqeVFVVODfPYKTlcsAoyWYI1tZPgP+yVFHPxptQBSVSD4XXito Mzq09jNaG0Pog== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dongliang Mu , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.10 84/98] ipack: tpci200: fix memory leak in the tpci200_register Date: Tue, 24 Aug 2021 12:58:54 -0400 Message-Id: <20210824165908.709932-85-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165908.709932-1-sashal@kernel.org> References: <20210824165908.709932-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.61-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.10.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.10.61-rc1 X-KernelTest-Deadline: 2021-08-26T16:58+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu [ Upstream commit 50f05bd114a46a74726e432bf81079d3f13a55b7 ] The error handling code in tpci200_register does not free interface_regs allocated by ioremap and the current version of error handling code is problematic. Fix this by refactoring the error handling code and free interface_regs when necessary. Fixes: 43986798fd50 ("ipack: add error handling for ioremap_nocache") Cc: stable@vger.kernel.org Reported-by: Dongliang Mu Signed-off-by: Dongliang Mu Link: https://lore.kernel.org/r/20210810100323.3938492-2-mudongliangabcd@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/ipack/carriers/tpci200.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/ipack/carriers/tpci200.c b/drivers/ipack/carriers/tpci200.c index 33a1b17a2628..c1098f40e03f 100644 --- a/drivers/ipack/carriers/tpci200.c +++ b/drivers/ipack/carriers/tpci200.c @@ -256,7 +256,7 @@ static int tpci200_register(struct tpci200_board *tpci200) "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 2 !", tpci200->info->pdev->bus->number, tpci200->info->pdev->devfn); - goto out_disable_pci; + goto err_disable_device; } /* Request IO ID INT space (Bar 3) */ @@ -268,7 +268,7 @@ static int tpci200_register(struct tpci200_board *tpci200) "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 3 !", tpci200->info->pdev->bus->number, tpci200->info->pdev->devfn); - goto out_release_ip_space; + goto err_ip_interface_bar; } /* Request MEM8 space (Bar 5) */ @@ -279,7 +279,7 @@ static int tpci200_register(struct tpci200_board *tpci200) "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 5!", tpci200->info->pdev->bus->number, tpci200->info->pdev->devfn); - goto out_release_ioid_int_space; + goto err_io_id_int_spaces_bar; } /* Request MEM16 space (Bar 4) */ @@ -290,7 +290,7 @@ static int tpci200_register(struct tpci200_board *tpci200) "(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 4!", tpci200->info->pdev->bus->number, tpci200->info->pdev->devfn); - goto out_release_mem8_space; + goto err_mem8_space_bar; } /* Map internal tpci200 driver user space */ @@ -304,7 +304,7 @@ static int tpci200_register(struct tpci200_board *tpci200) tpci200->info->pdev->bus->number, tpci200->info->pdev->devfn); res = -ENOMEM; - goto out_release_mem8_space; + goto err_mem16_space_bar; } /* Initialize lock that protects interface_regs */ @@ -343,18 +343,22 @@ static int tpci200_register(struct tpci200_board *tpci200) "(bn 0x%X, sn 0x%X) unable to register IRQ !", tpci200->info->pdev->bus->number, tpci200->info->pdev->devfn); - goto out_release_ioid_int_space; + goto err_interface_regs; } return 0; -out_release_mem8_space: +err_interface_regs: + pci_iounmap(tpci200->info->pdev, tpci200->info->interface_regs); +err_mem16_space_bar: + pci_release_region(tpci200->info->pdev, TPCI200_MEM16_SPACE_BAR); +err_mem8_space_bar: pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR); -out_release_ioid_int_space: +err_io_id_int_spaces_bar: pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR); -out_release_ip_space: +err_ip_interface_bar: pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR); -out_disable_pci: +err_disable_device: pci_disable_device(tpci200->info->pdev); return res; } -- 2.30.2