summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2009-04-02 18:44:50 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2009-04-02 18:44:50 +0000
commiteb363815d95c12d5528801b61a547ec17268e147 (patch)
treebf46300d00f5d0c6fb0b5cb80d6f3fc164d87c6e /sys/dev
parent18d68267be9932247dfd19a353d4bc8116423f9d (diff)
Convert lockmgr to rwlock. Fixing a (harmless) lock leak on attach
failure while i'm at it. Been in snaps for a while. ok deraadt@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/i2o/iop.c22
-rw-r--r--sys/dev/i2o/iopsp.c14
-rw-r--r--sys/dev/i2o/iopvar.h6
3 files changed, 19 insertions, 23 deletions
diff --git a/sys/dev/i2o/iop.c b/sys/dev/i2o/iop.c
index df0a35aeb37..6879456f102 100644
--- a/sys/dev/i2o/iop.c
+++ b/sys/dev/i2o/iop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: iop.c,v 1.35 2008/06/26 05:42:14 ray Exp $ */
+/* $OpenBSD: iop.c,v 1.36 2009/04/02 18:44:49 oga Exp $ */
/* $NetBSD: iop.c,v 1.12 2001/03/21 14:27:05 ad Exp $ */
/*-
@@ -391,7 +391,7 @@ iop_init(struct iop_softc *sc, const char *intrstr)
sc->sc_maxob, letoh32(sc->sc_status.maxoutboundmframes));
#endif
- lockinit(&sc->sc_conflock, PRIBIO, "iopconf", 0, 0);
+ rw_init(&sc->sc_conflock, "iopconf");
startuphook_establish((void (*)(void *))iop_config_interrupts, sc);
return;
@@ -530,12 +530,13 @@ iop_config_interrupts(struct device *self)
config_found_sm(self, &ia, iop_vendor_print, iop_submatch);
#endif
- lockmgr(&sc->sc_conflock, LK_EXCLUSIVE, NULL);
- if ((rv = iop_reconfigure(sc, 0)) == -1) {
+ rw_enter_write(&sc->sc_conflock);
+ rv = iop_reconfigure(sc, 0);
+ rw_exit_write(&sc->sc_conflock);
+ if (rv == -1) {
printf("%s: configure failed (%d)\n", sc->sc_dv.dv_xname, rv);
return;
}
- lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
kthread_create_deferred(iop_create_reconf_thread, sc);
}
@@ -584,11 +585,11 @@ iop_reconf_thread(void *cookie)
DPRINTF(("%s: async reconfig: notified (0x%08x, %d)\n",
sc->sc_dv.dv_xname, letoh32(lct.changeindicator), rv));
- if (rv == 0 &&
- lockmgr(&sc->sc_conflock, LK_EXCLUSIVE, NULL) == 0) {
+ if (rv == 0) {
+ rw_enter_write(&sc->sc_conflock);
iop_reconfigure(sc, letoh32(lct.changeindicator));
chgind = sc->sc_chgind + 1;
- lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
+ rw_exit_write(&sc->sc_conflock);
}
tsleep(iop_reconf_thread, PWAIT, "iopzzz", hz * 5);
@@ -2359,8 +2360,7 @@ iopioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
return (ENOTTY);
}
- if ((rv = lockmgr(&sc->sc_conflock, LK_SHARED, NULL)) != 0)
- return (rv);
+ rw_enter_read(&sc->sc_conflock);
switch (cmd) {
case IOPIOCGLCT:
@@ -2388,7 +2388,7 @@ iopioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
break;
}
- lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
+ rw_exit_read(&sc->sc_conflock);
return (rv);
}
diff --git a/sys/dev/i2o/iopsp.c b/sys/dev/i2o/iopsp.c
index 3db66922fb6..3cfb91b3a3b 100644
--- a/sys/dev/i2o/iopsp.c
+++ b/sys/dev/i2o/iopsp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: iopsp.c,v 1.14 2009/02/16 21:19:06 miod Exp $ */
+/* $OpenBSD: iopsp.c,v 1.15 2009/04/02 18:44:49 oga Exp $ */
/* $NetBSD$ */
/*-
@@ -45,7 +45,7 @@
#include <sys/endian.h>
#include <sys/malloc.h>
#include <sys/scsiio.h>
-#include <sys/lock.h>
+#include <sys/rwlock.h>
#include <machine/bus.h>
@@ -371,13 +371,7 @@ iopsp_rescan(struct iopsp_softc *sc)
iop = (struct iop_softc *)sc->sc_dv.dv_parent;
- rv = lockmgr(&iop->sc_conflock, LK_EXCLUSIVE, NULL);
- if (rv != 0) {
-#ifdef I2ODEBUG
- printf("iopsp_rescan: unable to acquire lock\n");
-#endif
- return (rv);
- }
+ rw_enter_write(&iop->sc_conflock);
im = iop_msg_alloc(iop, &sc->sc_ii, IM_WAIT);
@@ -395,7 +389,7 @@ iopsp_rescan(struct iopsp_softc *sc)
if ((rv = iop_lct_get(iop)) == 0)
rv = iopsp_reconfig(&sc->sc_dv);
- lockmgr(&iop->sc_conflock, LK_RELEASE, NULL);
+ rw_exit_write(&iop->sc_conflock);
return (rv);
}
diff --git a/sys/dev/i2o/iopvar.h b/sys/dev/i2o/iopvar.h
index 0f1675ff1fa..60a19493101 100644
--- a/sys/dev/i2o/iopvar.h
+++ b/sys/dev/i2o/iopvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: iopvar.h,v 1.9 2008/06/26 05:42:15 ray Exp $ */
+/* $OpenBSD: iopvar.h,v 1.10 2009/04/02 18:44:49 oga Exp $ */
/* $NetBSD: iopvar.h,v 1.5 2001/03/20 13:01:49 ad Exp $ */
/*-
@@ -33,6 +33,8 @@
#ifndef _I2O_IOPVAR_H_
#define _I2O_IOPVAR_H_
+#include <sys/rwlock.h>
+
/*
* Transfer descriptor.
*/
@@ -106,7 +108,7 @@ struct iop_softc {
bus_space_tag_t sc_iot; /* bus space tag */
bus_dma_tag_t sc_dmat; /* bus DMA tag */
void *sc_ih; /* interrupt handler cookie */
- struct lock sc_conflock; /* autoconfiguration lock */
+ struct rwlock sc_conflock; /* autoconfiguration lock */
bus_addr_t sc_memaddr; /* register window address */
bus_size_t sc_memsize; /* register window size */