Commit 85a2f9b4 authored by Steven Rostedt's avatar Steven Rostedt

tracing: use pointer error returns for __tracing_open

Impact: fix compile warning and clean up

When I first wrote __tracing_open, instead of passing the error
code via the ERR_PTR macros, I lazily used a separate parameter
to hold the return for errors.

When Frederic Weisbecker updated that function, he used the Linux
kernel ERR_PTR for the returns. This caused the parameter return
to possibly not be initialized on error. gcc correctly pointed this
out with a warning.

This patch converts the entire function to use the Linux kernel
ERR_PTR macro methods.
Signed-off-by: default avatarSteven Rostedt <srostedt@redhat.com>
parent d8e83d26
...@@ -1684,23 +1684,20 @@ static struct seq_operations tracer_seq_ops = { ...@@ -1684,23 +1684,20 @@ static struct seq_operations tracer_seq_ops = {
}; };
static struct trace_iterator * static struct trace_iterator *
__tracing_open(struct inode *inode, struct file *file, int *ret) __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; struct seq_file *m;
int cpu; int cpu, ret;
if (tracing_disabled) { if (tracing_disabled)
*ret = -ENODEV; return ERR_PTR(-ENODEV);
return NULL;
}
iter = kzalloc(sizeof(*iter), GFP_KERNEL); iter = kzalloc(sizeof(*iter), GFP_KERNEL);
if (!iter) { if (!iter)
*ret = -ENOMEM; return ERR_PTR(-ENOMEM);
goto out;
}
/* /*
* We make a copy of the current tracer to avoid concurrent * We make a copy of the current tracer to avoid concurrent
...@@ -1708,10 +1705,9 @@ __tracing_open(struct inode *inode, struct file *file, int *ret) ...@@ -1708,10 +1705,9 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
*/ */
mutex_lock(&trace_types_lock); mutex_lock(&trace_types_lock);
iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL); iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL);
if (!iter->trace) { if (!iter->trace)
*ret = -ENOMEM;
goto fail; goto fail;
}
if (current_trace) if (current_trace)
*iter->trace = *current_trace; *iter->trace = *current_trace;
...@@ -1750,9 +1746,11 @@ __tracing_open(struct inode *inode, struct file *file, int *ret) ...@@ -1750,9 +1746,11 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
} }
/* TODO stop tracer */ /* TODO stop tracer */
*ret = seq_open(file, &tracer_seq_ops); ret = seq_open(file, &tracer_seq_ops);
if (*ret) if (ret < 0) {
fail_ret = ERR_PTR(ret);
goto fail_buffer; goto fail_buffer;
}
m = file->private_data; m = file->private_data;
m->private = iter; m->private = iter;
...@@ -1762,7 +1760,6 @@ __tracing_open(struct inode *inode, struct file *file, int *ret) ...@@ -1762,7 +1760,6 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
mutex_unlock(&trace_types_lock); mutex_unlock(&trace_types_lock);
out:
return iter; return iter;
fail_buffer: fail_buffer:
...@@ -1775,7 +1772,7 @@ __tracing_open(struct inode *inode, struct file *file, int *ret) ...@@ -1775,7 +1772,7 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
kfree(iter->trace); kfree(iter->trace);
kfree(iter); kfree(iter);
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)
...@@ -1815,9 +1812,12 @@ static int tracing_release(struct inode *inode, struct file *file) ...@@ -1815,9 +1812,12 @@ static int tracing_release(struct inode *inode, struct file *file)
static int tracing_open(struct inode *inode, struct file *file) static int tracing_open(struct inode *inode, struct file *file)
{ {
int ret; struct trace_iterator *iter;
int ret = 0;
__tracing_open(inode, file, &ret); iter = __tracing_open(inode, file);
if (IS_ERR(iter))
ret = PTR_ERR(iter);
return ret; return ret;
} }
...@@ -1825,11 +1825,13 @@ static int tracing_open(struct inode *inode, struct file *file) ...@@ -1825,11 +1825,13 @@ static int tracing_open(struct inode *inode, struct file *file)
static int tracing_lt_open(struct inode *inode, struct file *file) static int tracing_lt_open(struct inode *inode, struct file *file)
{ {
struct trace_iterator *iter; struct trace_iterator *iter;
int ret; int ret = 0;
iter = __tracing_open(inode, file, &ret); iter = __tracing_open(inode, file);
if (!ret) if (IS_ERR(iter))
ret = PTR_ERR(iter);
else
iter->iter_flags |= TRACE_FILE_LAT_FMT; iter->iter_flags |= TRACE_FILE_LAT_FMT;
return ret; return ret;
......
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