2005-03-05 15:19:35

by Mikael Pettersson

[permalink] [raw]
Subject: [PATCH][2.4.30-pre2] fix undefined behaviour in cistpl.c

Compiling drivers/pcmcia/cistpl.c with gcc-4.0 generates this warning:

cistpl.c: In function 'read_cis_mem':
cistpl.c:143: warning: 'sys' is used uninitialized in this function

Note 'is' not 'may be'. And there is indeed a control flow path in
which 'sys' is updated with '+=' even though it has no initial value.
Luckily 'sys' is reassigned later before being used, making this
assignment redundant, so the fix is to simply remove it.

This problem is not present in the 2.6 kernel.

Signed-off-by: Mikael Pettersson <[email protected]>

--- linux-2.4.30-pre2/drivers/pcmcia/cistpl.c.~1~ 2004-02-18 15:16:23.000000000 +0100
+++ linux-2.4.30-pre2/drivers/pcmcia/cistpl.c 2005-03-05 15:51:37.000000000 +0100
@@ -140,7 +140,6 @@ int read_cis_mem(socket_info_t *s, int a
} else {
u_int inc = 1;
if (attr) { mem->flags |= MAP_ATTRIB; inc++; addr *= 2; }
- sys += (addr & (s->cap.map_size-1));
mem->card_start = addr & ~(s->cap.map_size-1);
while (len) {
set_cis_map(s, mem);


2005-03-07 21:25:38

by Marcelo Tosatti

[permalink] [raw]
Subject: Re: [PATCH][2.4.30-pre2] fix undefined behaviour in cistpl.c

On Sat, Mar 05, 2005 at 04:17:18PM +0100, Mikael Pettersson wrote:
> Compiling drivers/pcmcia/cistpl.c with gcc-4.0 generates this warning:
>
> cistpl.c: In function 'read_cis_mem':
> cistpl.c:143: warning: 'sys' is used uninitialized in this function
>
> Note 'is' not 'may be'. And there is indeed a control flow path in
> which 'sys' is updated with '+=' even though it has no initial value.
> Luckily 'sys' is reassigned later before being used, making this
> assignment redundant, so the fix is to simply remove it.

Indeed - applied, thanks Mikael.

> This problem is not present in the 2.6 kernel.
>
> Signed-off-by: Mikael Pettersson <[email protected]>
>
> --- linux-2.4.30-pre2/drivers/pcmcia/cistpl.c.~1~ 2004-02-18 15:16:23.000000000 +0100
> +++ linux-2.4.30-pre2/drivers/pcmcia/cistpl.c 2005-03-05 15:51:37.000000000 +0100
> @@ -140,7 +140,6 @@ int read_cis_mem(socket_info_t *s, int a
> } else {
> u_int inc = 1;
> if (attr) { mem->flags |= MAP_ATTRIB; inc++; addr *= 2; }
> - sys += (addr & (s->cap.map_size-1));
> mem->card_start = addr & ~(s->cap.map_size-1);
> while (len) {
> set_cis_map(s, mem);