Skip to content

Commit 89a4db7

Browse files
cuiyunhuigregkh
authored andcommitted
perf/dwc_pcie: fix some unreleased resources
[ Upstream commit 6eb1e8e ] 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]>
1 parent 1b3ebfb commit 89a4db7

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

569569
dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
570-
if (!dev_info)
570+
if (!dev_info) {
571+
platform_device_unregister(plat_dev);
571572
return -ENOMEM;
573+
}
572574

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

729+
static void dwc_pcie_cleanup_devices(void)
730+
{
731+
struct dwc_pcie_dev_info *dev_info, *tmp;
732+
733+
list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node) {
734+
dwc_pcie_unregister_dev(dev_info);
735+
}
736+
}
737+
727738
static int __init dwc_pcie_pmu_init(void)
728739
{
729740
struct pci_dev *pdev = NULL;
@@ -736,7 +747,7 @@ static int __init dwc_pcie_pmu_init(void)
736747
ret = dwc_pcie_register_dev(pdev);
737748
if (ret) {
738749
pci_dev_put(pdev);
739-
return ret;
750+
goto err_cleanup;
740751
}
741752
}
742753

@@ -745,35 +756,35 @@ static int __init dwc_pcie_pmu_init(void)
745756
dwc_pcie_pmu_online_cpu,
746757
dwc_pcie_pmu_offline_cpu);
747758
if (ret < 0)
748-
return ret;
759+
goto err_cleanup;
749760

750761
dwc_pcie_pmu_hp_state = ret;
751762

752763
ret = platform_driver_register(&dwc_pcie_pmu_driver);
753764
if (ret)
754-
goto platform_driver_register_err;
765+
goto err_remove_cpuhp;
755766

756767
ret = bus_register_notifier(&pci_bus_type, &dwc_pcie_pmu_nb);
757768
if (ret)
758-
goto platform_driver_register_err;
769+
goto err_unregister_driver;
759770
notify = true;
760771

761772
return 0;
762773

763-
platform_driver_register_err:
774+
err_unregister_driver:
775+
platform_driver_unregister(&dwc_pcie_pmu_driver);
776+
err_remove_cpuhp:
764777
cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state);
765-
778+
err_cleanup:
779+
dwc_pcie_cleanup_devices();
766780
return ret;
767781
}
768782

769783
static void __exit dwc_pcie_pmu_exit(void)
770784
{
771-
struct dwc_pcie_dev_info *dev_info, *tmp;
772-
773785
if (notify)
774786
bus_unregister_notifier(&pci_bus_type, &dwc_pcie_pmu_nb);
775-
list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node)
776-
dwc_pcie_unregister_dev(dev_info);
787+
dwc_pcie_cleanup_devices();
777788
platform_driver_unregister(&dwc_pcie_pmu_driver);
778789
cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state);
779790
}

0 commit comments

Comments
 (0)