aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/events/intel
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2016-02-22 17:19:21 -0500
committerIngo Molnar <mingo@kernel.org>2016-02-29 03:35:22 -0500
commit55f2890f0726fe4a1f41a3a0e72ca1a263f095c3 (patch)
tree936e8d322037b448031783013352124a9a32e143 /arch/x86/events/intel
parent4d120c535d638a952e644817ba3cbef30deedb2b (diff)
perf/x86/intel/rapl: Add proper error handling
Like uncore the rapl driver lacks error handling. It leaks memory and leaves the hotplug notifier registered. Add the proper error checks, cleanup the memory and register the hotplug notifier only on success. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andi Kleen <andi.kleen@intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Harish Chegondi <harish.chegondi@intel.com> Cc: Jacob Pan <jacob.jun.pan@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Vince Weaver <vincent.weaver@maine.edu> Cc: linux-kernel@vger.kernel.org Link: http://lkml.kernel.org/r/20160222221012.231222076@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/events/intel')
-rw-r--r--arch/x86/events/intel/rapl.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
index 536f0cebba8f..98b04d202760 100644
--- a/arch/x86/events/intel/rapl.c
+++ b/arch/x86/events/intel/rapl.c
@@ -686,6 +686,14 @@ static int rapl_check_hw_unit(void)
686 return 0; 686 return 0;
687} 687}
688 688
689static void __init cleanup_rapl_pmus(void)
690{
691 int cpu;
692
693 for_each_online_cpu(cpu)
694 kfree(per_cpu(rapl_pmu, cpu));
695}
696
689static const struct x86_cpu_id rapl_cpu_match[] = { 697static const struct x86_cpu_id rapl_cpu_match[] = {
690 [0] = { .vendor = X86_VENDOR_INTEL, .family = 6 }, 698 [0] = { .vendor = X86_VENDOR_INTEL, .family = 6 },
691 [1] = {}, 699 [1] = {},
@@ -702,7 +710,7 @@ static int __init rapl_pmu_init(void)
702 * check for Intel processor family 6 710 * check for Intel processor family 6
703 */ 711 */
704 if (!x86_match_cpu(rapl_cpu_match)) 712 if (!x86_match_cpu(rapl_cpu_match))
705 return 0; 713 return -ENODEV;
706 714
707 /* check supported CPU */ 715 /* check supported CPU */
708 switch (boot_cpu_data.x86_model) { 716 switch (boot_cpu_data.x86_model) {
@@ -734,8 +742,9 @@ static int __init rapl_pmu_init(void)
734 break; 742 break;
735 default: 743 default:
736 /* unsupported */ 744 /* unsupported */
737 return 0; 745 return -ENODEV;
738 } 746 }
747
739 ret = rapl_check_hw_unit(); 748 ret = rapl_check_hw_unit();
740 if (ret) 749 if (ret)
741 return ret; 750 return ret;
@@ -743,6 +752,7 @@ static int __init rapl_pmu_init(void)
743 /* run cpu model quirks */ 752 /* run cpu model quirks */
744 for (quirk = rapl_quirks; quirk; quirk = quirk->next) 753 for (quirk = rapl_quirks; quirk; quirk = quirk->next)
745 quirk->func(); 754 quirk->func();
755
746 cpu_notifier_register_begin(); 756 cpu_notifier_register_begin();
747 757
748 for_each_online_cpu(cpu) { 758 for_each_online_cpu(cpu) {
@@ -752,15 +762,14 @@ static int __init rapl_pmu_init(void)
752 rapl_cpu_init(cpu); 762 rapl_cpu_init(cpu);
753 } 763 }
754 764
755 __perf_cpu_notifier(rapl_cpu_notifier);
756
757 ret = perf_pmu_register(&rapl_pmu_class, "power", -1); 765 ret = perf_pmu_register(&rapl_pmu_class, "power", -1);
758 if (WARN_ON(ret)) { 766 if (WARN_ON(ret)) {
759 pr_info("RAPL PMU detected, registration failed (%d), RAPL PMU disabled\n", ret); 767 pr_info("RAPL PMU detected, registration failed (%d), RAPL PMU disabled\n", ret);
760 cpu_notifier_register_done(); 768 goto out;
761 return -1;
762 } 769 }
763 770
771 __perf_cpu_notifier(rapl_cpu_notifier);
772
764 pmu = __this_cpu_read(rapl_pmu); 773 pmu = __this_cpu_read(rapl_pmu);
765 774
766 pr_info("RAPL PMU detected," 775 pr_info("RAPL PMU detected,"
@@ -775,9 +784,13 @@ static int __init rapl_pmu_init(void)
775 rapl_domain_names[i], rapl_hw_unit[i]); 784 rapl_domain_names[i], rapl_hw_unit[i]);
776 } 785 }
777 } 786 }
778out:
779 cpu_notifier_register_done();
780 787
788 cpu_notifier_register_done();
781 return 0; 789 return 0;
790
791out:
792 cleanup_rapl_pmus();
793 cpu_notifier_register_done();
794 return ret;
782} 795}
783device_initcall(rapl_pmu_init); 796device_initcall(rapl_pmu_init);