summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-01-23 00:30:59 +0000
committercheloha <cheloha@openbsd.org>2020-01-23 00:30:59 +0000
commita89c4f9236dc680327a8003833e4d8db9534aa81 (patch)
tree841eb646e621284cb05dbd38f3708f3e7e20024f
parentallow npppd to use pppac(4) (once i wire it up) (diff)
downloadwireguard-openbsd-a89c4f9236dc680327a8003833e4d8db9534aa81.tar.xz
wireguard-openbsd-a89c4f9236dc680327a8003833e4d8db9534aa81.zip
ciss(4): ciss_cmd: split polling loop into two loops
There are really two loops here. One for SCSI_NOSLEEP and delay(9), the other for tsleep(9). The paths share a loop in the code but they shouldn't. They have different termination conditions and share little code. If we pull the conditional clause out of the for-loop and then give each path its own polling loop the logic should be easier to follow. ok krw@
-rw-r--r--sys/dev/ic/ciss.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/sys/dev/ic/ciss.c b/sys/dev/ic/ciss.c
index 5b6f69d7f04..8e038ef82d7 100644
--- a/sys/dev/ic/ciss.c
+++ b/sys/dev/ic/ciss.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ciss.c,v 1.76 2020/01/20 07:28:03 cheloha Exp $ */
+/* $OpenBSD: ciss.c,v 1.77 2020/01/23 00:30:59 cheloha Exp $ */
/*
* Copyright (c) 2005,2006 Michael Shalayeff
@@ -532,8 +532,9 @@ ciss_cmd(struct ciss_ccb *ccb, int flags, int wait)
tohz = tvtohz(&tv);
if (tohz == 0)
tohz = 1;
- for (i *= 100, etick = tick + tohz; i--; ) {
- if (!(wait & SCSI_NOSLEEP)) {
+
+ if (!(wait & SCSI_NOSLEEP)) {
+ for (etick = tick + tohz;;) {
ccb->ccb_state = CISS_CCB_POLL;
CISS_DPRINTF(CISS_D_CMD, ("tsleep(%d) ", tohz));
if (tsleep(ccb, PRIBIO + 1, "ciss_cmd",
@@ -548,7 +549,13 @@ ciss_cmd(struct ciss_ccb *ccb, int flags, int wait)
continue;
}
ccb1 = ccb;
- } else {
+
+ error = ciss_done(ccb1);
+ if (ccb1 == ccb)
+ return (error);
+ }
+ } else {
+ for (i *= 100; i--;) {
DELAY(10);
if (!(bus_space_read_4(sc->iot, sc->ioh,
@@ -588,11 +595,11 @@ ciss_cmd(struct ciss_ccb *ccb, int flags, int wait)
ccb1 = sc->ccbs + (id >> 2) * sc->ccblen;
ccb1->ccb_cmd.id = htole32(id);
ccb1->ccb_cmd.id_hi = htole32(0);
- }
- error = ciss_done(ccb1);
- if (ccb1 == ccb)
- return (error);
+ error = ciss_done(ccb1);
+ if (ccb1 == ccb)
+ return (error);
+ }
}
/* if never got a chance to be done above... */