Skip to content

Commit

Permalink
tracing: Make -ENOMEM the default error for parse_synth_field()
Browse files Browse the repository at this point in the history
parse_synth_field() returns a pointer and requires that errors get
surrounded by ERR_PTR(). The ret variable is initialized to zero, but should
never be used as zero, and if it is, it could cause a false return code and
produce a NULL pointer dereference. It makes no sense to set ret to zero.

Set ret to -ENOMEM (the most common error case), and have any other errors
set it to something else. This removes the need to initialize ret on *every*
error branch.

Fixes: 761a8c5 ("tracing, synthetic events: Replace buggy strcat() with seq_buf operations")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (VMware) committed Nov 2, 2020
1 parent b02414c commit 561ca66
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions kernel/trace/trace_events_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
{
struct synth_field *field;
const char *prefix = NULL, *field_type = argv[0], *field_name, *array;
int len, ret = 0;
int len, ret = -ENOMEM;
struct seq_buf s;
ssize_t size;

Expand Down Expand Up @@ -617,10 +617,9 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
len--;

field->name = kmemdup_nul(field_name, len, GFP_KERNEL);
if (!field->name) {
ret = -ENOMEM;
if (!field->name)
goto free;
}

if (!is_good_name(field->name)) {
synth_err(SYNTH_ERR_BAD_NAME, errpos(field_name));
ret = -EINVAL;
Expand All @@ -638,10 +637,9 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
len += strlen(prefix);

field->type = kzalloc(len, GFP_KERNEL);
if (!field->type) {
ret = -ENOMEM;
if (!field->type)
goto free;
}

seq_buf_init(&s, field->type, len);
if (prefix)
seq_buf_puts(&s, prefix);
Expand All @@ -653,6 +651,7 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
}
if (WARN_ON_ONCE(!seq_buf_buffer_left(&s)))
goto free;

s.buffer[s.len] = '\0';

size = synth_field_size(field->type);
Expand All @@ -666,10 +665,8 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,

len = sizeof("__data_loc ") + strlen(field->type) + 1;
type = kzalloc(len, GFP_KERNEL);
if (!type) {
ret = -ENOMEM;
if (!type)
goto free;
}

seq_buf_init(&s, type, len);
seq_buf_puts(&s, "__data_loc ");
Expand Down

0 comments on commit 561ca66

Please sign in to comment.