summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMatthew Dempsky <matthew@cvs.openbsd.org>2011-07-06 04:49:37 +0000
committerMatthew Dempsky <matthew@cvs.openbsd.org>2011-07-06 04:49:37 +0000
commit51c6c9b181971ccd9a6d6f7f9dd1fa5dc8df1c23 (patch)
tree9e6859366146d5377f6e62a5adfeca45f358d3ad /sys/arch
parent9f81aca0122f901a2f924a0d3d759a2d37d682de (diff)
Eliminate redundant buf validation checks in xxstrategy() methods now
that they're implemented consistently in bounds_check_with_label(). Also, per krw's request, change bounds_check_with_label() to return 0 if the checks succeed, and change the drivers to test == -1 instead of <= 0. (Man page update to follow; intentionally omitting arch/vax/mba/hp.c from this commit because it doesn't even build currently and miod@ promises to kill it soon.) ok krw@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/hp300/dev/hd.c34
-rw-r--r--sys/arch/octeon/dev/octcf.c33
-rw-r--r--sys/arch/sparc/dev/presto.c16
-rw-r--r--sys/arch/sparc/dev/xd.c24
-rw-r--r--sys/arch/sparc/dev/xy.c24
-rw-r--r--sys/arch/vax/mscp/mscp_disk.c20
-rw-r--r--sys/arch/vax/vsa/hdc9224.c11
7 files changed, 54 insertions, 108 deletions
diff --git a/sys/arch/hp300/dev/hd.c b/sys/arch/hp300/dev/hd.c
index 3f9d01610a0..e07497b4ceb 100644
--- a/sys/arch/hp300/dev/hd.c
+++ b/sys/arch/hp300/dev/hd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hd.c,v 1.68 2011/06/19 21:20:04 miod Exp $ */
+/* $OpenBSD: hd.c,v 1.69 2011/07/06 04:49:35 matthew Exp $ */
/* $NetBSD: rd.c,v 1.33 1997/07/10 18:14:08 kleink Exp $ */
/*
@@ -650,7 +650,6 @@ hdstrategy(bp)
int unit = DISKUNIT(bp->b_dev);
struct hd_softc *rs;
struct buf *dp;
- struct disklabel *lp;
int s;
rs = hdlookup(unit);
@@ -666,27 +665,8 @@ hdstrategy(bp)
(bp->b_flags & B_READ) ? 'R' : 'W');
#endif
- lp = rs->sc_dkdev.dk_label;
-
- /*
- * If it's a null transfer, return immediately
- */
- if (bp->b_bcount == 0)
- goto done;
-
- /*
- * The transfer must be a whole number of blocks.
- */
- if ((bp->b_bcount % lp->d_secsize) != 0) {
- bp->b_error = EINVAL;
- goto bad;
- }
-
- /*
- * Do bounds checking, adjust transfer. if error, process;
- * If end of partition, just return.
- */
- if (bounds_check_with_label(bp, lp) <= 0)
+ /* Validate the request. */
+ if (bounds_check_with_label(bp, rs->sc_dkdev.dk_label) == -1)
goto done;
s = splbio();
@@ -700,13 +680,11 @@ hdstrategy(bp)
device_unref(&rs->sc_dev);
return;
-bad:
+
+ bad:
bp->b_flags |= B_ERROR;
-done:
- /*
- * Correctly set the buf to indicate a completed xfer
- */
bp->b_resid = bp->b_bcount;
+ done:
s = splbio();
biodone(bp);
splx(s);
diff --git a/sys/arch/octeon/dev/octcf.c b/sys/arch/octeon/dev/octcf.c
index a6879e15e0f..ccba97d1063 100644
--- a/sys/arch/octeon/dev/octcf.c
+++ b/sys/arch/octeon/dev/octcf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: octcf.c,v 1.6 2011/06/19 04:55:34 deraadt Exp $ */
+/* $OpenBSD: octcf.c,v 1.7 2011/07/06 04:49:35 matthew Exp $ */
/* $NetBSD: wd.c,v 1.193 1999/02/28 17:15:27 explorer Exp $ */
/*
@@ -302,27 +302,22 @@ octcfstrategy(struct buf *bp)
}
OCTCFDEBUG_PRINT(("octcfstrategy (%s)\n", wd->sc_dev.dv_xname),
DEBUG_XFERS);
- /* Valid request? */
- if (bp->b_blkno < 0 ||
- (bp->b_bcount % wd->sc_dk.dk_label->d_secsize) != 0 ||
- (bp->b_bcount / wd->sc_dk.dk_label->d_secsize) >= (1 << NBBY)) {
- bp->b_error = EINVAL;
- goto bad;
- }
/* If device invalidated (e.g. media change, door open), error. */
if ((wd->sc_flags & OCTCFF_LOADED) == 0) {
bp->b_error = EIO;
goto bad;
}
- /* If it's a null transfer, return immediately. */
- if (bp->b_bcount == 0)
- goto done;
- /*
- * Do bounds checking, adjust transfer. if error, process.
- * If end of partition, just return.
- */
- if (bounds_check_with_label(bp, wd->sc_dk.dk_label) <= 0)
+
+ /* Validate the request. */
+ if (bounds_check_with_label(bp, wd->sc_dk.dk_label) == -1)
goto done;
+
+ /* Check that the number of sectors can fit in a byte. */
+ if ((bp->b_bcount / wd->sc_dk.dk_label->d_secsize) >= (1 << NBBY)) {
+ bp->b_error = EINVAL;
+ goto bad;
+ }
+
/* Queue transfer on drive, activate drive and controller if idle. */
s = splbio();
disksort(&wd->sc_q, bp);
@@ -330,11 +325,11 @@ octcfstrategy(struct buf *bp)
splx(s);
device_unref(&wd->sc_dev);
return;
-bad:
+
+ bad:
bp->b_flags |= B_ERROR;
-done:
- /* Toss transfer; we're done early. */
bp->b_resid = bp->b_bcount;
+ done:
s = splbio();
biodone(bp);
splx(s);
diff --git a/sys/arch/sparc/dev/presto.c b/sys/arch/sparc/dev/presto.c
index f9d05429d4c..b242ce3fd97 100644
--- a/sys/arch/sparc/dev/presto.c
+++ b/sys/arch/sparc/dev/presto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: presto.c,v 1.21 2011/06/03 21:14:11 matthew Exp $ */
+/* $OpenBSD: presto.c,v 1.22 2011/07/06 04:49:35 matthew Exp $ */
/*
* Copyright (c) 2003, Miodrag Vallat.
* All rights reserved.
@@ -280,15 +280,14 @@ prestostrategy(struct buf *bp)
sc = (struct presto_softc *)device_lookup(&presto_cd, unit);
/* Sort rogue requests out */
- if (sc == NULL || bp->b_blkno < 0 ||
- (bp->b_bcount % sc->sc_dk.dk_label->d_secsize) != 0) {
+ if (sc == NULL) {
bp->b_error = EINVAL;
goto bad;
}
- /* Do not write on "no trespassing" areas... */
- if (bounds_check_with_label(bp, sc->sc_dk.dk_label) <= 0)
- goto bad;
+ /* Validate the request. */
+ if (bounds_check_with_label(bp, sc->sc_dk.dk_label) == -1)
+ goto done;
/* Bound the request size, then move data between buf and nvram */
bp->b_resid = bp->b_bcount;
@@ -303,11 +302,10 @@ prestostrategy(struct buf *bp)
bp->b_resid -= count;
goto done;
-bad:
+ bad:
bp->b_flags |= B_ERROR;
bp->b_resid = bp->b_bcount;
-
-done:
+ done:
s = splbio();
biodone(bp);
splx(s);
diff --git a/sys/arch/sparc/dev/xd.c b/sys/arch/sparc/dev/xd.c
index af721ed86e2..166dee9db63 100644
--- a/sys/arch/sparc/dev/xd.c
+++ b/sys/arch/sparc/dev/xd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xd.c,v 1.55 2011/06/05 18:40:33 matthew Exp $ */
+/* $OpenBSD: xd.c,v 1.56 2011/07/06 04:49:35 matthew Exp $ */
/* $NetBSD: xd.c,v 1.37 1997/07/29 09:58:16 fair Exp $ */
/*
@@ -1011,9 +1011,7 @@ xdstrategy(bp)
/* check for live device */
- if (unit >= xd_cd.cd_ndevs || (xd = xd_cd.cd_devs[unit]) == 0 ||
- bp->b_blkno < 0 ||
- (bp->b_bcount % xd->sc_dk.dk_label->d_secsize) != 0) {
+ if (unit >= xd_cd.cd_ndevs || (xd = xd_cd.cd_devs[unit]) == 0) {
bp->b_error = EINVAL;
goto bad;
}
@@ -1036,17 +1034,9 @@ xdstrategy(bp)
bp->b_error = EIO;
goto bad;
}
- /* short circuit zero length request */
- if (bp->b_bcount == 0)
- goto done;
-
- /* check bounds with label (disksubr.c). Determine the size of the
- * transfer, and make sure it is within the boundaries of the
- * partition. Adjust transfer if needed, and signal errors or early
- * completion. */
-
- if (bounds_check_with_label(bp, xd->sc_dk.dk_label) <= 0)
+ /* Validate the request. */
+ if (bounds_check_with_label(bp, xd->sc_dk.dk_label) == -1)
goto done;
/*
@@ -1090,11 +1080,11 @@ xdstrategy(bp)
splx(s);
return;
-bad: /* tells upper layers we have an error */
+ bad: /* tells upper layers we have an error */
bp->b_flags |= B_ERROR;
-done: /* tells upper layers we are done with this
- * buf */
bp->b_resid = bp->b_bcount;
+ done: /* tells upper layers we are done with this
+ * buf */
s = splbio();
biodone(bp);
splx(s);
diff --git a/sys/arch/sparc/dev/xy.c b/sys/arch/sparc/dev/xy.c
index 071f98fc864..24dc1510bec 100644
--- a/sys/arch/sparc/dev/xy.c
+++ b/sys/arch/sparc/dev/xy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xy.c,v 1.52 2011/06/05 18:40:33 matthew Exp $ */
+/* $OpenBSD: xy.c,v 1.53 2011/07/06 04:49:35 matthew Exp $ */
/* $NetBSD: xy.c,v 1.26 1997/07/19 21:43:56 pk Exp $ */
/*
@@ -974,9 +974,7 @@ xystrategy(bp)
/* check for live device */
- if (unit >= xy_cd.cd_ndevs || (xy = xy_cd.cd_devs[unit]) == 0 ||
- bp->b_blkno < 0 ||
- (bp->b_bcount % xy->sc_dk.dk_label->d_secsize) != 0) {
+ if (unit >= xy_cd.cd_ndevs || (xy = xy_cd.cd_devs[unit]) == 0) {
bp->b_error = EINVAL;
goto bad;
}
@@ -999,17 +997,9 @@ xystrategy(bp)
bp->b_error = EIO;
goto bad;
}
- /* short circuit zero length request */
- if (bp->b_bcount == 0)
- goto done;
-
- /* check bounds with label (disksubr.c). Determine the size of the
- * transfer, and make sure it is within the boundaries of the
- * partition. Adjust transfer if needed, and signal errors or early
- * completion. */
-
- if (bounds_check_with_label(bp, xy->sc_dk.dk_label) <= 0)
+ /* Validate the request. */
+ if (bounds_check_with_label(bp, xy->sc_dk.dk_label) == -1)
goto done;
/*
@@ -1029,11 +1019,11 @@ xystrategy(bp)
splx(s);
return;
-bad: /* tells upper layers we have an error */
+ bad: /* tells upper layers we have an error */
bp->b_flags |= B_ERROR;
-done: /* tells upper layers we are done with this
- * buf */
bp->b_resid = bp->b_bcount;
+ done: /* tells upper layers we are done with this
+ * buf */
s = splbio();
biodone(bp);
splx(s);
diff --git a/sys/arch/vax/mscp/mscp_disk.c b/sys/arch/vax/mscp/mscp_disk.c
index b4cb3da23f3..c9bc08d52fa 100644
--- a/sys/arch/vax/mscp/mscp_disk.c
+++ b/sys/arch/vax/mscp/mscp_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mscp_disk.c,v 1.36 2011/07/05 21:39:08 krw Exp $ */
+/* $OpenBSD: mscp_disk.c,v 1.37 2011/07/06 04:49:36 matthew Exp $ */
/* $NetBSD: mscp_disk.c,v 1.30 2001/11/13 07:38:28 lukem Exp $ */
/*
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
@@ -286,8 +286,7 @@ rastrategy(bp)
unit = DISKUNIT(bp->b_dev);
if (unit >= ra_cd.cd_ndevs || (ra = ra_cd.cd_devs[unit]) == NULL) {
bp->b_error = ENXIO;
- bp->b_flags |= B_ERROR;
- goto done;
+ goto bad;
}
/*
* If drive is open `raw' or reading label, let it at it.
@@ -303,16 +302,12 @@ rastrategy(bp)
/* If disk is not online, try to put it online */
if (ra->ra_state == DK_CLOSED)
if (ra_putonline(ra) == MSCP_FAILED) {
- bp->b_flags |= B_ERROR;
bp->b_error = EIO;
- goto done;
+ goto bad;
}
- /*
- * Determine the size of the transfer, and make sure it is
- * within the boundaries of the partition.
- */
- if (bounds_check_with_label(bp, ra->ra_disk.dk_label) <= 0)
+ /* Validate the request. */
+ if (bounds_check_with_label(bp, ra->ra_disk.dk_label) == -1)
goto done;
/* Make some statistics... /bqt */
@@ -322,7 +317,10 @@ rastrategy(bp)
mscp_strategy(bp, ra->ra_dev.dv_parent);
return;
-done:
+ bad:
+ bp->b_flags |= B_ERROR;
+ bp->b_resid = bp->b_bcount;
+ done:
s = splbio();
biodone(bp);
splx(s);
diff --git a/sys/arch/vax/vsa/hdc9224.c b/sys/arch/vax/vsa/hdc9224.c
index bf95d76b523..6f8921f4666 100644
--- a/sys/arch/vax/vsa/hdc9224.c
+++ b/sys/arch/vax/vsa/hdc9224.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hdc9224.c,v 1.36 2011/06/05 18:40:33 matthew Exp $ */
+/* $OpenBSD: hdc9224.c,v 1.37 2011/07/06 04:49:36 matthew Exp $ */
/* $NetBSD: hdc9224.c,v 1.16 2001/07/26 15:05:09 wiz Exp $ */
/*
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
@@ -440,22 +440,19 @@ hdstrategy(struct buf *bp)
{
struct hdsoftc *hd;
struct hdcsoftc *sc;
- struct disklabel *lp;
int unit, s;
unit = DISKUNIT(bp->b_dev);
if (unit > hd_cd.cd_ndevs || (hd = hd_cd.cd_devs[unit]) == NULL) {
bp->b_error = ENXIO;
bp->b_flags |= B_ERROR;
+ bp->b_resid = bp->b_bcount;
goto done;
}
sc = (void *)hd->sc_dev.dv_parent;
- lp = hd->sc_disk.dk_label;
- if ((bounds_check_with_label(bp, hd->sc_disk.dk_label)) <= 0)
- goto done;
-
- if (bp->b_bcount == 0)
+ /* Validate the request. */
+ if (bounds_check_with_label(bp, hd->sc_disk.dk_label) == -1)
goto done;
s = splbio();