2006-05-10 03:00:17

by Daniel Walker

[permalink] [raw]
Subject: [PATCH -mm] matroxfb_maven gcc 4.1 warning fix

It looks possible that the PLL and clock functions might get into a condition
when these stack variables would get used/returned with uninitialized
data . So it needs further review ..

Fixes the following warning,

drivers/video/matrox/matroxfb_maven.c: In function 'maven_out_compute':
drivers/video/matrox/matroxfb_maven.c:287: warning: 'p' may be used uninitialized in this function
drivers/video/matrox/matroxfb_maven.c:718: warning: 'h2' may be used uninitialized in this function
drivers/video/matrox/matroxfb_maven.c:718: warning: 'b' may be used uninitialized in this function
drivers/video/matrox/matroxfb_maven.c:718: warning: 'a' may be used uninitialized in this function

Signed-Off-By: Daniel Walker <[email protected]>

Index: linux-2.6.16/drivers/video/matrox/matroxfb_maven.c
===================================================================
--- linux-2.6.16.orig/drivers/video/matrox/matroxfb_maven.c
+++ linux-2.6.16/drivers/video/matrox/matroxfb_maven.c
@@ -284,7 +284,7 @@ static unsigned int matroxfb_mavenclock(
unsigned int* in, unsigned int* feed, unsigned int* post,
unsigned int* htotal2) {
unsigned int fvco;
- unsigned int p;
+ unsigned int p = 0;

fvco = matroxfb_PLL_mavenclock(&maven1000_pll, ctl, htotal, vtotal, in, feed, &p, htotal2);
if (!fvco)
@@ -715,7 +715,10 @@ static int maven_find_exact_clocks(unsig
m->regs[0x82] = 0x81;

for (x = 0; x < 8; x++) {
- unsigned int a, b, c, h2;
+ unsigned int a = 0;
+ unsigned int b = 0;
+ unsigned int h2 = 0;
+ unsigned int c;
unsigned int h = ht + 2 + x;

if (!matroxfb_mavenclock((m->mode == MATROXFB_OUTPUT_MODE_PAL) ? &maven_PAL : &maven_NTSC, h, vt, &a, &b, &c, &h2)) {


2006-05-10 10:16:13

by Petr Vandrovec

[permalink] [raw]
Subject: Re: [PATCH -mm] matroxfb_maven gcc 4.1 warning fix

Daniel Walker wrote:
> It looks possible that the PLL and clock functions might get into a condition
> when these stack variables would get used/returned with uninitialized
> data . So it needs further review ..

May I veto this? Please fix gcc instead, it does its analysis incorrectly.
matroxfb_PLL_mavenclock either returns 0, or initializes all arguments it gets (if
not, then please show me code path which returns non-zero and does not set
h2/post/in/feed). And matroxfb_mavenclock either returns EINVAL, or sets *post.
And a,b & h2 are used in maven_find_exact_clocks() are used only if
matroxfb_mavenclock returned 0 - and in this case a,b & h2 were always set.

Thanks,
Petr Vandrovec


> Fixes the following warning,
>
> drivers/video/matrox/matroxfb_maven.c: In function 'maven_out_compute':
> drivers/video/matrox/matroxfb_maven.c:287: warning: 'p' may be used uninitialized in this function
> drivers/video/matrox/matroxfb_maven.c:718: warning: 'h2' may be used uninitialized in this function
> drivers/video/matrox/matroxfb_maven.c:718: warning: 'b' may be used uninitialized in this function
> drivers/video/matrox/matroxfb_maven.c:718: warning: 'a' may be used uninitialized in this function

P.S.: It is off-topic for LKML, but this one is my favorite, it comes from
ncpfs I maintain...

vana:/usr/src/hg/ncpfs/lib# cat test.c
#include <pthread.h>
#include <stdio.h>

pthread_mutex_t nds_ring_lock;

extern int test(void);

static int __NWCCGetServerAddressPtr(int* count) {
if (test()) {
return 1;
}
*count = 0;
return 0;
}

void NWDXFindConnection(void) {
int connaddresses;
int err2;

pthread_mutex_lock(&nds_ring_lock);
err2 = __NWCCGetServerAddressPtr(&connaddresses);
pthread_mutex_unlock(&nds_ring_lock);
if (err2)
return;
printf("ConnAddress is uninitialized? %u\n", connaddresses);
}


vana:/usr/src/hg/ncpfs/lib# gcc -v -O2 -W -c test.c
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --with-tune=i686 --enable-checking=release i486-linux-gnu
Thread model: posix
...
gcc version 4.0.4 20060422 (prerelease) (Debian 4.0.3-2)
GNU C version 4.0.4 20060422 (prerelease) (Debian 4.0.3-2) (i486-linux-gnu)
compiled by GNU C version 4.0.4 20060422 (prerelease) (Debian 4.0.3-2).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
test.c: In function 'NWDXFindConnection':
test.c:17: warning: 'connaddresses' may be used uninitialized in this function