tracing: trace_output.c, fix false positive compiler warning
Steven Rostedt
maintainerQuoted 37 lines · tip-bot for Jaswinder Singh Rajput
Commit-ID: 48dd0fed90e2b1f1ba87401439b85942181c6df3 Gitweb: http://git.kernel.org/tip/48dd0fed90e2b1f1ba87401439b85942181c6df3 Author: Jaswinder Singh Rajput <[email protected]> AuthorDate: Wed, 6 May 2009 15:45:45 +0530 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 6 May 2009 14:19:16 +0200tracing:
trace_output.c, fix false positive compiler warningThis compiler warning:
CC
kernel/trace/trace_output.o
kernel/trace/trace_output.c: In function ?register_ftrace_event?:
kernel/trace/trace_output.c:544: warning: ?list? may be used uninitialized in this functionIs wrong as 'list' is always initialized - but GCC (4.3.2) does not recognize this relationship properly.
Work around the warning by initializing the variable to NULL.
[ Impact: fix false positive compiler warning ]
Signed-off-by Jaswinder Singh Rajput <[email protected]>Acked-by Steven Rostedt <[email protected]>LKML-Reference: <new-submission>
Signed-off-by Ingo Molnar <[email protected]>--- kernel/trace/trace_output.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/trace/trace_output.c +0
-0
kernel/trace/trace_output.c int register_ftrace_event(struct trace_event *event) · line 544
Quoted 5 lines
kernel/trace/trace_output.c +1
-1@@ -541,7 +541,7 @@ int register_ftrace_event(struct trace_event *event)INIT_LIST_HEAD (&event->list);if (!event->type) { -struct list_head *list; +struct list_head *list =NULL ;
Actually this is the wrong place to initialize. The correct place is in the function that is expected to.
kernel/trace/trace_output.c int register_ftrace_event(struct trace_event *event) · line 546
Quoted 3 lines
kernel/trace/trace_output.c +0
-0if (next_event_type >FTRACE_MAX_EVENT ) {
Could you test this patch instead:
tracing: quiet gcc compile warning
Some versions of gcc can not catch the fact that the list variable in register_ftrace_event is initialized. There's one place in the logic that is a bit complex. The trace_search_list function that initializes the list will not initialize it on error. But that's OK, because the caller checks for error and will not use the list variable if there is one. Some versions of gcc miss this.
[ Impact: quiet gcc from complaining about an unused variable ]
kernel/trace/trace_output.c +3 -1
@@ -506,8 +506,10 @@ static int trace_search_list(struct list_head **list) }/* Did we used up all 65 thousand events??? */ -if ((last +1 ) >FTRACE_MAX_EVENT ) +if ((last +1 ) >FTRACE_MAX_EVENT ) { + *list =NULL ;return 0 ; + } *list = &e->list;return last +1 ;
Quoted 42 lines · Steven Rostedt
Quoted 39 lines · tip-bot for Jaswinder Singh Rajput
Commit-ID: 48dd0fed90e2b1f1ba87401439b85942181c6df3 Gitweb: http://git.kernel.org/tip/48dd0fed90e2b1f1ba87401439b85942181c6df3 Author: Jaswinder Singh Rajput <[email protected]> AuthorDate: Wed, 6 May 2009 15:45:45 +0530 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 6 May 2009 14:19:16 +0200tracing:
trace_output.c, fix false positive compiler warningThis compiler warning:
CC
kernel/trace/trace_output.o
kernel/trace/trace_output.c: In function ?register_ftrace_event?:
kernel/trace/trace_output.c:544: warning: ?list? may be used uninitialized in this functionIs wrong as 'list' is always initialized - but GCC (4.3.2) does not recognize this relationship properly.
Work around the warning by initializing the variable to NULL.
[ Impact: fix false positive compiler warning ]
Signed-off-by Jaswinder Singh Rajput <[email protected]>Acked-by Steven Rostedt <[email protected]>LKML-Reference: <new-submission>
Signed-off-by Ingo Molnar <[email protected]>--- kernel/trace/trace_output.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/trace/trace_output.c +0
-0@@ -541,7 +541,7 @@ int register_ftrace_event(struct trace_event *event)INIT_LIST_HEAD (&event->list);
Quoted 6 lines
kernel/trace/trace_output.c int register_ftrace_event(struct trace_event *event) · line 544
Quoted 3 lines
kernel/trace/trace_output.c +1
-1if (!event->type) { -struct list_head *list; +struct list_head *list =NULL ;Actually this is the wrong place to initialize. The correct place is in the function that is expected to.
does it really matter? It's far more robust to initialize at the definition site, because there we can be sure there's no side-effects. This one:
kernel/trace/trace_output.c static int trace_search_list(struct list_head **list) · line 512
Quoted 6 lines
kernel/trace/trace_output.c +3
-1/* Did we used up all 65 thousand events??? */ -if ((last +1 ) >FTRACE_MAX_EVENT ) +if ((last +1 ) >FTRACE_MAX_EVENT ) { + *list =NULL ;return 0 ; + }
Is correct too but needs a semantic check (and ongoing maintenance, etc.).
Ingo
Steven Rostedt
maintainerQuoted 22 lines · Ingo Molnar
Quoted 11 lines
Quoted 11 lines
--- kernel/trace/trace_output.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/trace/trace_output.c +0
-0@@ -541,7 +541,7 @@ int register_ftrace_event(struct trace_event *event)INIT_LIST_HEAD (&event->list);Quoted 6 lines
kernel/trace/trace_output.c int register_ftrace_event(struct trace_event *event) · line 544
Quoted 3 lines
kernel/trace/trace_output.c +1
-1if (!event->type) { -struct list_head *list; +struct list_head *list =NULL ;Actually this is the wrong place to initialize. The correct place is in the function that is expected to.
does it really matter? It's far more robust to initialize at the definition site, because there we can be sure there's no side-effects. This one:
Quoted 9 lines
kernel/trace/trace_output.c static int trace_search_list(struct list_head **list) · line 512
Quoted 6 lines
kernel/trace/trace_output.c +3
-1/* Did we used up all 65 thousand events??? */ -if ((last +1 ) >FTRACE_MAX_EVENT ) +if ((last +1 ) >FTRACE_MAX_EVENT ) { + *list =NULL ;return 0 ; + }Is correct too but needs a semantic check (and ongoing maintenance, etc.).
Actually, to answer this, we need to look at the entire code. Just looking at the changes of a patch does not include the big picture.
The original code is:
static int trace_search_list(struct list_head **list)
{
struct trace_event *e;
int last = __TRACE_LAST_TYPE;
if (list_empty(&ftrace_event_list)) {
*list = &ftrace_event_list;
return last + 1;
}
/*
* We used up all possible max events,
* lets see if somebody freed one.
*/
list_for_each_entry(e, &ftrace_event_list, list) {
if (e->type != last + 1)
break;
last++;
}
/* Did we used up all 65 thousand events??? */
if ((last + 1) > FTRACE_MAX_EVENT)
return 0;
*list = &e->list;
return last + 1;
}[...]
struct list_head *list;
if (next_event_type > FTRACE_MAX_EVENT) {
event->type = trace_search_list(&list);
if (!event->type)
goto out;
} else {
event->type = next_event_type++;
list = &ftrace_event_list;
}
if (WARN_ON(ftrace_find_event(event->type)))
goto out;
list_add_tail(&event->list, list);The caller is:
struct list_head *list;
if () {
event->type = trace_seach_list(&list);
} else {
[...]
list = &ftrace_event_list;
}This code shows that list is initialized by either trace_seach_list() or set manually.
Thus, my change makes trace_search_list always initialize the list variable. Thus if trace_search_list() is used someplace else, it will not cause us this error again.
If gcc can not figure out that trace_search_list initializes the code (from the original code), the
struct list_head *list = NULL;
will always be performed, because gcc thinks that's the only way to guarantee that it will be initialized.
My solution, gcc can easily see that trace_search_list will always initialize list, and will not set it needlessly to NULL.
-- Steve