Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2908195pxb; Tue, 24 Aug 2021 10:20:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxr55ESjQyY24kHfILv13u3KiBPmSX3KZyfwtFjeyNE7WFRxxcJkQk9idqmECYGqG9Yj8Zq X-Received: by 2002:a17:906:c251:: with SMTP id bl17mr41766770ejb.219.1629825657753; Tue, 24 Aug 2021 10:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825657; cv=none; d=google.com; s=arc-20160816; b=UXEWasjQs6NIRNk27CXFI98KojiuvTWA9AoJ6/qsogArAdpNhwdCC7CGbYaWAPIEFj frGwTTAuaqLCeJKi+XP4wp4UI1S3Pi5E3PAYYquAo1/ArOp/00VPXirBBMRr2lIgn5wV mRaYnKOZ1HEMWZGSUY5h00w6Jzm9PsBV5KHRfmK4ozSe1pcaze8WdPgbz+jbgSidPxGX hCybKMF2C1QJc1/Jvh8CuTIAjNRnT/cmxqMsmmdh9uij0/7ZyzWwVAs2qiXAwfsIMk5c gE4jfkoiqt8jLCrsrck5+GegnPY/FNOstJZti4rOGrV1hLKgSeApw1QQJTo1yVWYdgNN VSnA== 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=OW1GC7HDUaFfdMiFblRf7vc9Y3DIF++0tYPALkpmSwA=; b=lmOH+Lpwg2I5ZT/XUn9G3SVA7Od6sbyVLLOVBZsa2RNhIgsJLA4RTfKjdUCfutUu2i lJ+v6+671LJVGq3kpxhEjUgx0KFvwiNA4MhUDKKg5hjg3b3+bjfNhvPRENbgIs/IW6ju 6+wVENlB0twDLRwKjviJge6U6mPcQCi79WshYHFHTzfe6MtK+h7rs3Rj68Rr+guKRYl6 cslwB7Xmo1Ww3kipyrcPe45czcOD0ZauT7HJgLtYd2Q+npznYhGKSydm9AiRPhliW0EV ESaY+6AN94z5POw0a+uq0l2oxyHFMvBfXwQ43PsnXLnHEG/zcHqtts5dTF4qOrs/+6ml 8VRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NiIv50nl; 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 c9si398784edt.514.2021.08.24.10.20.33; Tue, 24 Aug 2021 10:20:57 -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=NiIv50nl; 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 S239194AbhHXRTF (ORCPT + 99 others); Tue, 24 Aug 2021 13:19:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:55922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240259AbhHXRRI (ORCPT ); Tue, 24 Aug 2021 13:17:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B11B261AA4; Tue, 24 Aug 2021 17:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824520; bh=3Q4fhlu4hFPxUNq9Co6iONT+mWByRjAo6gKaq5po0cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NiIv50nlqamvmyNo1plhq3n8j8OVTdP/FJcO7SebkcGHdz5K/KRuxLt19Q8h+Ap3T 4+Y7MnM5tbuFPAM9ssi6RSjexpvFwP7AvhRdgjcwZLGpwDyi/9pDokZFaCTG79RiNZ YiD9kdmOGoSTca9DRTgFYscnCchZ1SFuo59ExSDLPHCFT5R1AbB/71uY9Pk8AqvTD9 BxWOAhXVzBYKVl2Av+o6o1UaAL3B26U07EtHUYilkTv3I0kr2KolrcinryvsdMGhZ8 +utkJ8A9G7USb/fsvPWUZuxSIhe4oNqx3Mr0n0nvtA3BMrtAsLG+ix5KbFs0Cc5EQC esl/9zaLHqYKQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dongliang Mu , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.4 53/61] ipack: tpci200: fix memory leak in the tpci200_register Date: Tue, 24 Aug 2021 13:00:58 -0400 Message-Id: <20210824170106.710221-54-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170106.710221-1-sashal@kernel.org> References: <20210824170106.710221-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.143-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.4.143-rc1 X-KernelTest-Deadline: 2021-08-26T17:01+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 80cd0150f592..46665b1cef85 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