2014-02-11 08:30:11

by Ren Qiaowei

[permalink] [raw]
Subject: [PATCH] kernel/trace: fix compiler warning

The patch fixes the following compiler warning:
CC kernel/trace/trace_events.o
kernel/trace/trace_events.c: In function 'event_enable_read'
kernel/trace/trace_events.c:693: warning: 'flags' may be used \
uninitialized in this function

Signed-off-by: Qiaowei Ren <[email protected]>
---
kernel/trace/trace_events.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index e71ffd4..b7915f2 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -690,7 +690,7 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
loff_t *ppos)
{
struct ftrace_event_file *file;
- unsigned long flags;
+ unsigned long flags = 0;
char buf[4] = "0";

mutex_lock(&event_mutex);
--
1.7.1


2014-02-11 16:03:54

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] kernel/trace: fix compiler warning

On Tue, 11 Feb 2014 23:41:41 +0800
Qiaowei Ren <[email protected]> wrote:

> The patch fixes the following compiler warning:
> CC kernel/trace/trace_events.o
> kernel/trace/trace_events.c: In function 'event_enable_read'
> kernel/trace/trace_events.c:693: warning: 'flags' may be used \
> uninitialized in this function

You don't happen to have the branch profilers enabled?

Is CONFIG_TRACE_BRANCH_PROFILING set?

>
> Signed-off-by: Qiaowei Ren <[email protected]>
> ---
> kernel/trace/trace_events.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index e71ffd4..b7915f2 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -690,7 +690,7 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
> loff_t *ppos)
> {
> struct ftrace_event_file *file;
> - unsigned long flags;
> + unsigned long flags = 0;
> char buf[4] = "0";
>
> mutex_lock(&event_mutex);


False warning, and most likely because the branch profilers screw up
gcc's ability to figure these things out.

Here's the content of that function:

mutex_lock(&event_mutex);
file = event_file_data(filp);
if (likely(file))
flags = file->flags;
mutex_unlock(&event_mutex);

if (!file)
return -ENODEV;

if (flags & FTRACE_EVENT_FL_ENABLED &&


Pretty obvious that flags can not be used uninitialized. If you happen
to have BRANCH profiling enabled, you must ignore all the gcc "might be
used uninitialized" warnings. They are useless.

This is not a bug, sorry.

-- Steve