lkml.org 
[lkml]   [2006]   [Aug]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] arch/i386/kernel/cpu/transmeta.c, kernel 2.6.17.8
Forrest Voight wrote:
> Corrects warning:
>
> CC arch/i386/kernel/cpu/centaur.o
> CC arch/i386/kernel/cpu/transmeta.o
> arch/i386/kernel/cpu/transmeta.c: In function 'init_transmeta':
> arch/i386/kernel/cpu/transmeta.c:12: warning: 'cpu_freq' may be used
> uninitialized in this function
> CC arch/i386/kernel/cpu/intel.o
>

This is a false alarm.
Here's the code (details omitted):

if ( max >= 0x80860001 ) {
cpuid(0x80860001, &dummy, &cpu_rev, &cpu_freq, &cpu_flags);
^^^^^^^^^
}
if ( max >= 0x80860002 ) {
printk(KERN_INFO "CPU: Processor %u MHz\n", cpu_freq);
}

Note the two conditions: if second is true, the first is
true too, so both branches are executed, so first cpu_freq
is initialized (by cpuid() call) and next it's used in printk.

The same thing will be done by the following code:

if ( max >= 0x80860001 ) {
cpuid(0x80860001, &dummy, &cpu_rev, &cpu_freq, &cpu_flags);
if ( max >= 0x80860002 ) {
printk(KERN_INFO "CPU: Processor %u MHz\n", cpu_freq);
}
}

and in this case gcc will not (hopefully) issue the warning.

BTW, cpu_rev gets initialized to 0 here as well - looks like
it's done also just to prevent warning message.

/mjt

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

\
 
 \ /
  Last update: 2006-08-09 22:21    [W:0.042 / U:0.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site