Re: [PATCH] TRACING: Fix a copmile warning

From: Arnaud Lacombe
Date: Mon Jul 25 2011 - 15:43:40 EST


Hi,

On Mon, Jul 25, 2011 at 2:32 PM, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> On Mon, 2011-07-18 at 17:40 +0800, stufever@xxxxxxxxx wrote:
>> From: Wang Shaoyan <wangshaoyan.pt@xxxxxxxxxx>
>>
>> It's harmless but annyoing.
>>   kernel/trace/trace_printk.c: In function 'module_trace_bprintk_format_notify':
>>   kernel/trace/trace_printk.c:52: warning: 'fmt' may be used uninitialized in this function
>
> I prefer not to add this patch. Fix gcc. Actually some gcc's do not warn
> on this, others do. Here's the code that confuses gcc:
>
>                tb_fmt = kmalloc(sizeof(*tb_fmt), GFP_KERNEL);
>                if (tb_fmt)
>                        fmt = kmalloc(strlen(*iter) + 1, GFP_KERNEL);
>                if (tb_fmt && fmt) {
>                        list_add_tail(&tb_fmt->list, &trace_bprintk_fmt_list);
>                        strcpy(fmt, *iter);
>                        tb_fmt->fmt = fmt;
>                        *iter = tb_fmt->fmt;
>
>
> fmt will never be looked at if tb_fmt is NULL, and fmt is initialized if
> tb_fmt is not NULL.
>
Actually, we have a special uninitialized_var(x) macro to handle such
false positive. From include/linux/compiler-gcc.h:

/*
* A trick to suppress uninitialized variable warning without generating any
* code
*/
#define uninitialized_var(x) x = x

- Arnaud

> -- Steve
>
>>
>> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
>> Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
>> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
>> Signed-off-by: Wang Shaoyan <wangshaoyan.pt@xxxxxxxxxx>
>>
>> ---
>>  kernel/trace/trace_printk.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
>> index 1f06468..1a5fff8 100644
>> --- a/kernel/trace/trace_printk.c
>> +++ b/kernel/trace/trace_printk.c
>> @@ -49,7 +49,7 @@ static
>>  void hold_module_trace_bprintk_format(const char **start, const char **end)
>>  {
>>       const char **iter;
>> -     char *fmt;
>> +     char *fmt = NULL;
>>
>>       mutex_lock(&btrace_mutex);
>>       for (iter = start; iter < end; iter++) {
>
>
> --
> 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/
>
--
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/