Subject: inconsistent return value from bounds_check_with_label()
To: None <tech-kern@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
List: tech-kern
Date: 04/10/2003 15:28:54
--YiEDa0DAkWCtVeE4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,
Miod Vallat pointed me out that a commit has been done to OpenBSD to
work around inconsistent return values from bounds_check_with_label()
(some will return 0 for error, some will -1).
As we have a man page stating that bounds_check_with_label() returns -1
in case of error, I fixed the implementations to be compliant with this
(return -1 for error, 0 for EOF, 1 otherwise). I also found one case
where the return value was checked < 0 instead of <= 0, I also fixed it.
Note that this doesn't cause problems in the current state, as all
MI place check the return value <= 0, and the only place which checks < 0
is in a place where the MD bounds_check_with_label() is compliant (it's
just suboptimal in case of EOF).

Do my changes looks right ?

--
Manuel Bouyer, LIP6, Universite Paris VI.           Manuel.Bouyer@lip6.fr
     NetBSD: 24 ans d'experience feront toujours la difference
--

--YiEDa0DAkWCtVeE4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="diff.bcwl"

Index: arch/arc/arc/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arc/arc/disksubr.c,v
retrieving revision 1.13
diff -u -r1.13 disksubr.c
--- arch/arc/arc/disksubr.c	2003/01/19 10:06:12	1.13
+++ arch/arc/arc/disksubr.c	2003/04/10 11:01:27
@@ -530,7 +530,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return 0;
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -558,6 +558,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/arm/arm/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/arm/disksubr.c,v
retrieving revision 1.3
diff -u -r1.3 disksubr.c
--- arch/arm/arm/disksubr.c	2002/08/27 17:30:02	1.3
+++ arch/arm/arm/disksubr.c	2003/04/10 11:01:27
@@ -404,7 +404,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -432,8 +432,7 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
 
 /* End of disksubr.c */
Index: arch/bebox/bebox/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/bebox/bebox/disksubr.c,v
retrieving revision 1.9
diff -u -r1.9 disksubr.c
--- arch/bebox/bebox/disksubr.c	2002/02/19 17:09:43	1.9
+++ arch/bebox/bebox/disksubr.c	2003/04/10 11:01:28
@@ -483,7 +483,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -511,6 +511,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/cobalt/cobalt/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/cobalt/cobalt/disksubr.c,v
retrieving revision 1.7
diff -u -r1.7 disksubr.c
--- arch/cobalt/cobalt/disksubr.c	2002/02/19 17:09:43	1.7
+++ arch/cobalt/cobalt/disksubr.c	2003/04/10 11:01:28
@@ -424,7 +424,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -452,6 +452,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/evbmips/evbmips/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbmips/evbmips/disksubr.c,v
retrieving revision 1.2
diff -u -r1.2 disksubr.c
--- arch/evbmips/evbmips/disksubr.c	2003/03/19 03:05:43	1.2
+++ arch/evbmips/evbmips/disksubr.c	2003/04/10 11:01:29
@@ -271,5 +271,5 @@
 	return (1);
 bad:
 	bp->b_flags |= B_ERROR;
-	return (0);
+	return (-1);
 }
Index: arch/evbppc/evbppc/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbppc/evbppc/disksubr.c,v
retrieving revision 1.1
diff -u -r1.1 disksubr.c
--- arch/evbppc/evbppc/disksubr.c	2003/03/04 07:51:01	1.1
+++ arch/evbppc/evbppc/disksubr.c	2003/04/10 11:01:29
@@ -278,7 +278,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -306,6 +306,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/hp700/hp700/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hp700/hp700/disksubr.c,v
retrieving revision 1.1
diff -u -r1.1 disksubr.c
--- arch/hp700/hp700/disksubr.c	2002/06/06 19:48:05	1.1
+++ arch/hp700/hp700/disksubr.c	2003/04/10 11:01:30
@@ -854,7 +854,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -880,6 +880,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/hpc/hpc/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpc/hpc/disksubr.c,v
retrieving revision 1.3
diff -u -r1.3 disksubr.c
--- arch/hpc/hpc/disksubr.c	2002/02/19 17:09:43	1.3
+++ arch/hpc/hpc/disksubr.c	2003/04/10 11:01:30
@@ -469,7 +469,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -497,6 +497,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/i386/i386/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/disksubr.c,v
retrieving revision 1.48
diff -u -r1.48 disksubr.c
--- arch/i386/i386/disksubr.c	2003/01/31 15:35:04	1.48
+++ arch/i386/i386/disksubr.c	2003/04/10 11:01:30
@@ -490,7 +490,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -518,6 +518,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/mac68k/mac68k/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mac68k/mac68k/disksubr.c,v
retrieving revision 1.42
diff -u -r1.42 disksubr.c
--- arch/mac68k/mac68k/disksubr.c	2002/06/29 19:44:52	1.42
+++ arch/mac68k/mac68k/disksubr.c	2003/04/10 11:01:32
@@ -639,7 +639,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -669,6 +669,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/macppc/macppc/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/macppc/macppc/disksubr.c,v
retrieving revision 1.25
diff -u -r1.25 disksubr.c
--- arch/macppc/macppc/disksubr.c	2002/09/28 01:17:10	1.25
+++ arch/macppc/macppc/disksubr.c	2003/04/10 11:01:32
@@ -727,7 +727,7 @@
 		if (sz == 0) {
 			/* If axactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return 0;
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -746,6 +746,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return 0;
+	return -1;
 }
Index: arch/mvmeppc/mvmeppc/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mvmeppc/mvmeppc/disksubr.c,v
retrieving revision 1.2
diff -u -r1.2 disksubr.c
--- arch/mvmeppc/mvmeppc/disksubr.c	2003/03/19 03:05:43	1.2
+++ arch/mvmeppc/mvmeppc/disksubr.c	2003/04/10 11:01:32
@@ -481,7 +481,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -509,6 +509,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/ofppc/ofppc/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/ofppc/ofppc/disksubr.c,v
retrieving revision 1.11
diff -u -r1.11 disksubr.c
--- arch/ofppc/ofppc/disksubr.c	2002/09/18 01:44:29	1.11
+++ arch/ofppc/ofppc/disksubr.c	2003/04/10 11:01:33
@@ -340,7 +340,7 @@
 		if (sz == 0) {
 			/* If axactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return 0;
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -359,6 +359,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return 0;
+	return -1;
 }
Index: arch/playstation2/playstation2/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/playstation2/playstation2/disksubr.c,v
retrieving revision 1.2
diff -u -r1.2 disksubr.c
--- arch/playstation2/playstation2/disksubr.c	2002/02/19 17:09:47	1.2
+++ arch/playstation2/playstation2/disksubr.c	2003/04/10 11:01:33
@@ -409,7 +409,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -437,6 +437,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/pmppc/pmppc/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/pmppc/pmppc/disksubr.c,v
retrieving revision 1.1
diff -u -r1.1 disksubr.c
--- arch/pmppc/pmppc/disksubr.c	2002/05/30 08:51:38	1.1
+++ arch/pmppc/pmppc/disksubr.c	2003/04/10 11:01:33
@@ -474,7 +474,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -502,6 +502,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/prep/prep/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/prep/prep/disksubr.c,v
retrieving revision 1.4
diff -u -r1.4 disksubr.c
--- arch/prep/prep/disksubr.c	2002/02/19 17:09:48	1.4
+++ arch/prep/prep/disksubr.c	2003/04/10 11:01:34
@@ -482,7 +482,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -510,6 +510,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/sandpoint/sandpoint/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sandpoint/sandpoint/disksubr.c,v
retrieving revision 1.2
diff -u -r1.2 disksubr.c
--- arch/sandpoint/sandpoint/disksubr.c	2002/02/19 17:09:48	1.2
+++ arch/sandpoint/sandpoint/disksubr.c	2003/04/10 11:01:34
@@ -481,7 +481,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -509,6 +509,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/sbmips/sbmips/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sbmips/sbmips/disksubr.c,v
retrieving revision 1.3
diff -u -r1.3 disksubr.c
--- arch/sbmips/sbmips/disksubr.c	2003/03/19 03:05:44	1.3
+++ arch/sbmips/sbmips/disksubr.c	2003/04/10 11:01:34
@@ -424,7 +424,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -452,6 +452,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
Index: arch/sh3/sh3/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sh3/sh3/disksubr.c,v
retrieving revision 1.9
diff -u -r1.9 disksubr.c
--- arch/sh3/sh3/disksubr.c	2002/07/22 15:11:09	1.9
+++ arch/sh3/sh3/disksubr.c	2003/04/10 11:01:34
@@ -702,7 +702,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -730,6 +730,5 @@
 
  bad:
 	bp->b_flags |= B_ERROR;
- done:
-	return (0);
+	return (-1);
 }
Index: arch/vax/mba/hp.c
===================================================================
RCS file: /cvsroot/src/sys/arch/vax/mba/hp.c,v
retrieving revision 1.31
diff -u -r1.31 hp.c
--- arch/vax/mba/hp.c	2002/11/01 11:31:55	1.31
+++ arch/vax/mba/hp.c	2003/04/10 11:01:35
@@ -193,7 +193,7 @@
 	lp = sc->sc_disk.dk_label;
 
 	err = bounds_check_with_label(bp, lp, sc->sc_wlabel);
-	if (err < 0)
+	if (err <= 0)
 		goto done;
 
 	bp->b_rawblkno =
Index: arch/x68k/x68k/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/x68k/disksubr.c,v
retrieving revision 1.17
diff -u -r1.17 disksubr.c
--- arch/x68k/x68k/disksubr.c	2002/02/19 17:09:50	1.17
+++ arch/x68k/x68k/disksubr.c	2003/04/10 11:01:36
@@ -491,7 +491,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -519,8 +519,7 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }
 
 static void
Index: arch/x86_64/x86_64/disksubr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86_64/x86_64/disksubr.c,v
retrieving revision 1.2
diff -u -r1.2 disksubr.c
--- arch/x86_64/x86_64/disksubr.c	2002/02/19 17:09:50	1.2
+++ arch/x86_64/x86_64/disksubr.c	2003/04/10 11:01:36
@@ -487,7 +487,7 @@
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
-			goto done;
+			return (0);
 		}
 		if (sz < 0) {
 			/* If past end of disk, return EINVAL. */
@@ -515,6 +515,5 @@
 
 bad:
 	bp->b_flags |= B_ERROR;
-done:
-	return (0);
+	return (-1);
 }

--YiEDa0DAkWCtVeE4--