Skip to content

Commit 561ca66

Browse files
committed
tracing: Make -ENOMEM the default error for parse_synth_field()
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 <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent b02414c commit 561ca66

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

kernel/trace/trace_events_synth.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
584584
{
585585
struct synth_field *field;
586586
const char *prefix = NULL, *field_type = argv[0], *field_name, *array;
587-
int len, ret = 0;
587+
int len, ret = -ENOMEM;
588588
struct seq_buf s;
589589
ssize_t size;
590590

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

619619
field->name = kmemdup_nul(field_name, len, GFP_KERNEL);
620-
if (!field->name) {
621-
ret = -ENOMEM;
620+
if (!field->name)
622621
goto free;
623-
}
622+
624623
if (!is_good_name(field->name)) {
625624
synth_err(SYNTH_ERR_BAD_NAME, errpos(field_name));
626625
ret = -EINVAL;
@@ -638,10 +637,9 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
638637
len += strlen(prefix);
639638

640639
field->type = kzalloc(len, GFP_KERNEL);
641-
if (!field->type) {
642-
ret = -ENOMEM;
640+
if (!field->type)
643641
goto free;
644-
}
642+
645643
seq_buf_init(&s, field->type, len);
646644
if (prefix)
647645
seq_buf_puts(&s, prefix);
@@ -653,6 +651,7 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
653651
}
654652
if (WARN_ON_ONCE(!seq_buf_buffer_left(&s)))
655653
goto free;
654+
656655
s.buffer[s.len] = '\0';
657656

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

667666
len = sizeof("__data_loc ") + strlen(field->type) + 1;
668667
type = kzalloc(len, GFP_KERNEL);
669-
if (!type) {
670-
ret = -ENOMEM;
668+
if (!type)
671669
goto free;
672-
}
673670

674671
seq_buf_init(&s, type, len);
675672
seq_buf_puts(&s, "__data_loc ");

0 commit comments

Comments
 (0)