]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - kernel/trace/trace.c
Merge remote-tracking branch 'ftrace/for-next'
[karo-tx-linux.git] / kernel / trace / trace.c
index 496f94d57698294966d2c0c9bd10de34854b34a5..063a92bad5786d4326a76140647ddc78ead4f784 100644 (file)
@@ -843,9 +843,12 @@ int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
        if (isspace(ch)) {
                parser->buffer[parser->idx] = 0;
                parser->cont = false;
-       } else {
+       } else if (parser->idx < parser->size - 1) {
                parser->cont = true;
                parser->buffer[parser->idx++] = ch;
+       } else {
+               ret = -EINVAL;
+               goto out;
        }
 
        *ppos += read;
@@ -2760,7 +2763,7 @@ static void show_snapshot_main_help(struct seq_file *m)
        seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
        seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
        seq_printf(m, "#                      Takes a snapshot of the main buffer.\n");
-       seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n");
+       seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
        seq_printf(m, "#                      (Doesn't have to be '2' works with any number that\n");
        seq_printf(m, "#                       is not a '0' or '1')\n");
 }
@@ -3165,11 +3168,6 @@ static const struct file_operations show_traces_fops = {
        .llseek         = seq_lseek,
 };
 
-/*
- * Only trace on a CPU if the bitmask is set:
- */
-static cpumask_var_t tracing_cpumask;
-
 /*
  * The tracer itself will not take this lock, but still we want
  * to provide a consistent cpumask to user-space:
@@ -3186,11 +3184,12 @@ static ssize_t
 tracing_cpumask_read(struct file *filp, char __user *ubuf,
                     size_t count, loff_t *ppos)
 {
+       struct trace_array *tr = file_inode(filp)->i_private;
        int len;
 
        mutex_lock(&tracing_cpumask_update_lock);
 
-       len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
+       len = cpumask_scnprintf(mask_str, count, tr->tracing_cpumask);
        if (count - len < 2) {
                count = -EINVAL;
                goto out_err;
@@ -3208,7 +3207,7 @@ static ssize_t
 tracing_cpumask_write(struct file *filp, const char __user *ubuf,
                      size_t count, loff_t *ppos)
 {
-       struct trace_array *tr = filp->private_data;
+       struct trace_array *tr = file_inode(filp)->i_private;
        cpumask_var_t tracing_cpumask_new;
        int err, cpu;
 
@@ -3228,12 +3227,12 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,
                 * Increase/decrease the disabled counter if we are
                 * about to flip a bit in the cpumask:
                 */
-               if (cpumask_test_cpu(cpu, tracing_cpumask) &&
+               if (cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
                                !cpumask_test_cpu(cpu, tracing_cpumask_new)) {
                        atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled);
                        ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu);
                }
-               if (!cpumask_test_cpu(cpu, tracing_cpumask) &&
+               if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
                                cpumask_test_cpu(cpu, tracing_cpumask_new)) {
                        atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled);
                        ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu);
@@ -3242,7 +3241,7 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,
        arch_spin_unlock(&ftrace_max_lock);
        local_irq_enable();
 
-       cpumask_copy(tracing_cpumask, tracing_cpumask_new);
+       cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new);
 
        mutex_unlock(&tracing_cpumask_update_lock);
        free_cpumask_var(tracing_cpumask_new);
@@ -3256,9 +3255,10 @@ err_unlock:
 }
 
 static const struct file_operations tracing_cpumask_fops = {
-       .open           = tracing_open_generic,
+       .open           = tracing_open_generic_tr,
        .read           = tracing_cpumask_read,
        .write          = tracing_cpumask_write,
+       .release        = tracing_release_generic_tr,
        .llseek         = generic_file_llseek,
 };
 
@@ -5938,6 +5938,11 @@ static int new_instance_create(const char *name)
        if (!tr->name)
                goto out_free_tr;
 
+       if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL))
+               goto out_free_tr;
+
+       cpumask_copy(tr->tracing_cpumask, cpu_all_mask);
+
        raw_spin_lock_init(&tr->start_lock);
 
        tr->current_trace = &nop_trace;
@@ -5969,6 +5974,7 @@ static int new_instance_create(const char *name)
  out_free_tr:
        if (tr->trace_buffer.buffer)
                ring_buffer_free(tr->trace_buffer.buffer);
+       free_cpumask_var(tr->tracing_cpumask);
        kfree(tr->name);
        kfree(tr);
 
@@ -6098,6 +6104,9 @@ init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
 {
        int cpu;
 
+       trace_create_file("tracing_cpumask", 0644, d_tracer,
+                         tr, &tracing_cpumask_fops);
+
        trace_create_file("trace_options", 0644, d_tracer,
                          tr, &tracing_iter_fops);
 
@@ -6147,9 +6156,6 @@ static __init int tracer_init_debugfs(void)
 
        init_tracer_debugfs(&global_trace, d_tracer);
 
-       trace_create_file("tracing_cpumask", 0644, d_tracer,
-                       &global_trace, &tracing_cpumask_fops);
-
        trace_create_file("available_tracers", 0444, d_tracer,
                        &global_trace, &show_traces_fops);
 
@@ -6371,7 +6377,7 @@ __init static int tracer_alloc_buffers(void)
        if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL))
                goto out;
 
-       if (!alloc_cpumask_var(&tracing_cpumask, GFP_KERNEL))
+       if (!alloc_cpumask_var(&global_trace.tracing_cpumask, GFP_KERNEL))
                goto out_free_buffer_mask;
 
        /* Only allocate trace_printk buffers if a trace_printk exists */
@@ -6386,7 +6392,7 @@ __init static int tracer_alloc_buffers(void)
                ring_buf_size = 1;
 
        cpumask_copy(tracing_buffer_mask, cpu_possible_mask);
-       cpumask_copy(tracing_cpumask, cpu_all_mask);
+       cpumask_copy(global_trace.tracing_cpumask, cpu_all_mask);
 
        raw_spin_lock_init(&global_trace.start_lock);
 
@@ -6441,7 +6447,7 @@ out_free_cpumask:
 #ifdef CONFIG_TRACER_MAX_TRACE
        free_percpu(global_trace.max_buffer.data);
 #endif
-       free_cpumask_var(tracing_cpumask);
+       free_cpumask_var(global_trace.tracing_cpumask);
 out_free_buffer_mask:
        free_cpumask_var(tracing_buffer_mask);
 out: