From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF76EC3600B for ; Mon, 31 Mar 2025 14:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=U2z6fsWUMuqyteuduVvlyJnAMML7TtExuMwlK70laME=; b=mlhP8U6ojFjW8Y78atUIFPIIKM wOSQeED2UlMvU0+Pzc3+/TeVT1rCXYtvC9VT6M/mAb+kvkOE/VzqZJ9KRzFjSa7ap82eaeATvNJeM ITmuhKyLMNkcpsQuI0DFmeEi2f5krl1EEvFn0Idn47JHUm0MKKsgF6DqH2wYg/TZe+HsIJJ0E6l45 tuc2K3vABDjk9qHLy4oNlg4EvrxRgb0gUMoUzZh54W86GgMki9LFCIrLbV/TwW4WJfb2upE5Rcd3y qgbtCOn5IfGuph9VFqAnEj6qXsTQuop42kWmuMI4OtRHC2E0Liv91pT4SWNCy0gc6KX7tmOe+Gvh5 iQ8HFGMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzGT3-00000000dIG-2HHM; Mon, 31 Mar 2025 14:50:25 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzGEL-00000000Zjt-3Ps6 for linux-arm-kernel@lists.infradead.org; Mon, 31 Mar 2025 14:35:15 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 486305C5714; Mon, 31 Mar 2025 14:32:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C423CC4CEE3; Mon, 31 Mar 2025 14:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743431712; bh=JqI6exjjN8uxNSKa+vUX2BGVkSh6tDPWGkpGiWMorQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B6hu8dG6fOQesGYuvhwLnJt5UPt5VVkFKreGvalRoV9v4wXmAzQUGxa9fkuPXGa2A 8pSwEIqaSo5glkLJlXyURK82Ehz3rrU+hfBgIa4EHXdDap22khk5Gl+LsLqM1sxtpH d4zsRWhFtQJEpom03CTn2HipAxHalhR6XCjOJsckOnl4mW7fPTALXfcmJpLzRDcgcm v0ny3fogj35eEOSyk+lMumRl++a0gVmxfZukC7LPxNKdG/96eK9SsZKyQjpfK6UOQc SAojrHSxAlWx+dKwRrgImy+R+u3pOaUBHFBSxq/X0RJgdYODNoJMhrFZgKwTtTlSOl L5g4PdTEAVjaA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yunhui Cui , Shuai Xue , Will Deacon , Sasha Levin , renyu.zj@linux.alibaba.com, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Subject: [PATCH AUTOSEL 6.13 09/16] perf/dwc_pcie: fix some unreleased resources Date: Mon, 31 Mar 2025 10:34:43 -0400 Message-Id: <20250331143450.1685242-9-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250331143450.1685242-1-sashal@kernel.org> References: <20250331143450.1685242-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.13.9 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250331_073513_940859_1251F7C2 X-CRM114-Status: GOOD ( 15.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Yunhui Cui [ Upstream commit 6eb1e8ef586ac4a3dcdc20248f9cb45e4ceb141f ] Release leaked resources, such as plat_dev and dev_info. Signed-off-by: Yunhui Cui Reviewed-by: Shuai Xue Link: https://lore.kernel.org/r/20250220121716.50324-2-cuiyunhui@bytedance.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/perf/dwc_pcie_pmu.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c index 9cbea9675e21a..a7e7864e73a8e 100644 --- a/drivers/perf/dwc_pcie_pmu.c +++ b/drivers/perf/dwc_pcie_pmu.c @@ -567,8 +567,10 @@ static int dwc_pcie_register_dev(struct pci_dev *pdev) return PTR_ERR(plat_dev); dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL); - if (!dev_info) + if (!dev_info) { + platform_device_unregister(plat_dev); return -ENOMEM; + } /* Cache platform device to handle pci device hotplug */ dev_info->plat_dev = plat_dev; @@ -724,6 +726,15 @@ static struct platform_driver dwc_pcie_pmu_driver = { .driver = {.name = "dwc_pcie_pmu",}, }; +static void dwc_pcie_cleanup_devices(void) +{ + struct dwc_pcie_dev_info *dev_info, *tmp; + + list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node) { + dwc_pcie_unregister_dev(dev_info); + } +} + static int __init dwc_pcie_pmu_init(void) { struct pci_dev *pdev = NULL; @@ -736,7 +747,7 @@ static int __init dwc_pcie_pmu_init(void) ret = dwc_pcie_register_dev(pdev); if (ret) { pci_dev_put(pdev); - return ret; + goto err_cleanup; } } @@ -745,35 +756,35 @@ static int __init dwc_pcie_pmu_init(void) dwc_pcie_pmu_online_cpu, dwc_pcie_pmu_offline_cpu); if (ret < 0) - return ret; + goto err_cleanup; dwc_pcie_pmu_hp_state = ret; ret = platform_driver_register(&dwc_pcie_pmu_driver); if (ret) - goto platform_driver_register_err; + goto err_remove_cpuhp; ret = bus_register_notifier(&pci_bus_type, &dwc_pcie_pmu_nb); if (ret) - goto platform_driver_register_err; + goto err_unregister_driver; notify = true; return 0; -platform_driver_register_err: +err_unregister_driver: + platform_driver_unregister(&dwc_pcie_pmu_driver); +err_remove_cpuhp: cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state); - +err_cleanup: + dwc_pcie_cleanup_devices(); return ret; } static void __exit dwc_pcie_pmu_exit(void) { - struct dwc_pcie_dev_info *dev_info, *tmp; - if (notify) bus_unregister_notifier(&pci_bus_type, &dwc_pcie_pmu_nb); - list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node) - dwc_pcie_unregister_dev(dev_info); + dwc_pcie_cleanup_devices(); platform_driver_unregister(&dwc_pcie_pmu_driver); cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state); } -- 2.39.5