[PATCH] Warning fix for "comparison is always false"

Pavel Roskin proski at gnu.org
Tue Mar 16 18:00:42 GMT 2004


Hello!

The attached patch fixes all warnings of this type:

drivers/pcmcia/i82365.c: In function `i365_set_io_map':
drivers/pcmcia/i82365.c:1134: warning: comparison is always false due to
limited range of data type

The warnings are caused by comparing variables of the type ioaddr_t to
0xffff.  The type ioaddr_t is PCMCIA specific despite its generic sounding
name.  It is unsigned int on ARM and unsigned short on other platforms.

The check makes sense for ARM architecture.  On the driver level, it makes
sense for all other architectures as well.  The limitation on the address
is in the hardware.  Other hardware doesn't have this limitation on the
port addresses.

What makes this check unneeded for now on non-ARM architectures is another
limitation - in cardmgr.  cardmgr also uses ioaddr_t in the
AdjustResourceInfo request, so it can only pass 16-bit values for fort
addresses.

The patch changes the check to hide the problem from gcc.  Some day gcc
will outwit us, but by then we'll hopefully use a new cardmgr and unsigned
long instead of ioaddr_t.

For now, it's important to fix all known warnings to make the new ones
visible should they crop up (and they just did - see patch for unused
version variable).

-- 
Regards,
Pavel Roskin
-------------- next part --------------
--- linux.orig/drivers/pcmcia/i82092.c
+++ linux/drivers/pcmcia/i82092.c
@@ -674,7 +674,8 @@ static int i82092aa_set_io_map(struct pc
 		leave("i82092aa_set_io_map with invalid map");
 		return -EINVAL;
 	}
-	if ((io->start > 0xffff) || (io->stop > 0xffff) || (io->stop < io->start)){
+	if ((io->start & ~0xffff) || (io->stop & ~0xffff) ||
+	    (io->stop < io->start)) {
 		leave("i82092aa_set_io_map with invalid io");
 		return -EINVAL;
 	}
--- linux.orig/drivers/pcmcia/i82365.c
+++ linux/drivers/pcmcia/i82365.c
@@ -1131,7 +1131,7 @@ static int i365_set_io_map(u_short sock,
 	  "%#4.4x-%#4.4x)\n", sock, io->map, io->flags,
 	  io->speed, io->start, io->stop);
     map = io->map;
-    if ((map > 1) || (io->start > 0xffff) || (io->stop > 0xffff) ||
+    if ((map > 1) || (io->start & ~0xffff) || (io->stop & ~0xffff) ||
 	(io->stop < io->start)) return -EINVAL;
     /* Turn off the window before changing anything */
     if (i365_get(sock, I365_ADDRWIN) & I365_ENA_IO(map))
--- linux.orig/drivers/pcmcia/tcic.c
+++ linux/drivers/pcmcia/tcic.c
@@ -794,7 +794,7 @@ static int tcic_set_io_map(struct pcmcia
     debug(1, "SetIOMap(%d, %d, %#2.2x, %d ns, "
 	  "%#4.4x-%#4.4x)\n", psock, io->map, io->flags,
 	  io->speed, io->start, io->stop);
-    if ((io->map > 1) || (io->start > 0xffff) || (io->stop > 0xffff) ||
+    if ((io->map > 1) || (io->start & ~0xffff) || (io->stop & ~0xffff) ||
 	(io->stop < io->start)) return -EINVAL;
     tcic_setw(TCIC_ADDR+2, TCIC_ADR2_INDREG | (psock << TCIC_SS_SHFT));
     addr = TCIC_IWIN(psock, io->map);


More information about the linux-pcmcia mailing list