[PATCH 2/2] perf/x86/amd/ibs: Fix missing CPU hotplug cleanup and unchecked init return

From: Ayush Yaduvanshi

Date: Thu Nov 12 2026 - 21:41:20 EST


Check the return value of cpuhp_setup_state() and remove the hotplug state
if perf_event_ibs_init() fails. Unregister syscore operations and reset
ibs_caps on initialization failure.

Signed-off-by: Ayush Yaduvanshi <ayush37735@xxxxxxxxx>
---
arch/x86/events/amd/ibs.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
index 66e67e27224f..2518cc7a24a6 100644
--- a/arch/x86/events/amd/ibs.c
+++ b/arch/x86/events/amd/ibs.c
@@ -2129,6 +2129,7 @@ static int x86_pmu_amd_ibs_dying_cpu(unsigned int cpu)
static __init int amd_ibs_init(void)
{
u32 caps;
+ int ret;

caps = __get_ibs_caps();
if (!caps)
@@ -2156,12 +2157,27 @@ static __init int amd_ibs_init(void)
* x86_pmu_amd_ibs_starting_cpu will be called from core on
* all online cpus.
*/
- cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
- "perf/x86/amd/ibs:starting",
- x86_pmu_amd_ibs_starting_cpu,
- x86_pmu_amd_ibs_dying_cpu);
+ ret = cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
+ "perf/x86/amd/ibs:starting",
+ x86_pmu_amd_ibs_starting_cpu,
+ x86_pmu_amd_ibs_dying_cpu);
+ if (ret)
+ goto err_pm;
+
+ ret = perf_event_ibs_init();
+ if (ret) {
+ cpuhp_remove_state(CPUHP_AP_PERF_X86_AMD_IBS_STARTING);
+ goto err_pm;
+ }

- return perf_event_ibs_init();
+ return 0;
+
+err_pm:
+#ifdef CONFIG_PM
+ unregister_syscore(&perf_ibs_syscore);
+#endif
+ ibs_caps = 0;
+ return ret;
}

/* Since we need the pci subsystem to init ibs we can't do this earlier: */
--
2.53.0