Commit 50e18b94 authored by Jiri Olsa's avatar Jiri Olsa Committed by Steven Rostedt

tracing: Use seq_*_private interface for some seq files

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.comSigned-off-by: default avatarJiri 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: default avatarSteven Rostedt <rostedt@goodmis.org>
parent b02ee9a3
...@@ -2469,57 +2469,35 @@ static int ...@@ -2469,57 +2469,35 @@ static int
ftrace_avail_open(struct inode *inode, struct file *file) ftrace_avail_open(struct inode *inode, struct file *file)
{ {
struct ftrace_iterator *iter; struct ftrace_iterator *iter;
int ret;
if (unlikely(ftrace_disabled)) if (unlikely(ftrace_disabled))
return -ENODEV; return -ENODEV;
iter = kzalloc(sizeof(*iter), GFP_KERNEL); iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
if (!iter) if (iter) {
return -ENOMEM;
iter->pg = ftrace_pages_start; iter->pg = ftrace_pages_start;
iter->ops = &global_ops; 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);
} }
return ret; return iter ? 0 : -ENOMEM;
} }
static int static int
ftrace_enabled_open(struct inode *inode, struct file *file) ftrace_enabled_open(struct inode *inode, struct file *file)
{ {
struct ftrace_iterator *iter; struct ftrace_iterator *iter;
int ret;
if (unlikely(ftrace_disabled)) if (unlikely(ftrace_disabled))
return -ENODEV; return -ENODEV;
iter = kzalloc(sizeof(*iter), GFP_KERNEL); iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
if (!iter) if (iter) {
return -ENOMEM;
iter->pg = ftrace_pages_start; iter->pg = ftrace_pages_start;
iter->flags = FTRACE_ITER_ENABLED; iter->flags = FTRACE_ITER_ENABLED;
iter->ops = &global_ops; 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);
} }
return ret; return iter ? 0 : -ENOMEM;
} }
static void ftrace_filter_reset(struct ftrace_hash *hash) static void ftrace_filter_reset(struct ftrace_hash *hash)
......
...@@ -2413,15 +2413,13 @@ static struct trace_iterator * ...@@ -2413,15 +2413,13 @@ static struct trace_iterator *
__tracing_open(struct inode *inode, struct file *file) __tracing_open(struct inode *inode, struct file *file)
{ {
long cpu_file = (long) inode->i_private; long cpu_file = (long) inode->i_private;
void *fail_ret = ERR_PTR(-ENOMEM);
struct trace_iterator *iter; struct trace_iterator *iter;
struct seq_file *m; int cpu;
int cpu, ret;
if (tracing_disabled) if (tracing_disabled)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
iter = kzalloc(sizeof(*iter), GFP_KERNEL); iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter));
if (!iter) if (!iter)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -2478,32 +2476,15 @@ __tracing_open(struct inode *inode, struct file *file) ...@@ -2478,32 +2476,15 @@ __tracing_open(struct inode *inode, struct file *file)
tracing_iter_reset(iter, cpu); 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); mutex_unlock(&trace_types_lock);
return iter; 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: fail:
mutex_unlock(&trace_types_lock); mutex_unlock(&trace_types_lock);
kfree(iter->trace); kfree(iter->trace);
kfree(iter); seq_release_private(inode, file);
return ERR_PTR(-ENOMEM);
return fail_ret;
} }
int tracing_open_generic(struct inode *inode, struct file *filp) int tracing_open_generic(struct inode *inode, struct file *filp)
...@@ -2539,11 +2520,10 @@ static int tracing_release(struct inode *inode, struct file *file) ...@@ -2539,11 +2520,10 @@ static int tracing_release(struct inode *inode, struct file *file)
tracing_start(); tracing_start();
mutex_unlock(&trace_types_lock); mutex_unlock(&trace_types_lock);
seq_release(inode, file);
mutex_destroy(&iter->mutex); mutex_destroy(&iter->mutex);
free_cpumask_var(iter->started); free_cpumask_var(iter->started);
kfree(iter->trace); kfree(iter->trace);
kfree(iter); seq_release_private(inode, file);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment