Skip to content

Commit

Permalink
tracing: use pointer error returns for __tracing_open
Browse files Browse the repository at this point in the history
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: Steven Rostedt <srostedt@redhat.com>
  • Loading branch information
Steven Rostedt committed Feb 27, 2009
1 parent d8e83d2 commit 85a2f9b
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,34 +1684,30 @@ static struct seq_operations tracer_seq_ops = {
};

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;
void *fail_ret = ERR_PTR(-ENOMEM);
struct trace_iterator *iter;
struct seq_file *m;
int cpu;
int cpu, ret;

if (tracing_disabled) {
*ret = -ENODEV;
return NULL;
}
if (tracing_disabled)
return ERR_PTR(-ENODEV);

iter = kzalloc(sizeof(*iter), GFP_KERNEL);
if (!iter) {
*ret = -ENOMEM;
goto out;
}
if (!iter)
return ERR_PTR(-ENOMEM);

/*
* We make a copy of the current tracer to avoid concurrent
* changes on it while we are reading.
*/
mutex_lock(&trace_types_lock);
iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL);
if (!iter->trace) {
*ret = -ENOMEM;
if (!iter->trace)
goto fail;
}

if (current_trace)
*iter->trace = *current_trace;

Expand Down Expand Up @@ -1750,9 +1746,11 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
}

/* TODO stop tracer */
*ret = seq_open(file, &tracer_seq_ops);
if (*ret)
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;
Expand All @@ -1762,7 +1760,6 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)

mutex_unlock(&trace_types_lock);

out:
return iter;

fail_buffer:
Expand All @@ -1775,7 +1772,7 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
kfree(iter->trace);
kfree(iter);

return ERR_PTR(-ENOMEM);
return fail_ret;
}

int tracing_open_generic(struct inode *inode, struct file *filp)
Expand Down Expand Up @@ -1815,21 +1812,26 @@ static int tracing_release(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;
}

static int tracing_lt_open(struct inode *inode, struct file *file)
{
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;

return ret;
Expand Down

0 comments on commit 85a2f9b

Please sign in to comment.