perf/arm_dmc620: Fix hotplug callback leak in dmc620_pmu_init()
authorShang XiaoJing <shangxiaojing@huawei.com>
Tue, 15 Nov 2022 11:55:39 +0000 (19:55 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:31:51 +0000 (13:31 +0100)
[ Upstream commit d9f564c966e63925aac4ba273a9319d7fb6f4b4e ]

dmc620_pmu_init() won't remove the callback added by
cpuhp_setup_state_multi() when platform_driver_register() failed. Remove
the callback by cpuhp_remove_multi_state() in fail path.

Similar to the handling of arm_ccn_init() in commit 26242b330093 ("bus:
arm-ccn: Prevent hotplug callback leak")

Fixes: 53c218da220c ("driver/perf: Add PMU driver for the ARM DMC-620 memory controller")
Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
Reviewed-by: Punit Agrawal <punit.agrawal@bytedance.com>
Link: https://lore.kernel.org/r/20221115115540.6245-2-shangxiaojing@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/perf/arm_dmc620_pmu.c

index 280a6ae..54aa465 100644 (file)
@@ -725,6 +725,8 @@ static struct platform_driver dmc620_pmu_driver = {
 
 static int __init dmc620_pmu_init(void)
 {
+       int ret;
+
        cpuhp_state_num = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
                                      DMC620_DRVNAME,
                                      NULL,
@@ -732,7 +734,11 @@ static int __init dmc620_pmu_init(void)
        if (cpuhp_state_num < 0)
                return cpuhp_state_num;
 
-       return platform_driver_register(&dmc620_pmu_driver);
+       ret = platform_driver_register(&dmc620_pmu_driver);
+       if (ret)
+               cpuhp_remove_multi_state(cpuhp_state_num);
+
+       return ret;
 }
 
 static void __exit dmc620_pmu_exit(void)