Skip to content

Commit 670e304

Browse files
cuiyunhuijfvogel
authored andcommitted
perf/dwc_pcie: fix some unreleased resources
[ Upstream commit 6eb1e8ef586ac4a3dcdc20248f9cb45e4ceb141f ] Release leaked resources, such as plat_dev and dev_info. Signed-off-by: Yunhui Cui <[email protected]> Reviewed-by: Shuai Xue <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 89a4db7a67e707533d20649fc4eaa2fcbf29472a) Signed-off-by: Jack Vogel <[email protected]>
1 parent 2e2cbe5 commit 670e304

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
@@ -568,8 +568,10 @@ static int dwc_pcie_register_dev(struct pci_dev *pdev)
568568
return PTR_ERR(plat_dev);
569569

570570
dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
571-
if (!dev_info)
571+
if (!dev_info) {
572+
platform_device_unregister(plat_dev);
572573
return -ENOMEM;
574+
}
573575

574576
/* Cache platform device to handle pci device hotplug */
575577
dev_info->plat_dev = plat_dev;
@@ -725,6 +727,15 @@ static struct platform_driver dwc_pcie_pmu_driver = {
725727
.driver = {.name = "dwc_pcie_pmu",},
726728
};
727729

730+
static void dwc_pcie_cleanup_devices(void)
731+
{
732+
struct dwc_pcie_dev_info *dev_info, *tmp;
733+
734+
list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node) {
735+
dwc_pcie_unregister_dev(dev_info);
736+
}
737+
}
738+
728739
static int __init dwc_pcie_pmu_init(void)
729740
{
730741
struct pci_dev *pdev = NULL;
@@ -737,7 +748,7 @@ static int __init dwc_pcie_pmu_init(void)
737748
ret = dwc_pcie_register_dev(pdev);
738749
if (ret) {
739750
pci_dev_put(pdev);
740-
return ret;
751+
goto err_cleanup;
741752
}
742753
}
743754

@@ -746,35 +757,35 @@ static int __init dwc_pcie_pmu_init(void)
746757
dwc_pcie_pmu_online_cpu,
747758
dwc_pcie_pmu_offline_cpu);
748759
if (ret < 0)
749-
return ret;
760+
goto err_cleanup;
750761

751762
dwc_pcie_pmu_hp_state = ret;
752763

753764
ret = platform_driver_register(&dwc_pcie_pmu_driver);
754765
if (ret)
755-
goto platform_driver_register_err;
766+
goto err_remove_cpuhp;
756767

757768
ret = bus_register_notifier(&pci_bus_type, &dwc_pcie_pmu_nb);
758769
if (ret)
759-
goto platform_driver_register_err;
770+
goto err_unregister_driver;
760771
notify = true;
761772

762773
return 0;
763774

764-
platform_driver_register_err:
775+
err_unregister_driver:
776+
platform_driver_unregister(&dwc_pcie_pmu_driver);
777+
err_remove_cpuhp:
765778
cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state);
766-
779+
err_cleanup:
780+
dwc_pcie_cleanup_devices();
767781
return ret;
768782
}
769783

770784
static void __exit dwc_pcie_pmu_exit(void)
771785
{
772-
struct dwc_pcie_dev_info *dev_info, *tmp;
773-
774786
if (notify)
775787
bus_unregister_notifier(&pci_bus_type, &dwc_pcie_pmu_nb);
776-
list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node)
777-
dwc_pcie_unregister_dev(dev_info);
788+
dwc_pcie_cleanup_devices();
778789
platform_driver_unregister(&dwc_pcie_pmu_driver);
779790
cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state);
780791
}

0 commit comments

Comments
 (0)