tracing: Use seq_*_private interface for some seq files
authorJiri Olsa <jolsa@redhat.com>
Wed, 25 Apr 2012 08:23:39 +0000 (10:23 +0200)
committerSteven Rostedt <rostedt@goodmis.org>
Wed, 9 May 2012 01:04:12 +0000 (21:04 -0400)
It's appropriate to use __seq_open_private interface to open
some of trace seq files, because it covers all steps we are
duplicating in tracing code - zallocating the iterator and
setting it as seq_file's private.

Using this for following files:
  trace
  available_filter_functions
  enabled_functions

Link: http://lkml.kernel.org/r/1335342219-2782-5-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
[
 Fixed warnings for:
   kernel/trace/trace.c: In function '__tracing_open':
   kernel/trace/trace.c:2418:11: warning: unused variable 'ret' [-Wunused-variable]
   kernel/trace/trace.c:2417:19: warning: unused variable 'm' [-Wunused-variable]
]

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/ftrace.c
kernel/trace/trace.c

index 0fa92f677c9209e2ed046752752de986e34f071e..cf81f27ce6c67768cef1de7cc402f5a80b507d31 100644 (file)
@@ -2469,57 +2469,35 @@ static int
 ftrace_avail_open(struct inode *inode, struct file *file)
 {
        struct ftrace_iterator *iter;
-       int ret;
 
        if (unlikely(ftrace_disabled))
                return -ENODEV;
 
-       iter = kzalloc(sizeof(*iter), GFP_KERNEL);
-       if (!iter)
-               return -ENOMEM;
-
-       iter->pg = ftrace_pages_start;
-       iter->ops = &global_ops;
-
-       ret = seq_open(file, &show_ftrace_seq_ops);
-       if (!ret) {
-               struct seq_file *m = file->private_data;
-
-               m->private = iter;
-       } else {
-               kfree(iter);
+       iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
+       if (iter) {
+               iter->pg = ftrace_pages_start;
+               iter->ops = &global_ops;
        }
 
-       return ret;
+       return iter ? 0 : -ENOMEM;
 }
 
 static int
 ftrace_enabled_open(struct inode *inode, struct file *file)
 {
        struct ftrace_iterator *iter;
-       int ret;
 
        if (unlikely(ftrace_disabled))
                return -ENODEV;
 
-       iter = kzalloc(sizeof(*iter), GFP_KERNEL);
-       if (!iter)
-               return -ENOMEM;
-
-       iter->pg = ftrace_pages_start;
-       iter->flags = FTRACE_ITER_ENABLED;
-       iter->ops = &global_ops;
-
-       ret = seq_open(file, &show_ftrace_seq_ops);
-       if (!ret) {
-               struct seq_file *m = file->private_data;
-
-               m->private = iter;
-       } else {
-               kfree(iter);
+       iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
+       if (iter) {
+               iter->pg = ftrace_pages_start;
+               iter->flags = FTRACE_ITER_ENABLED;
+               iter->ops = &global_ops;
        }
 
-       return ret;
+       return iter ? 0 : -ENOMEM;
 }
 
 static void ftrace_filter_reset(struct ftrace_hash *hash)
index f11a285ee5bb4f87d139ca1f938c9652490322e7..4fb10ef727d3f4d2613a90bd3b13d74a8507793e 100644 (file)
@@ -2413,15 +2413,13 @@ static struct trace_iterator *
 __tracing_open(struct inode *inode, struct file *file)
 {
        long cpu_file = (long) inode->i_private;
-       void *fail_ret = ERR_PTR(-ENOMEM);
        struct trace_iterator *iter;
-       struct seq_file *m;
-       int cpu, ret;
+       int cpu;
 
        if (tracing_disabled)
                return ERR_PTR(-ENODEV);
 
-       iter = kzalloc(sizeof(*iter), GFP_KERNEL);
+       iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter));
        if (!iter)
                return ERR_PTR(-ENOMEM);
 
@@ -2478,32 +2476,15 @@ __tracing_open(struct inode *inode, struct file *file)
                tracing_iter_reset(iter, cpu);
        }
 
-       ret = seq_open(file, &tracer_seq_ops);
-       if (ret < 0) {
-               fail_ret = ERR_PTR(ret);
-               goto fail_buffer;
-       }
-
-       m = file->private_data;
-       m->private = iter;
-
        mutex_unlock(&trace_types_lock);
 
        return iter;
 
- fail_buffer:
-       for_each_tracing_cpu(cpu) {
-               if (iter->buffer_iter[cpu])
-                       ring_buffer_read_finish(iter->buffer_iter[cpu]);
-       }
-       free_cpumask_var(iter->started);
-       tracing_start();
  fail:
        mutex_unlock(&trace_types_lock);
        kfree(iter->trace);
-       kfree(iter);
-
-       return fail_ret;
+       seq_release_private(inode, file);
+       return ERR_PTR(-ENOMEM);
 }
 
 int tracing_open_generic(struct inode *inode, struct file *filp)
@@ -2539,11 +2520,10 @@ static int tracing_release(struct inode *inode, struct file *file)
        tracing_start();
        mutex_unlock(&trace_types_lock);
 
-       seq_release(inode, file);
        mutex_destroy(&iter->mutex);
        free_cpumask_var(iter->started);
        kfree(iter->trace);
-       kfree(iter);
+       seq_release_private(inode, file);
        return 0;
 }