Skip to content

Commit 6eb1e8e

Browse files
cuiyunhuiwilldeacon
authored andcommitted
perf/dwc_pcie: fix some unreleased resources
Release leaked resources, such as plat_dev and dev_info. Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com> Reviewed-by: Shuai Xue <xueshuai@linux.alibaba.com> Link: https://lore.kernel.org/r/20250220121716.50324-2-cuiyunhui@bytedance.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 678a5d3 commit 6eb1e8e

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

drivers/perf/dwc_pcie_pmu.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,10 @@ static int dwc_pcie_register_dev(struct pci_dev *pdev)
572572
return PTR_ERR(plat_dev);
573573

574574
dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
575-
if (!dev_info)
575+
if (!dev_info) {
576+
platform_device_unregister(plat_dev);
576577
return -ENOMEM;
578+
}
577579

578580
/* Cache platform device to handle pci device hotplug */
579581
dev_info->plat_dev = plat_dev;
@@ -730,6 +732,15 @@ static struct platform_driver dwc_pcie_pmu_driver = {
730732
.driver = {.name = "dwc_pcie_pmu",},
731733
};
732734

735+
static void dwc_pcie_cleanup_devices(void)
736+
{
737+
struct dwc_pcie_dev_info *dev_info, *tmp;
738+
739+
list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node) {
740+
dwc_pcie_unregister_dev(dev_info);
741+
}
742+
}
743+
733744
static int __init dwc_pcie_pmu_init(void)
734745
{
735746
struct pci_dev *pdev = NULL;
@@ -742,7 +753,7 @@ static int __init dwc_pcie_pmu_init(void)
742753
ret = dwc_pcie_register_dev(pdev);
743754
if (ret) {
744755
pci_dev_put(pdev);
745-
return ret;
756+
goto err_cleanup;
746757
}
747758
}
748759

@@ -751,35 +762,35 @@ static int __init dwc_pcie_pmu_init(void)
751762
dwc_pcie_pmu_online_cpu,
752763
dwc_pcie_pmu_offline_cpu);
753764
if (ret < 0)
754-
return ret;
765+
goto err_cleanup;
755766

756767
dwc_pcie_pmu_hp_state = ret;
757768

758769
ret = platform_driver_register(&dwc_pcie_pmu_driver);
759770
if (ret)
760-
goto platform_driver_register_err;
771+
goto err_remove_cpuhp;
761772

762773
ret = bus_register_notifier(&pci_bus_type, &dwc_pcie_pmu_nb);
763774
if (ret)
764-
goto platform_driver_register_err;
775+
goto err_unregister_driver;
765776
notify = true;
766777

767778
return 0;
768779

769-
platform_driver_register_err:
780+
err_unregister_driver:
781+
platform_driver_unregister(&dwc_pcie_pmu_driver);
782+
err_remove_cpuhp:
770783
cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state);
771-
784+
err_cleanup:
785+
dwc_pcie_cleanup_devices();
772786
return ret;
773787
}
774788

775789
static void __exit dwc_pcie_pmu_exit(void)
776790
{
777-
struct dwc_pcie_dev_info *dev_info, *tmp;
778-
779791
if (notify)
780792
bus_unregister_notifier(&pci_bus_type, &dwc_pcie_pmu_nb);
781-
list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node)
782-
dwc_pcie_unregister_dev(dev_info);
793+
dwc_pcie_cleanup_devices();
783794
platform_driver_unregister(&dwc_pcie_pmu_driver);
784795
cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state);
785796
}

0 commit comments

Comments
 (0)