Re: [PATCH 1/1] kernel/trace: gcc warning: uninitialized variable.

From: Steven Rostedt
Date: Fri May 11 2012 - 23:08:46 EST


On Fri, 2012-05-11 at 23:26 -0300, Raphael Santana carvalho wrote:
> >From 2f1490c5e8e2a393d9376d959e2ff6836757f51a Mon Sep 17 00:00:00 2001
> From: Raphael S.Carvalho <utroz@xxxxxxxxxxxxx>
> Date: Fri, 11 May 2012 22:58:43 -0300
> Subject: [PATCH 1/1] kernel/trace: gcc warning: uninitialized variable.
>
> I've received a problem in this file when I was compiling my own kernel.
> It's a simple uninitialized variable, so that gcc is warning about it.
>
> The function is actually working correctly, because it's impossible to use the
> variable(page2) uninitialized because it's only referenced if nr_pages == 2,
> and we will have previously set it in that case.

Correct.

>
> gcc version 4.5.2 (GCC) - Follows the warning:

It's a bug in gcc. If you use gcc 4.6 or later it does not warn.

As this code may change in the future, I don't want to hide errors that
gcc 4.6 could catch. Thus I'm not going to take this patch.

Don't feel bad, you're probably the 5th person I declined this change
from. At least you noticed that it was just gcc complaining and did not
blindly set the variable to NULL.

-- Steve

> kernel/trace/trace.c:3755:8 warning: 'page2': may be used uninitialized in this function
>
> Signed-off-by: Raphael S.Carvalho <utroz@xxxxxxxxxxxxx>
> ---
> kernel/trace/trace.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 2a22255..4ffff83 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3752,7 +3752,7 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
> int nr_pages = 1;
> ssize_t written;
> void *page1;
> - void *page2;
> + void *uninitialized_var(page2);
> int offset;
> int size;
> int len;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/