Skip to content

Commit d29859e

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/perf/intel/cstate: Sanitize error handling
There is no point in WARN_ON() inside of a well known init function. We already know the call stack and it's really not of critical importance whether the registration of a PMU fails. Aside of that for consistency reasons it's just pointless to try to register another PMU if the first register attempt failed. There is also no value in keeping one PMU if the second one can not be registered. Make it consistent so we can finaly modularize the driver. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Vince Weaver <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 424646e commit d29859e

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

arch/x86/events/intel/cstate.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -581,37 +581,45 @@ static int __init cstate_probe(const struct cstate_model *cm)
581581
return (has_cstate_core || has_cstate_pkg) ? 0 : -ENODEV;
582582
}
583583

584-
static void __init cstate_cpumask_init(void)
584+
static void __init cstate_cleanup(void)
585585
{
586-
int cpu;
587-
588-
cpu_notifier_register_begin();
589-
590-
for_each_online_cpu(cpu)
591-
cstate_cpu_init(cpu);
586+
if (has_cstate_core)
587+
perf_pmu_unregister(&cstate_core_pmu);
592588

593-
__perf_cpu_notifier(cstate_cpu_notifier);
594-
595-
cpu_notifier_register_done();
589+
if (has_cstate_pkg)
590+
perf_pmu_unregister(&cstate_pkg_pmu);
596591
}
597592

598-
static void __init cstate_pmus_register(void)
593+
static int __init cstate_init(void)
599594
{
600-
int err;
595+
int cpu, err;
596+
597+
cpu_notifier_register_begin();
598+
for_each_online_cpu(cpu)
599+
cstate_cpu_init(cpu);
601600

602601
if (has_cstate_core) {
603602
err = perf_pmu_register(&cstate_core_pmu, cstate_core_pmu.name, -1);
604-
if (WARN_ON(err))
605-
pr_info("Failed to register PMU %s error %d\n",
606-
cstate_core_pmu.name, err);
603+
if (err) {
604+
has_cstate_core = false;
605+
pr_info("Failed to register cstate core pmu\n");
606+
goto out;
607+
}
607608
}
608609

609610
if (has_cstate_pkg) {
610611
err = perf_pmu_register(&cstate_pkg_pmu, cstate_pkg_pmu.name, -1);
611-
if (WARN_ON(err))
612-
pr_info("Failed to register PMU %s error %d\n",
613-
cstate_pkg_pmu.name, err);
612+
if (err) {
613+
has_cstate_pkg = false;
614+
pr_info("Failed to register cstate pkg pmu\n");
615+
cstate_cleanup();
616+
goto out;
617+
}
614618
}
619+
__perf_cpu_notifier(cstate_cpu_notifier);
620+
out:
621+
cpu_notifier_register_done();
622+
return err;
615623
}
616624

617625
static int __init cstate_pmu_init(void)
@@ -630,10 +638,6 @@ static int __init cstate_pmu_init(void)
630638
if (err)
631639
return err;
632640

633-
cstate_cpumask_init();
634-
635-
cstate_pmus_register();
636-
637-
return 0;
641+
return cstate_init();
638642
}
639643
device_initcall(cstate_pmu_init);

0 commit comments

Comments
 (0)