Skip to contentSkip to conversation

tracing: Uninitialized variable in create_tracing_map_fields()

PATCH In review Dan Carpenter 3 participants 3 messages Mar 28, 2018 – Apr 2, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: Uninitialized variable in create_tracing_map_fields()

Smatch complains that idx can be used uninitialized when we check if (idx < 0). It has to be the first iteration through the loop and the HIST_FIELD_FL_STACKTRACE bit has to be clear and the HIST_FIELD_FL_VAR bit has to be set to reach the bug.

Fixes 30350d65ac56 ("tracing: Add variable support to hist triggers")
kernel/trace/trace_events_hist.c +1 -1
index 4f027642ceef..6aceee287d07 100644
@@ -4411,7 +4411,7 @@ static int create_tracing_map_fields(struct hist_trigger_data *hist_data)
 	struct tracing_map *map = hist_data->map;
 	struct ftrace_event_field *field;
 	struct hist_field *hist_field;
-	int i, idx;
+	int i, idx = 0;
 
 	for_each_hist_field(i, hist_data) {
 		hist_field = hist_data->fields[i];
Acked-by on v1 1/1
#1 lore raw

Hi Dan,

Quoted 13 lines · Dan Carpenter

Smatch complains that idx can be used uninitialized when we check if (idx < 0). It has to be the first iteration through the loop and the HIST_FIELD_FL_STACKTRACE bit has to be clear and the HIST_FIELD_FL_VAR bit has to be set to reach the bug.

Fixes 30350d65ac56 ("tracing: Add variable support to hist triggers")
kernel/trace/trace_events_hist.c +0 -0
index 4f027642ceef..6aceee287d07 100644

kernel/trace/trace_events_hist.c static int create_tracing_map_fields(struct hist_trigger_data *hist_data) · line 4417

Quoted 8 lines
kernel/trace/trace_events_hist.c +1 -1
@@ -4411,7 +4411,7 @@ static int create_tracing_map_fields(struct hist_trigger_data *hist_data)
 	struct tracing_map *map = hist_data->map;
 	struct ftrace_event_field *field;
 	struct hist_field *hist_field;
-	int i, idx;
+	int i, idx = 0;
 
 	for_each_hist_field(i, hist_data) {
 		hist_field = hist_data->fields[i];

Yes, this should definitely be initialized to 0, thanks for the patch!