Skip to content

Commit 39b2ca7

Browse files
Ravi BangoriaPeter Zijlstra
authored andcommitted
perf/amd/ibs: Cascade pmu init functions' return value
IBS pmu initialization code ignores return value provided by callee functions. Fix it. Signed-off-by: Ravi Bangoria <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f758bc5 commit 39b2ca7

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

arch/x86/events/amd/ibs.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,10 @@ static __init int perf_ibs_pmu_init(struct perf_ibs *perf_ibs, char *name)
777777
return ret;
778778
}
779779

780-
static __init void perf_event_ibs_init(void)
780+
static __init int perf_event_ibs_init(void)
781781
{
782782
struct attribute **attr = ibs_op_format_attrs;
783+
int ret;
783784

784785
/*
785786
* Some chips fail to reset the fetch count when it is written; instead
@@ -791,7 +792,9 @@ static __init void perf_event_ibs_init(void)
791792
if (boot_cpu_data.x86 == 0x19 && boot_cpu_data.x86_model < 0x10)
792793
perf_ibs_fetch.fetch_ignore_if_zero_rip = 1;
793794

794-
perf_ibs_pmu_init(&perf_ibs_fetch, "ibs_fetch");
795+
ret = perf_ibs_pmu_init(&perf_ibs_fetch, "ibs_fetch");
796+
if (ret)
797+
return ret;
795798

796799
if (ibs_caps & IBS_CAPS_OPCNT) {
797800
perf_ibs_op.config_mask |= IBS_OP_CNT_CTL;
@@ -804,15 +807,35 @@ static __init void perf_event_ibs_init(void)
804807
perf_ibs_op.cnt_mask |= IBS_OP_MAX_CNT_EXT_MASK;
805808
}
806809

807-
perf_ibs_pmu_init(&perf_ibs_op, "ibs_op");
810+
ret = perf_ibs_pmu_init(&perf_ibs_op, "ibs_op");
811+
if (ret)
812+
goto err_op;
813+
814+
ret = register_nmi_handler(NMI_LOCAL, perf_ibs_nmi_handler, 0, "perf_ibs");
815+
if (ret)
816+
goto err_nmi;
808817

809-
register_nmi_handler(NMI_LOCAL, perf_ibs_nmi_handler, 0, "perf_ibs");
810818
pr_info("perf: AMD IBS detected (0x%08x)\n", ibs_caps);
819+
return 0;
820+
821+
err_nmi:
822+
perf_pmu_unregister(&perf_ibs_op.pmu);
823+
free_percpu(perf_ibs_op.pcpu);
824+
perf_ibs_op.pcpu = NULL;
825+
err_op:
826+
perf_pmu_unregister(&perf_ibs_fetch.pmu);
827+
free_percpu(perf_ibs_fetch.pcpu);
828+
perf_ibs_fetch.pcpu = NULL;
829+
830+
return ret;
811831
}
812832

813833
#else /* defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_AMD) */
814834

815-
static __init void perf_event_ibs_init(void) { }
835+
static __init int perf_event_ibs_init(void)
836+
{
837+
return 0;
838+
}
816839

817840
#endif
818841

@@ -1082,9 +1105,7 @@ static __init int amd_ibs_init(void)
10821105
x86_pmu_amd_ibs_starting_cpu,
10831106
x86_pmu_amd_ibs_dying_cpu);
10841107

1085-
perf_event_ibs_init();
1086-
1087-
return 0;
1108+
return perf_event_ibs_init();
10881109
}
10891110

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

0 commit comments

Comments
 (0)