diff options
author | bde <bde@FreeBSD.org> | 1996-09-24 17:47:59 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1996-09-24 17:47:59 +0000 |
commit | 5200f0a42d198234134eaafe2ac7926dcd528c81 (patch) | |
tree | 077a8f06463134d6fdc824a51d6c56036ea53960 /sys | |
parent | a0082297a8ede5618e20e7cfc0aca508fe867b5b (diff) | |
download | FreeBSD-src-5200f0a42d198234134eaafe2ac7926dcd528c81.zip FreeBSD-src-5200f0a42d198234134eaafe2ac7926dcd528c81.tar.gz |
Fixed a few hundred warnings (2400 in LINT) for signed vs unsigned
comparisons in the inb() and outb() macros. I decided that int args
are OK here. Any type that can hold a u_int16_t without overflow
is correct, and 32-bit types are optimal.
Introduced a few tens of warnings (100 in LINT) for use of pessimized
(short) types for the port arg. Only a few drivers are affected by
this. u_short pessimizations aren't detected.
Added `__extension__' before the statement-expression in inb() so
that it can be compiled without warnings by gcc -pedantic.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/amd64/include/cpufunc.h | 19 | ||||
-rw-r--r-- | sys/i386/include/cpufunc.h | 19 |
2 files changed, 26 insertions, 12 deletions
diff --git a/sys/amd64/include/cpufunc.h b/sys/amd64/include/cpufunc.h index 7f23b8e..83acd1d 100644 --- a/sys/amd64/include/cpufunc.h +++ b/sys/amd64/include/cpufunc.h @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cpufunc.h,v 1.54 1996/08/01 20:29:28 wollman Exp $ + * $Id: cpufunc.h,v 1.55 1996/09/12 11:08:07 asami Exp $ */ /* @@ -112,18 +112,25 @@ fls(int mask) * Use an expression-statement instead of a conditional expression * because gcc-2.6.0 would promote the operands of the conditional * and produce poor code for "if ((inb(var) & const1) == const2)". + * + * The unnecessary test `(port) < 0x10000' is to generate a warning if + * the `port' has type u_short or smaller. Such types are pessimal. + * This actually only works for signed types. The range check is + * careful to avoid generating warnings. */ -#define inb(port) ({ \ +#define inb(port) __extension__ ({ \ u_char _data; \ - if (__builtin_constant_p((int) (port)) && (port) < 256ul) \ + if (__builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000) \ _data = inbc(port); \ else \ _data = inbv(port); \ _data; }) -#define outb(port, data) \ - (__builtin_constant_p((int) (port)) && (port) < 256ul \ - ? outbc(port, data) : outbv(port, data)) +#define outb(port, data) ( \ + __builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000 \ + ? outbc(port, data) : outbv(port, data)) static __inline u_char inbc(u_int port) diff --git a/sys/i386/include/cpufunc.h b/sys/i386/include/cpufunc.h index 7f23b8e..83acd1d 100644 --- a/sys/i386/include/cpufunc.h +++ b/sys/i386/include/cpufunc.h @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cpufunc.h,v 1.54 1996/08/01 20:29:28 wollman Exp $ + * $Id: cpufunc.h,v 1.55 1996/09/12 11:08:07 asami Exp $ */ /* @@ -112,18 +112,25 @@ fls(int mask) * Use an expression-statement instead of a conditional expression * because gcc-2.6.0 would promote the operands of the conditional * and produce poor code for "if ((inb(var) & const1) == const2)". + * + * The unnecessary test `(port) < 0x10000' is to generate a warning if + * the `port' has type u_short or smaller. Such types are pessimal. + * This actually only works for signed types. The range check is + * careful to avoid generating warnings. */ -#define inb(port) ({ \ +#define inb(port) __extension__ ({ \ u_char _data; \ - if (__builtin_constant_p((int) (port)) && (port) < 256ul) \ + if (__builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000) \ _data = inbc(port); \ else \ _data = inbv(port); \ _data; }) -#define outb(port, data) \ - (__builtin_constant_p((int) (port)) && (port) < 256ul \ - ? outbc(port, data) : outbv(port, data)) +#define outb(port, data) ( \ + __builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000 \ + ? outbc(port, data) : outbv(port, data)) static __inline u_char inbc(u_int port) |