Check for context name duplicata
[lttng-modules.git] / lttng-context-perf-counters.c
index 56e0d25035ae7f6a09eec09114ced55524b81159..2f7132fbf26bf8db8aa9897fbfcee73cbc97e143 100644 (file)
@@ -111,7 +111,7 @@ int __cpuinit lttng_perf_counter_cpu_hp_callback(struct notifier_block *nb,
        case CPU_ONLINE_FROZEN:
                pevent = perf_event_create_kernel_counter(attr,
                                cpu, NULL, overflow_callback);
-               if (!pevent)
+               if (!pevent || IS_ERR(pevent))
                        return NOTIFY_BAD;
                barrier();      /* Create perf counter before setting event */
                events[cpu] = pevent;
@@ -170,6 +170,10 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
                ret = -ENOMEM;
                goto append_context_error;
        }
+       if (lttng_find_context(*ctx, name_alloc))  {
+               ret = -EEXIST;
+               goto find_error;
+       }
 
 #ifdef CONFIG_HOTPLUG_CPU
        field->u.perf_counter.nb.notifier_call =
@@ -182,7 +186,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
        for_each_online_cpu(cpu) {
                events[cpu] = perf_event_create_kernel_counter(attr,
                                        cpu, NULL, overflow_callback);
-               if (!events[cpu]) {
+               if (!events[cpu] || IS_ERR(events[cpu])) {
                        ret = -EINVAL;
                        goto counter_error;
                }
@@ -210,13 +214,14 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
 
 counter_error:
        for_each_online_cpu(cpu) {
-               if (events[cpu])
+               if (events[cpu] && !IS_ERR(events[cpu]))
                        perf_event_release_kernel(events[cpu]);
        }
        put_online_cpus();
 #ifdef CONFIG_HOTPLUG_CPU
        unregister_cpu_notifier(&field->u.perf_counter.nb);
 #endif
+find_error:
        lttng_remove_context_field(ctx, field);
 append_context_error:
        kfree(name_alloc);
This page took 0.024134 seconds and 4 git commands to generate.