tracing: Remove unnecessary null test before debugfs_remove()
[cascardo/linux.git] / kernel / trace / trace.c
index 16f7038..4caa814 100644 (file)
@@ -923,30 +923,6 @@ out:
        return ret;
 }
 
-ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
-{
-       int len;
-       int ret;
-
-       if (!cnt)
-               return 0;
-
-       if (s->len <= s->readpos)
-               return -EBUSY;
-
-       len = s->len - s->readpos;
-       if (cnt > len)
-               cnt = len;
-       ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
-       if (ret == cnt)
-               return -EFAULT;
-
-       cnt -= ret;
-
-       s->readpos += cnt;
-       return cnt;
-}
-
 static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt)
 {
        int len;
@@ -1085,13 +1061,13 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
 }
 #endif /* CONFIG_TRACER_MAX_TRACE */
 
-static void wait_on_pipe(struct trace_iterator *iter)
+static int wait_on_pipe(struct trace_iterator *iter)
 {
        /* Iterators are static, they should be filled or empty */
        if (trace_buffer_iter(iter, iter->cpu_file))
-               return;
+               return 0;
 
-       ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file);
+       return ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file);
 }
 
 #ifdef CONFIG_FTRACE_STARTUP_TEST
@@ -1338,7 +1314,7 @@ static int trace_create_savedcmd(void)
 {
        int ret;
 
-       savedcmd = kmalloc(sizeof(struct saved_cmdlines_buffer), GFP_KERNEL);
+       savedcmd = kmalloc(sizeof(*savedcmd), GFP_KERNEL);
        if (!savedcmd)
                return -ENOMEM;
 
@@ -3840,7 +3816,7 @@ tracing_saved_cmdlines_size_read(struct file *filp, char __user *ubuf,
        int r;
 
        arch_spin_lock(&trace_cmdline_lock);
-       r = sprintf(buf, "%u\n", savedcmd->cmdline_num);
+       r = scnprintf(buf, sizeof(buf), "%u\n", savedcmd->cmdline_num);
        arch_spin_unlock(&trace_cmdline_lock);
 
        return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
@@ -3857,7 +3833,7 @@ static int tracing_resize_saved_cmdlines(unsigned int val)
 {
        struct saved_cmdlines_buffer *s, *savedcmd_temp;
 
-       s = kmalloc(sizeof(struct saved_cmdlines_buffer), GFP_KERNEL);
+       s = kmalloc(sizeof(*s), GFP_KERNEL);
        if (!s)
                return -ENOMEM;
 
@@ -4378,6 +4354,7 @@ tracing_poll_pipe(struct file *filp, poll_table *poll_table)
 static int tracing_wait_pipe(struct file *filp)
 {
        struct trace_iterator *iter = filp->private_data;
+       int ret;
 
        while (trace_empty(iter)) {
 
@@ -4399,10 +4376,13 @@ static int tracing_wait_pipe(struct file *filp)
 
                mutex_unlock(&iter->mutex);
 
-               wait_on_pipe(iter);
+               ret = wait_on_pipe(iter);
 
                mutex_lock(&iter->mutex);
 
+               if (ret)
+                       return ret;
+
                if (signal_pending(current))
                        return -EINTR;
        }
@@ -5327,8 +5307,12 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,
                                goto out_unlock;
                        }
                        mutex_unlock(&trace_types_lock);
-                       wait_on_pipe(iter);
+                       ret = wait_on_pipe(iter);
                        mutex_lock(&trace_types_lock);
+                       if (ret) {
+                               size = ret;
+                               goto out_unlock;
+                       }
                        if (signal_pending(current)) {
                                size = -EINTR;
                                goto out_unlock;
@@ -5538,8 +5522,10 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
                        goto out;
                }
                mutex_unlock(&trace_types_lock);
-               wait_on_pipe(iter);
+               ret = wait_on_pipe(iter);
                mutex_lock(&trace_types_lock);
+               if (ret)
+                       goto out;
                if (signal_pending(current)) {
                        ret = -EINTR;
                        goto out;
@@ -6085,10 +6071,8 @@ destroy_trace_option_files(struct trace_option_dentry *topts)
        if (!topts)
                return;
 
-       for (cnt = 0; topts[cnt].opt; cnt++) {
-               if (topts[cnt].entry)
-                       debugfs_remove(topts[cnt].entry);
-       }
+       for (cnt = 0; topts[cnt].opt; cnt++)
+               debugfs_remove(topts[cnt].entry);
 
        kfree(topts);
 }
@@ -6232,22 +6216,25 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)
        return 0;
 }
 
+static void free_trace_buffer(struct trace_buffer *buf)
+{
+       if (buf->buffer) {
+               ring_buffer_free(buf->buffer);
+               buf->buffer = NULL;
+               free_percpu(buf->data);
+               buf->data = NULL;
+       }
+}
+
 static void free_trace_buffers(struct trace_array *tr)
 {
        if (!tr)
                return;
 
-       if (tr->trace_buffer.buffer) {
-               ring_buffer_free(tr->trace_buffer.buffer);
-               tr->trace_buffer.buffer = NULL;
-               free_percpu(tr->trace_buffer.data);
-       }
+       free_trace_buffer(&tr->trace_buffer);
 
 #ifdef CONFIG_TRACER_MAX_TRACE
-       if (tr->max_buffer.buffer) {
-               ring_buffer_free(tr->max_buffer.buffer);
-               tr->max_buffer.buffer = NULL;
-       }
+       free_trace_buffer(&tr->max_buffer);
 #endif
 }