From hselasky@c2i.net  Fri May 13 13:28:03 2005
Return-Path: <hselasky@c2i.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 1AF2316A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 13 May 2005 13:28:03 +0000 (GMT)
Received: from swip.net (mailfe01.swip.net [212.247.154.1])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 801D243D64
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 13 May 2005 13:28:02 +0000 (GMT)
	(envelope-from hselasky@c2i.net)
Received: from mp-217-199-167.daxnet.no ([193.217.199.167] verified)
  by mailfe01.swip.net (CommuniGate Pro SMTP 4.3c5)
  with ESMTP id 368001340 for FreeBSD-gnats-submit@freebsd.org; Fri, 13 May 2005 15:28:01 +0200
Message-Id: <200505131528.46810.hselasky@c2i.net>
Date: Fri, 13 May 2005 15:28:46 +0200
From: Hans Petter Selasky <hselasky@c2i.net>
Reply-To: hselasky@c2i.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: problem in "sys/i386/include/bus.h" cause random freezes

>Number:         80980
>Category:       kern
>Synopsis:       [i386] [patch] problem in "sys/i386/include/bus.h" cause random freezes
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    brucec
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 13 13:30:01 GMT 2005
>Closed-Date:    Sun Feb 13 18:04:24 UTC 2011
>Last-Modified:  Sun Feb 13 18:10:13 UTC 2011
>Originator:     HPS
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD 6.0-CURRENT FreeBSD 6.0-CURRENT #45: Mon Mar 21 15:40:17 CET 
2005 root@:/usr/obj/usr/src/sys/custom i386

>Description:

When using I386_BUS_SPACE_MEM, neither "bus_space_read_XXX" nor 
"bus_space_write_XXX" checks for length/count equal to zero. This can cause 
random freezes with some drivers.

Actually the code is like this, just in assembly:

while(--count)
{
 I/O
}

which is not correct. This happens several places in "sys/i386/include/bus.h".

>How-To-Repeat:

bus_space_read_multi_2(t,h,0,&buf[0],0); will freeze the system !

"t","h", and "buf" must be valid though, and "t" must equal 
I386_BUS_SPACE_MEM.

>Fix:

Wrap all "__asm __volatile" statements inside:

if(count != 0)
{

}
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->brucec  
Responsible-Changed-By: brucec 
Responsible-Changed-When: Sat Jun 19 18:20:52 UTC 2010 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80980 

From: Bruce Cran <bruce@cran.org.uk>
To: bug-followup@FreeBSD.org, hselasky@c2i.net
Cc:  
Subject: Re: kern/80980: [i386] [patch] problem in "sys/i386/include/bus.h"
 cause random freezes
Date: Sun, 28 Nov 2010 21:49:23 +0000

 I'm not sure if it's a bug in the drivers that they try and do the
 read/write with a length of zero, so adding the check may be working
 around bugs that would otherwise be made apparent when the system
 crashes or freezes.
 
 -- 
 Bruce

From: Hans Petter Selasky <hselasky@c2i.net>
To: Bruce Cran <bruce@cran.org.uk>
Cc: bug-followup@freebsd.org
Subject: Re: kern/80980: [i386] [patch] problem in "sys/i386/include/bus.h" cause random freezes
Date: Mon, 29 Nov 2010 08:33:56 +0100

 On Sunday 28 November 2010 22:49:23 Bruce Cran wrote:
 > I'm not sure if it's a bug in the drivers that they try and do the
 > read/write with a length of zero, so adding the check may be working
 > around bugs that would otherwise be made apparent when the system
 > crashes or freezes.
 
 Maybe this should be properly documented in man bus_space_read_multi_1 ?
 
 --HPS

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/80980: commit references a PR
Date: Thu,  2 Dec 2010 22:19:40 +0000 (UTC)

 Author: brucec
 Date: Thu Dec  2 22:19:30 2010
 New Revision: 216134
 URL: http://svn.freebsd.org/changeset/base/216134
 
 Log:
   Disallow passing in a count of zero bytes to the bus_space(9) functions.
   
   Passing a count of zero on i386 and amd64 for [I386|AMD64]_BUS_SPACE_MEM
   causes a crash/hang since the 'loop' instruction decrements the counter
   before checking if it's zero.
   
   PR:	kern/80980
   Discussed with:	jhb
 
 Modified:
   head/share/man/man9/bus_space.9
   head/sys/amd64/include/bus.h
   head/sys/arm/include/bus.h
   head/sys/i386/include/bus.h
   head/sys/ia64/include/bus.h
   head/sys/mips/include/bus.h
   head/sys/pc98/include/bus.h
   head/sys/powerpc/include/bus.h
   head/sys/sparc64/include/bus.h
   head/sys/sun4v/include/bus.h
 
 Modified: head/share/man/man9/bus_space.9
 ==============================================================================
 --- head/share/man/man9/bus_space.9	Thu Dec  2 22:00:57 2010	(r216133)
 +++ head/share/man/man9/bus_space.9	Thu Dec  2 22:19:30 2010	(r216134)
 @@ -719,6 +719,9 @@ or which return data read from bus space
  do not obviously return an error code) do not fail.
  They could only fail
  if given invalid arguments, and in that case their behaviour is undefined.
 +Functions which take a count of bytes must not pass in a count of zero; 
 +doing so will cause a panic if the kernel was compiled with 
 +.Cd "options INVARIANTS" .
  .Sh TYPES
  Several types are defined in
  .In machine/bus.h
 
 Modified: head/sys/amd64/include/bus.h
 ==============================================================================
 --- head/sys/amd64/include/bus.h	Thu Dec  2 22:00:57 2010	(r216133)
 +++ head/sys/amd64/include/bus.h	Thu Dec  2 22:19:30 2010	(r216134)
 @@ -104,6 +104,9 @@
  #ifndef _AMD64_BUS_H_
  #define _AMD64_BUS_H_
  
 +#include <sys/param.h>
 +#include <sys/systm.h>
 +
  #include <machine/_bus.h>
  #include <machine/cpufunc.h>
  
 @@ -268,7 +271,7 @@ static __inline void
  bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
  		       bus_size_t offset, u_int8_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO)
  		insb(bsh + offset, addr, count);
  	else {
 @@ -289,7 +292,7 @@ static __inline void
  bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
  		       bus_size_t offset, u_int16_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO)
  		insw(bsh + offset, addr, count);
  	else {
 @@ -310,7 +313,7 @@ static __inline void
  bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
  		       bus_size_t offset, u_int32_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO)
  		insl(bsh + offset, addr, count);
  	else {
 @@ -356,7 +359,7 @@ static __inline void
  bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, u_int8_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -388,7 +391,7 @@ static __inline void
  bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, u_int16_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -420,7 +423,7 @@ static __inline void
  bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, u_int32_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -532,7 +535,7 @@ static __inline void
  bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, const u_int8_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO)
  		outsb(bsh + offset, addr, count);
  	else {
 @@ -553,7 +556,7 @@ static __inline void
  bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, const u_int16_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO)
  		outsw(bsh + offset, addr, count);
  	else {
 @@ -574,7 +577,7 @@ static __inline void
  bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, const u_int32_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO)
  		outsl(bsh + offset, addr, count);
  	else {
 @@ -621,7 +624,7 @@ static __inline void
  bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
  			 bus_size_t offset, const u_int8_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -653,7 +656,7 @@ static __inline void
  bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
  			 bus_size_t offset, const u_int16_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -685,7 +688,7 @@ static __inline void
  bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
  			 bus_size_t offset, const u_int32_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -877,6 +880,7 @@ bus_space_copy_region_1(bus_space_tag_t 
  	bus_space_handle_t addr1 = bsh1 + off1;
  	bus_space_handle_t addr2 = bsh2 + off2;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO) {
  		if (addr1 >= addr2) {
  			/* src after dest: copy forward */
 @@ -912,6 +916,7 @@ bus_space_copy_region_2(bus_space_tag_t 
  	bus_space_handle_t addr1 = bsh1 + off1;
  	bus_space_handle_t addr2 = bsh2 + off2;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO) {
  		if (addr1 >= addr2) {
  			/* src after dest: copy forward */
 @@ -947,6 +952,7 @@ bus_space_copy_region_4(bus_space_tag_t 
  	bus_space_handle_t addr1 = bsh1 + off1;
  	bus_space_handle_t addr2 = bsh2 + off2;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == AMD64_BUS_SPACE_IO) {
  		if (addr1 >= addr2) {
  			/* src after dest: copy forward */
 
 Modified: head/sys/arm/include/bus.h
 ==============================================================================
 --- head/sys/arm/include/bus.h	Thu Dec  2 22:00:57 2010	(r216133)
 +++ head/sys/arm/include/bus.h	Thu Dec  2 22:19:30 2010	(r216134)
 @@ -66,6 +66,9 @@
  #ifndef _MACHINE_BUS_H_
  #define _MACHINE_BUS_H_
  
 +#include <sys/param.h>
 +#include <sys/systm.h>
 +
  #include <machine/_bus.h>
  
  /*
 @@ -318,21 +321,29 @@ struct bus_space {
   * Bus read multiple operations.
   */
  #define	bus_space_read_multi_1(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_multi_1: count == 0"));	\
  	__bs_nonsingle(rm,1,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_2(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_multi_2: count == 0"));	\
  	__bs_nonsingle(rm,2,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_4(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_multi_4: count == 0"));	\
  	__bs_nonsingle(rm,4,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_8(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_multi_8: count == 0"));	\
  	__bs_nonsingle(rm,8,(t),(h),(o),(a),(c))
  
  #define	bus_space_read_multi_stream_1(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_multi_stream_1: count == 0"));	\
  	__bs_nonsingle_s(rm,1,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_stream_2(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_multi_stream_2: count == 0"));	\
  	__bs_nonsingle_s(rm,2,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_stream_4(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_multi_stream_4: count == 0"));	\
  	__bs_nonsingle_s(rm,4,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_stream_8(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_multi_stream_8: count == 0"));	\
  	__bs_nonsingle_s(rm,8,(t),(h),(o),(a),(c))
  
  
 @@ -340,21 +351,29 @@ struct bus_space {
   * Bus read region operations.
   */
  #define	bus_space_read_region_1(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_region_1: count == 0"));	\
  	__bs_nonsingle(rr,1,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_2(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_region_2: count == 0"));	\
  	__bs_nonsingle(rr,2,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_4(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_region_4: count == 0"));	\
  	__bs_nonsingle(rr,4,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_8(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_region_8: count == 0"));	\
  	__bs_nonsingle(rr,8,(t),(h),(o),(a),(c))
  
  #define	bus_space_read_region_stream_1(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_region_stream_1: count == 0"));\
  	__bs_nonsingle_s(rr,1,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_stream_2(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_region_stream_2: count == 0"));\
  	__bs_nonsingle_s(rr,2,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_stream_4(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_region_stream_4: count == 0"));\
  	__bs_nonsingle_s(rr,4,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_stream_8(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_region_stream_8 count == 0"));	\
  	__bs_nonsingle_s(rr,8,(t),(h),(o),(a),(c))
  
  
 @@ -376,21 +395,29 @@ struct bus_space {
   * Bus write multiple operations.
   */
  #define	bus_space_write_multi_1(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_multi_1: count == 0"));	\
  	__bs_nonsingle(wm,1,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_2(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_multi_2: count == 0"));	\
  	__bs_nonsingle(wm,2,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_4(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_multi_4: count == 0"));	\
  	__bs_nonsingle(wm,4,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_8(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_multi_8: count == 0"));	\
  	__bs_nonsingle(wm,8,(t),(h),(o),(a),(c))
  
  #define	bus_space_write_multi_stream_1(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_write_multi_stream_1: count == 0"));\
  	__bs_nonsingle_s(wm,1,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_stream_2(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_write_multi_stream_2: count == 0"));\
  	__bs_nonsingle_s(wm,2,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_stream_4(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_write_multi_stream_4: count == 0"));\
  	__bs_nonsingle_s(wm,4,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_stream_8(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_write_multi_stream_8: count == 0"));\
  	__bs_nonsingle_s(wm,8,(t),(h),(o),(a),(c))
  
  
 @@ -398,34 +425,50 @@ struct bus_space {
   * Bus write region operations.
   */
  #define	bus_space_write_region_1(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_region_1: count == 0"));	\
  	__bs_nonsingle(wr,1,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_2(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_region_2: count == 0"));	\
  	__bs_nonsingle(wr,2,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_4(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_region_4: count == 0"));	\
  	__bs_nonsingle(wr,4,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_8(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_region_8: count == 0"));	\
  	__bs_nonsingle(wr,8,(t),(h),(o),(a),(c))
  
  #define	bus_space_write_region_stream_1(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_region_stream_1: count == 0"));		\
  	__bs_nonsingle_s(wr,1,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_stream_2(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_region_stream_2: count == 0"));		\
  	__bs_nonsingle_s(wr,2,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_stream_4(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_region_stream_4: count == 0"));		\
  	__bs_nonsingle_s(wr,4,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_stream_8(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_region_stream_8: count == 0"));		\
  	__bs_nonsingle_s(wr,8,(t),(h),(o),(a),(c))
  
  
  /*
   * Set multiple operations.
   */
 -#define	bus_space_set_multi_1(t, h, o, v, c)				\
 +#define	bus_space_set_multi_1(t, h, o, v, c)			\
 +	KASSERT(c != 0, ("bus_space_set_multi_1: count == 0"));	\
  	__bs_set(sm,1,(t),(h),(o),(v),(c))
 -#define	bus_space_set_multi_2(t, h, o, v, c)				\
 +#define	bus_space_set_multi_2(t, h, o, v, c)			\
 +	KASSERT(c != 0, ("bus_space_set_multi_2: count == 0"));	\
  	__bs_set(sm,2,(t),(h),(o),(v),(c))
 -#define	bus_space_set_multi_4(t, h, o, v, c)				\
 +#define	bus_space_set_multi_4(t, h, o, v, c)			\
 +	KASSERT(c != 0, ("bus_space_set_multi_4: count == 0"));	\
  	__bs_set(sm,4,(t),(h),(o),(v),(c))
 -#define	bus_space_set_multi_8(t, h, o, v, c)				\
 +#define	bus_space_set_multi_8(t, h, o, v, c)			\
 +	KASSERT(c != 0, ("bus_space_set_multi_8: count == 0"));	\
  	__bs_set(sm,8,(t),(h),(o),(v),(c))
  
  
 @@ -433,25 +476,33 @@ struct bus_space {
   * Set region operations.
   */
  #define	bus_space_set_region_1(t, h, o, v, c)				\
 +	KASSERT(c != 0, ("bus_space_set_region_1: count == 0"));	\
  	__bs_set(sr,1,(t),(h),(o),(v),(c))
  #define	bus_space_set_region_2(t, h, o, v, c)				\
 +	KASSERT(c != 0, ("bus_space_set_region_2: count == 0"));	\
  	__bs_set(sr,2,(t),(h),(o),(v),(c))
  #define	bus_space_set_region_4(t, h, o, v, c)				\
 +	KASSERT(c != 0, ("bus_space_set_region_4: count == 0"));	\
  	__bs_set(sr,4,(t),(h),(o),(v),(c))
  #define	bus_space_set_region_8(t, h, o, v, c)				\
 +	KASSERT(c != 0, ("bus_space_set_region_8: count == 0"));	\
  	__bs_set(sr,8,(t),(h),(o),(v),(c))
  
  
  /*
   * Copy operations.
   */
 -#define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)				\
 +#define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
 +	KASSERT(c != 0, ("bus_space_copy_region_1: count == 0"));	\
  	__bs_copy(1, t, h1, o1, h2, o2, c)
 -#define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)				\
 +#define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
 +	KASSERT(c != 0, ("bus_space_copy_region_2: count == 0"));	\
  	__bs_copy(2, t, h1, o1, h2, o2, c)
 -#define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)				\
 +#define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
 +	KASSERT(c != 0, ("bus_space_copy_region_4: count == 0"));	\
  	__bs_copy(4, t, h1, o1, h2, o2, c)
 -#define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)				\
 +#define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)			\
 +	KASSERT(c != 0, ("bus_space_copy_region_8: count == 0"));	\
  	__bs_copy(8, t, h1, o1, h2, o2, c)
  
  /*
 
 Modified: head/sys/i386/include/bus.h
 ==============================================================================
 --- head/sys/i386/include/bus.h	Thu Dec  2 22:00:57 2010	(r216133)
 +++ head/sys/i386/include/bus.h	Thu Dec  2 22:19:30 2010	(r216134)
 @@ -104,6 +104,9 @@
  #ifndef _I386_BUS_H_
  #define _I386_BUS_H_
  
 +#include <sys/param.h>
 +#include <sys/systm.h>
 +
  #include <machine/_bus.h>
  #include <machine/cpufunc.h>
  
 @@ -272,7 +275,7 @@ static __inline void
  bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
  		       bus_size_t offset, u_int8_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		insb(bsh + offset, addr, count);
  	else {
 @@ -297,7 +300,7 @@ static __inline void
  bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
  		       bus_size_t offset, u_int16_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		insw(bsh + offset, addr, count);
  	else {
 @@ -322,7 +325,7 @@ static __inline void
  bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
  		       bus_size_t offset, u_int32_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		insl(bsh + offset, addr, count);
  	else {
 @@ -372,7 +375,7 @@ static __inline void
  bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, u_int8_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -412,7 +415,7 @@ static __inline void
  bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, u_int16_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -452,7 +455,7 @@ static __inline void
  bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, u_int32_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -572,7 +575,7 @@ static __inline void
  bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, const u_int8_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		outsb(bsh + offset, addr, count);
  	else {
 @@ -597,7 +600,7 @@ static __inline void
  bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, const u_int16_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		outsw(bsh + offset, addr, count);
  	else {
 @@ -622,7 +625,7 @@ static __inline void
  bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
  			bus_size_t offset, const u_int32_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		outsl(bsh + offset, addr, count);
  	else {
 @@ -673,7 +676,7 @@ static __inline void
  bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
  			 bus_size_t offset, const u_int8_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -713,7 +716,7 @@ static __inline void
  bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
  			 bus_size_t offset, const u_int16_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -753,7 +756,7 @@ static __inline void
  bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
  			 bus_size_t offset, const u_int32_t *addr, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO) {
  		int _port_ = bsh + offset;
  #ifdef __GNUCLIKE_ASM
 @@ -818,6 +821,7 @@ bus_space_set_multi_1(bus_space_tag_t ta
  {
  	bus_space_handle_t addr = bsh + offset;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		while (count--)
  			outb(addr, value);
 @@ -832,6 +836,7 @@ bus_space_set_multi_2(bus_space_tag_t ta
  {
  	bus_space_handle_t addr = bsh + offset;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		while (count--)
  			outw(addr, value);
 @@ -846,6 +851,7 @@ bus_space_set_multi_4(bus_space_tag_t ta
  {
  	bus_space_handle_t addr = bsh + offset;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		while (count--)
  			outl(addr, value);
 @@ -882,6 +888,7 @@ bus_space_set_region_1(bus_space_tag_t t
  {
  	bus_space_handle_t addr = bsh + offset;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		for (; count != 0; count--, addr++)
  			outb(addr, value);
 @@ -896,6 +903,7 @@ bus_space_set_region_2(bus_space_tag_t t
  {
  	bus_space_handle_t addr = bsh + offset;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		for (; count != 0; count--, addr += 2)
  			outw(addr, value);
 @@ -910,6 +918,7 @@ bus_space_set_region_4(bus_space_tag_t t
  {
  	bus_space_handle_t addr = bsh + offset;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO)
  		for (; count != 0; count--, addr += 4)
  			outl(addr, value);
 @@ -953,6 +962,7 @@ bus_space_copy_region_1(bus_space_tag_t 
  	bus_space_handle_t addr1 = bsh1 + off1;
  	bus_space_handle_t addr2 = bsh2 + off2;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO) {
  		if (addr1 >= addr2) {
  			/* src after dest: copy forward */
 @@ -988,6 +998,7 @@ bus_space_copy_region_2(bus_space_tag_t 
  	bus_space_handle_t addr1 = bsh1 + off1;
  	bus_space_handle_t addr2 = bsh2 + off2;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO) {
  		if (addr1 >= addr2) {
  			/* src after dest: copy forward */
 @@ -1023,6 +1034,7 @@ bus_space_copy_region_4(bus_space_tag_t 
  	bus_space_handle_t addr1 = bsh1 + off1;
  	bus_space_handle_t addr2 = bsh2 + off2;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (tag == I386_BUS_SPACE_IO) {
  		if (addr1 >= addr2) {
  			/* src after dest: copy forward */
 
 Modified: head/sys/ia64/include/bus.h
 ==============================================================================
 --- head/sys/ia64/include/bus.h	Thu Dec  2 22:00:57 2010	(r216133)
 +++ head/sys/ia64/include/bus.h	Thu Dec  2 22:19:30 2010	(r216134)
 @@ -91,6 +91,9 @@
  #ifndef _MACHINE_BUS_H_
  #define _MACHINE_BUS_H_
  
 +#include <sys/param.h>
 +#include <sys/systm.h>
 +
  #include <machine/_bus.h>
  #include <machine/cpufunc.h>
  
 @@ -298,7 +301,7 @@ static __inline void
  bus_space_read_multi_1(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint8_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_read_multi_io_1(bsh + ofs, bufp, count);
  	else {
 @@ -311,7 +314,7 @@ static __inline void
  bus_space_read_multi_2(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint16_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_read_multi_io_2(bsh + ofs, bufp, count);
  	else {
 @@ -324,7 +327,7 @@ static __inline void
  bus_space_read_multi_4(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint32_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_read_multi_io_4(bsh + ofs, bufp, count);
  	else {
 @@ -337,7 +340,7 @@ static __inline void
  bus_space_read_multi_8(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint64_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_read_multi_io_8(bsh + ofs, bufp, count);
  	else {
 @@ -361,7 +364,7 @@ static __inline void
  bus_space_write_multi_1(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, const uint8_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_write_multi_io_1(bsh + ofs, bufp, count);
  	else {
 @@ -374,7 +377,7 @@ static __inline void
  bus_space_write_multi_2(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, const uint16_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_write_multi_io_2(bsh + ofs, bufp, count);
  	else {
 @@ -387,7 +390,7 @@ static __inline void
  bus_space_write_multi_4(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, const uint32_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_write_multi_io_4(bsh + ofs, bufp, count);
  	else {
 @@ -400,7 +403,7 @@ static __inline void
  bus_space_write_multi_8(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, const uint64_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_write_multi_io_8(bsh + ofs, bufp, count);
  	else {
 @@ -425,7 +428,7 @@ static __inline void
  bus_space_read_region_1(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint8_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_read_region_io_1(bsh + ofs, bufp, count);
  	else {
 @@ -439,7 +442,7 @@ static __inline void
  bus_space_read_region_2(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint16_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_read_region_io_2(bsh + ofs, bufp, count);
  	else {
 @@ -453,7 +456,7 @@ static __inline void
  bus_space_read_region_4(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint32_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_read_region_io_4(bsh + ofs, bufp, count);
  	else {
 @@ -467,7 +470,7 @@ static __inline void
  bus_space_read_region_8(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint64_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_read_region_io_8(bsh + ofs, bufp, count);
  	else {
 @@ -493,7 +496,7 @@ static __inline void
  bus_space_write_region_1(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, const uint8_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_write_region_io_1(bsh + ofs, bufp, count);
  	else {
 @@ -507,7 +510,7 @@ static __inline void
  bus_space_write_region_2(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, const uint16_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_write_region_io_2(bsh + ofs, bufp, count);
  	else {
 @@ -521,7 +524,7 @@ static __inline void
  bus_space_write_region_4(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, const uint32_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_write_region_io_4(bsh + ofs, bufp, count);
  	else {
 @@ -535,7 +538,7 @@ static __inline void
  bus_space_write_region_8(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, const uint64_t *bufp, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_write_region_io_8(bsh + ofs, bufp, count);
  	else {
 @@ -555,7 +558,7 @@ static __inline void
  bus_space_set_multi_1(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint8_t val, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	while (count-- > 0)
  		bus_space_write_1(bst, bsh, ofs, val);
  }
 @@ -564,7 +567,7 @@ static __inline void
  bus_space_set_multi_2(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint16_t val, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	while (count-- > 0)
  		bus_space_write_2(bst, bsh, ofs, val);
  }
 @@ -573,7 +576,7 @@ static __inline void
  bus_space_set_multi_4(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint32_t val, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	while (count-- > 0)
  		bus_space_write_4(bst, bsh, ofs, val);
  }
 @@ -582,7 +585,7 @@ static __inline void
  bus_space_set_multi_8(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint64_t val, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	while (count-- > 0)
  		bus_space_write_8(bst, bsh, ofs, val);
  }
 @@ -603,7 +606,7 @@ static __inline void
  bus_space_set_region_1(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint8_t val, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_set_region_io_1(bsh + ofs, val, count);
  	else {
 @@ -617,7 +620,7 @@ static __inline void
  bus_space_set_region_2(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint16_t val, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_set_region_io_2(bsh + ofs, val, count);
  	else {
 @@ -631,7 +634,7 @@ static __inline void
  bus_space_set_region_4(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint32_t val, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_set_region_io_4(bsh + ofs, val, count);
  	else {
 @@ -645,7 +648,7 @@ static __inline void
  bus_space_set_region_8(bus_space_tag_t bst, bus_space_handle_t bsh,
      bus_size_t ofs, uint64_t val, size_t count)
  {
 -
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO))
  		bus_space_set_region_io_4(bsh + ofs, val, count);
  	else {
 @@ -674,6 +677,7 @@ bus_space_copy_region_1(bus_space_tag_t 
  {
  	uint8_t *dst, *src;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO)) {
  		bus_space_copy_region_io_1(sbsh + sofs, dbsh + dofs, count);
  		return;
 @@ -698,6 +702,7 @@ bus_space_copy_region_2(bus_space_tag_t 
  {
  	uint16_t *dst, *src;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO)) {
  		bus_space_copy_region_io_2(sbsh + sofs, dbsh + dofs, count);
  		return;
 @@ -722,6 +727,7 @@ bus_space_copy_region_4(bus_space_tag_t 
  {
  	uint32_t *dst, *src;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO)) {
  		bus_space_copy_region_io_4(sbsh + sofs, dbsh + dofs, count);
  		return;
 @@ -746,6 +752,7 @@ bus_space_copy_region_8(bus_space_tag_t 
  {
  	uint64_t *dst, *src;
  
 +	KASSERT(count != 0, ("%s: count == 0", __func__));
  	if (__predict_false(bst == IA64_BUS_SPACE_IO)) {
  		bus_space_copy_region_io_8(sbsh + sofs, dbsh + dofs, count);
  		return;
 
 Modified: head/sys/mips/include/bus.h
 ==============================================================================
 --- head/sys/mips/include/bus.h	Thu Dec  2 22:00:57 2010	(r216133)
 +++ head/sys/mips/include/bus.h	Thu Dec  2 22:19:30 2010	(r216134)
 @@ -73,6 +73,9 @@
  #ifndef _MACHINE_BUS_H_
  #define _MACHINE_BUS_H_
  
 +#include <sys/param.h>
 +#include <sys/systm.h>
 +
  #include <machine/_bus.h>
  
  struct bus_space {
 @@ -314,21 +317,29 @@ struct bus_space {
   * Bus read multiple operations.
   */
  #define	bus_space_read_multi_1(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_multi_1: count == 0"));	\
  	__bs_nonsingle(rm,1,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_2(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_multi_2: count == 0"));	\
  	__bs_nonsingle(rm,2,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_4(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_multi_4: count == 0"));	\
  	__bs_nonsingle(rm,4,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_8(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_multi_8: count == 0"));	\
  	__bs_nonsingle(rm,8,(t),(h),(o),(a),(c))
  
  #define	bus_space_read_multi_stream_1(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_multi_stream_1: count == 0"));	\
  	__bs_nonsingle_s(rm,1,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_stream_2(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_multi_stream_2: count == 0"));	\
  	__bs_nonsingle_s(rm,2,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_stream_4(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_multi_stream_4: count == 0"));	\
  	__bs_nonsingle_s(rm,4,(t),(h),(o),(a),(c))
  #define	bus_space_read_multi_stream_8(t, h, o, a, c)			\
 +	KASSERT(c != 0, ("bus_space_read_multi_stream_8: count == 0"));	\
  	__bs_nonsingle_s(rm,8,(t),(h),(o),(a),(c))
  
  
 @@ -336,21 +347,33 @@ struct bus_space {
   * Bus read region operations.
   */
  #define	bus_space_read_region_1(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_region_1: count == 0"));	\
  	__bs_nonsingle(rr,1,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_2(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_region_2: count == 0"));	\
  	__bs_nonsingle(rr,2,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_4(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_region_4: count == 0"));	\
  	__bs_nonsingle(rr,4,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_8(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_read_region_8: count == 0"));	\
  	__bs_nonsingle(rr,8,(t),(h),(o),(a),(c))
  
  #define	bus_space_read_region_stream_1(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_read_region_stream_1: count == 0"));		\
  	__bs_nonsingle_s(rr,1,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_stream_2(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_read_region_stream_2: count == 0"));		\
  	__bs_nonsingle_s(rr,2,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_stream_4(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_read_region_stream_4: count == 0"));		\
  	__bs_nonsingle_s(rr,4,(t),(h),(o),(a),(c))
  #define	bus_space_read_region_stream_8(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_read_region_stream_8: count == 0"));		\
  	__bs_nonsingle_s(rr,8,(t),(h),(o),(a),(c))
  
  
 @@ -372,21 +395,33 @@ struct bus_space {
   * Bus write multiple operations.
   */
  #define	bus_space_write_multi_1(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_multi_1: count == 0"));	\
  	__bs_nonsingle(wm,1,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_2(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_multi_2: count == 0"));	\
  	__bs_nonsingle(wm,2,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_4(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_multi_4: count == 0"));	\
  	__bs_nonsingle(wm,4,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_8(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_multi_8: count == 0"));	\
  	__bs_nonsingle(wm,8,(t),(h),(o),(a),(c))
  
  #define	bus_space_write_multi_stream_1(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_multi_stream_1: count == 0"));		\
  	__bs_nonsingle_s(wm,1,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_stream_2(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_multi_stream_2: count == 0"));		\
  	__bs_nonsingle_s(wm,2,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_stream_4(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_multi_stream_4: count == 0"));		\
  	__bs_nonsingle_s(wm,4,(t),(h),(o),(a),(c))
  #define	bus_space_write_multi_stream_8(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_multi_stream_8: count == 0"));		\
  	__bs_nonsingle_s(wm,8,(t),(h),(o),(a),(c))
  
  
 @@ -394,34 +429,50 @@ struct bus_space {
   * Bus write region operations.
   */
  #define	bus_space_write_region_1(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_region_1: count == 0"));	\
  	__bs_nonsingle(wr,1,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_2(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_region_2: count == 0"));	\
  	__bs_nonsingle(wr,2,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_4(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_region_4: count == 0"));	\
  	__bs_nonsingle(wr,4,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_8(t, h, o, a, c)				\
 +	KASSERT(c != 0, ("bus_space_write_region_8: count == 0"));	\
  	__bs_nonsingle(wr,8,(t),(h),(o),(a),(c))
  
  #define	bus_space_write_region_stream_1(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_region_stream_1: count == 0"));		\
  	__bs_nonsingle_s(wr,1,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_stream_2(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_region_stream_2: count == 0"));		\
  	__bs_nonsingle_s(wr,2,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_stream_4(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_region_stream_4: count == 0"));		\
  	__bs_nonsingle_s(wr,4,(t),(h),(o),(a),(c))
  #define	bus_space_write_region_stream_8(t, h, o, a, c)			\
 +	KASSERT(c != 0,							\
 +	    ("bus_space_write_region_stream_8: count == 0"));		\
  	__bs_nonsingle_s(wr,8,(t),(h),(o),(a),(c))
  
  
  /*
   * Set multiple operations.
   */
 -#define	bus_space_set_multi_1(t, h, o, v, c)				\
 +#define	bus_space_set_multi_1(t, h, o, v, c)			\
 +	KASSERT(c != 0, ("bus_space_set_multi_1: count == 0"));	\
  	__bs_set(sm,1,(t),(h),(o),(v),(c))
 -#define	bus_space_set_multi_2(t, h, o, v, c)				\
 +#define	bus_space_set_multi_2(t, h, o, v, c)			\
 +	KASSERT(c != 0, ("bus_space_set_multi_2: count == 0"));	\
  	__bs_set(sm,2,(t),(h),(o),(v),(c))
 -#define	bus_space_set_multi_4(t, h, o, v, c)				\
 +#define	bus_space_set_multi_4(t, h, o, v, c)			\
 +	KASSERT(c != 0, ("bus_space_set_multi_4: count == 0"));	\
  	__bs_set(sm,4,(t),(h),(o),(v),(c))
 -#define	bus_space_set_multi_8(t, h, o, v, c)				\
 +#define	bus_space_set_multi_8(t, h, o, v, c)			\
 +	KASSERT(c != 0, ("bus_space_set_multi_8: count == 0"));	\
  	__bs_set(sm,8,(t),(h),(o),(v),(c))
  
  
 @@ -429,25 +480,33 @@ struct bus_space {
   * Set region operations.
   */
  #define	bus_space_set_region_1(t, h, o, v, c)				\
 +	KASSERT(c != 0, ("bus_space_set_region_1: count == 0"));	\
  	__bs_set(sr,1,(t),(h),(o),(v),(c))
  #define	bus_space_set_region_2(t, h, o, v, c)				\
 +	KASSERT(c != 0, ("bus_space_set_region_2: count == 0"));	\
  	__bs_set(sr,2,(t),(h),(o),(v),(c))
  #define	bus_space_set_region_4(t, h, o, v, c)				\
 +	KASSERT(c != 0, ("bus_space_set_region_4: count == 0"));	\
  	__bs_set(sr,4,(t),(h),(o),(v),(c))
  #define	bus_space_set_region_8(t, h, o, v, c)				\
 +	KASSERT(c != 0, ("bus_space_set_region_8: count == 0"));	\
  	__bs_set(sr,8,(t),(h),(o),(v),(c))
  
  
  /*
   * Copy operations.
   */
 -#define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)				\
 +#define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
 +	KASSERT(c != 0, ("bus_space_copy_region_1: count == 0"));	\
  	__bs_copy(1, t, h1, o1, h2, o2, c)
 -#define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)				\
 +#define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
 +	KASSERT(c != 0, ("bus_space_copy_region_2: count == 0"));	\
  	__bs_copy(2, t, h1, o1, h2, o2, c)
 -#define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)				\
 +#define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
 +	KASSERT(c != 0, ("bus_space_copy_region_4: count == 0"));	\
  	__bs_copy(4, t, h1, o1, h2, o2, c)
 
 *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: brucec 
State-Changed-When: Thu Dec 2 22:27:55 UTC 2010 
State-Changed-Why:  
Fixed in r216134. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80980 
State-Changed-From-To: patched->closed 
State-Changed-By: brucec 
State-Changed-When: Fri Dec 3 07:12:29 UTC 2010 
State-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=80980 
State-Changed-From-To: closed->open 
State-Changed-By: brucec 
State-Changed-When: Fri Dec 3 07:12:48 UTC 2010 
State-Changed-Why:  
The checkin was reverted because it broke on platforms where bus_space_*  
are macros. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80980 
State-Changed-From-To: open->patched 
State-Changed-By: brucec 
State-Changed-When: Fri Dec 3 22:31:34 UTC 2010 
State-Changed-Why:  
It was agreed that the solution was to document the restriction in the man  
page. The fix was committed in r216156. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80980 
State-Changed-From-To: patched->closed 
State-Changed-By: brucec 
State-Changed-When: Sun Feb 13 18:03:54 UTC 2011 
State-Changed-Why:  
Documentation patch committed to stable/7 and stable/8. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80980 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/80980: commit references a PR
Date: Sun, 13 Feb 2011 18:00:30 +0000 (UTC)

 Author: brucec
 Date: Sun Feb 13 18:00:05 2011
 New Revision: 218647
 URL: http://svn.freebsd.org/changeset/base/218647
 
 Log:
   MFC r216156:
   
   Document the fact that passing in a count of zero to the bus_space functions
   will result in undefined behaviour.
   Taken from NetBSD's bus_space(9).
   
   PR:	kern/80980
 
 Modified:
   stable/7/share/man/man9/bus_space.9
 Directory Properties:
   stable/7/share/man/man9/   (props changed)
 
 Modified: stable/7/share/man/man9/bus_space.9
 ==============================================================================
 --- stable/7/share/man/man9/bus_space.9	Sun Feb 13 17:56:22 2011	(r218646)
 +++ stable/7/share/man/man9/bus_space.9	Sun Feb 13 18:00:05 2011	(r218647)
 @@ -719,6 +719,9 @@ or which return data read from bus space
  do not obviously return an error code) do not fail.
  They could only fail
  if given invalid arguments, and in that case their behaviour is undefined.
 +Functions which take a count of bytes have undefined results if the specified
 +.Fa count
 +is zero.
  .Sh TYPES
  Several types are defined in
  .In machine/bus.h
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/80980: commit references a PR
Date: Sun, 13 Feb 2011 18:03:34 +0000 (UTC)

 Author: brucec
 Date: Sun Feb 13 18:03:30 2011
 New Revision: 218648
 URL: http://svn.freebsd.org/changeset/base/218648
 
 Log:
   MFC r216156:
   
   Document the fact that passing in a count of zero to the bus_space functions
   will result in undefined behaviour.
   Taken from NetBSD's bus_space(9).
   
   PR:	kern/80980
 
 Modified:
   stable/8/share/man/man9/bus_space.9
 Directory Properties:
   stable/8/share/man/man9/   (props changed)
 
 Modified: stable/8/share/man/man9/bus_space.9
 ==============================================================================
 --- stable/8/share/man/man9/bus_space.9	Sun Feb 13 18:00:05 2011	(r218647)
 +++ stable/8/share/man/man9/bus_space.9	Sun Feb 13 18:03:30 2011	(r218648)
 @@ -719,6 +719,9 @@ or which return data read from bus space
  do not obviously return an error code) do not fail.
  They could only fail
  if given invalid arguments, and in that case their behaviour is undefined.
 +Functions which take a count of bytes have undefined results if the specified
 +.Fa count
 +is zero.
  .Sh TYPES
  Several types are defined in
  .In machine/bus.h
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
