Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2895213pxb; Tue, 24 Aug 2021 10:04:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWvuVNErSp9sWLncuniWWGIJ9aQLNRzq9jOmrUb77clXG+dwBz32+wb7mqrP/90qbbZcFf X-Received: by 2002:a02:866b:: with SMTP id e98mr36151425jai.48.1629824650545; Tue, 24 Aug 2021 10:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629824650; cv=none; d=google.com; s=arc-20160816; b=J0GL60Jg5zDH4MG/0VVNIEtV9PaduWT3rFBvfOfvGCZxntz98dMfC+1RYFhMqDn3Ix PfJjM7cwIN+BjUKcPMlh1P/+iQ53nyChNKauKgI77WpzLmlAUdTKzFqPnnwAe58yma3b r8/Ld8TDdkR5pURESLcy5X8RbqM1hqTLyLCReea8tgrN9UsrO3RKoIDvClL79a2JFi6J KH05umPnLs8sVk1nVNcdeI09k81khmvdx/IdKCV2xlYb7G7DR+jwGBHZEWgtc0AbhIkZ nqLNq+m1+XWCYDBXmPEWXdzLjCQVgxrs5hUcsH3PJxfAPyV5CB5r66YPFMcwPAo3kbao 3tvg== 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=VrsI8nb3sxEjjA9m04njXvO/206Lu9THEy1YKbBYmQ+QUBLSvkT+pNR7nypOr/+mUj es9NUaHJC06EBnkf/094BKeawL6f+6r0RNhAmugXNxj1OufrO5XTiycl3Jh3KAGAlie2 9ac3aqYzT4YDNn2VXFwO2hNowEbMKc2kLsHo4AWZwrLUpGEm2jgqj/Qh00e6PKdokE7f uVFy30kETXDSpR183jyIUY2iSmvYmE92vrttaR8yky2o36mI1rE8svLZywHKROAlbWyr 5w6Og9uDQaaEs3uV5eFK+FFugRvCq2tMsIXMHZHncoVOr+W89pZGFa8JgQOy8Fk2qbfA 863g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IZ0fuZGJ; 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 f11si17917509iok.80.2021.08.24.10.03.40; Tue, 24 Aug 2021 10:04:10 -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=IZ0fuZGJ; 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 S238923AbhHXRDj (ORCPT + 99 others); Tue, 24 Aug 2021 13:03:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:39686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238603AbhHXRAY (ORCPT ); Tue, 24 Aug 2021 13:00:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 11F8D6152B; Tue, 24 Aug 2021 16:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824267; bh=IBS659XqIUQKtV/xJFd6tq5k6v9GnO8pnjpKLmyx/g8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IZ0fuZGJBguDtfcY17TWVJ7lq7wbH+dbaP/p/2l8sfyYyD2L0D7EWApk9dFMiVnEz 63ZKENnCnC6sDtAVlLPFUzZmQXAMq/GWTmxEX0dNwO3XliQKLqzoSR7XHa7G87hZUw vgi5hWq3DuaEWA3OR4e57ycGsSb+Ds1jiRERf5yWHXNpMcAnriw6OpQhIbu1Gv8lLl nJrC6kHLQawqm+24qs6K2YruFw7Jv5akyKz+mpwphESMtaBzybhec//NCkF4w6iJpQ cB7Zrry2Vkf92NK0b4daVEBbUweqhdLy65cYP+dy77jojuLW4hR+ocX/dBPBiKOvwS ejB6T2zt6vT/A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dongliang Mu , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.13 101/127] ipack: tpci200: fix memory leak in the tpci200_register Date: Tue, 24 Aug 2021 12:55:41 -0400 Message-Id: <20210824165607.709387-102-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165607.709387-1-sashal@kernel.org> References: <20210824165607.709387-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.13.13-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.13.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.13.13-rc1 X-KernelTest-Deadline: 2021-08-26T16:55+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