diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-12-16 14:50:27 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-12-16 14:50:27 +0000 |
commit | 70cc4fddbf822c50152f99b7ddac261cb93d9992 (patch) | |
tree | 532f4e82b43bdb50bbde767e6f25e6371ac44677 | |
parent | fc196670d2fbb66e0b9a34d81431a46e28061648 (diff) |
Refactor umass_detach() in order to pass a size to free(9).
Based on a diff from Mathieu <naabed AT poolp DOT org>.
-rw-r--r-- | sys/dev/usb/umass.c | 13 | ||||
-rw-r--r-- | sys/dev/usb/umass_scsi.c | 30 | ||||
-rw-r--r-- | sys/dev/usb/umass_scsi.h | 3 | ||||
-rw-r--r-- | sys/dev/usb/umassvar.h | 8 |
4 files changed, 29 insertions, 25 deletions
diff --git a/sys/dev/usb/umass.c b/sys/dev/usb/umass.c index 8afd1efc0d4..86fb691f5d2 100644 --- a/sys/dev/usb/umass.c +++ b/sys/dev/usb/umass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: umass.c,v 1.70 2015/03/14 03:38:50 jsg Exp $ */ +/* $OpenBSD: umass.c,v 1.71 2015/12/16 14:50:26 mpi Exp $ */ /* $NetBSD: umass.c,v 1.116 2004/06/30 05:53:46 mycroft Exp $ */ /* @@ -129,7 +129,6 @@ #include <sys/kernel.h> #include <sys/conf.h> #include <sys/buf.h> -#include <sys/device.h> #include <sys/malloc.h> #include <sys/timeout.h> #undef KASSERT @@ -616,7 +615,6 @@ int umass_detach(struct device *self, int flags) { struct umass_softc *sc = (struct umass_softc *)self; - struct umassbus_softc *scbus; int rv = 0, i, s; DPRINTF(UDMASS_USB, ("%s: detached\n", sc->sc_dev.dv_xname)); @@ -647,14 +645,7 @@ umass_detach(struct device *self, int flags) } splx(s); - scbus = sc->bus; - if (scbus != NULL) { - if (scbus->sc_child != NULL) - rv = config_detach(scbus->sc_child, flags); - free(scbus, M_DEVBUF, 0); - sc->bus = NULL; - } - + rv = umass_scsi_detach(sc, flags); if (rv != 0) return (rv); diff --git a/sys/dev/usb/umass_scsi.c b/sys/dev/usb/umass_scsi.c index 7753cf72a2a..3c37d036afe 100644 --- a/sys/dev/usb/umass_scsi.c +++ b/sys/dev/usb/umass_scsi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: umass_scsi.c,v 1.42 2015/03/14 03:38:50 jsg Exp $ */ +/* $OpenBSD: umass_scsi.c,v 1.43 2015/12/16 14:50:26 mpi Exp $ */ /* $NetBSD: umass_scsipi.c,v 1.9 2003/02/16 23:14:08 augustss Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -52,7 +52,7 @@ #include <machine/bus.h> struct umass_scsi_softc { - struct umassbus_softc base; + struct device *sc_child; struct scsi_link sc_link; struct scsi_iopool sc_iopool; int sc_open; @@ -103,8 +103,7 @@ umass_scsi_attach(struct umass_softc *sc) sc->sc_dev.dv_xname, sc, scbus)); sc->sc_refcnt++; - scbus->base.sc_child = - config_found((struct device *)sc, &saa, scsiprint); + scbus->sc_child = config_found((struct device *)sc, &saa, scsiprint); if (--sc->sc_refcnt < 0) usb_detach_wakeup(&sc->sc_dev); @@ -131,8 +130,7 @@ umass_atapi_attach(struct umass_softc *sc) sc->sc_dev.dv_xname, sc, scbus)); sc->sc_refcnt++; - scbus->base.sc_child = config_found((struct device *)sc, - &saa, scsiprint); + scbus->sc_child = config_found((struct device *)sc, &saa, scsiprint); if (--sc->sc_refcnt < 0) usb_detach_wakeup(&sc->sc_dev); @@ -146,7 +144,7 @@ umass_scsi_setup(struct umass_softc *sc) scbus = malloc(sizeof(*scbus), M_DEVBUF, M_WAITOK | M_ZERO); - sc->bus = (struct umassbus_softc *)scbus; + sc->bus = scbus; scsi_iopool_init(&scbus->sc_iopool, scbus, umass_io_get, umass_io_put); @@ -162,6 +160,22 @@ umass_scsi_setup(struct umass_softc *sc) } int +umass_scsi_detach(struct umass_softc *sc, int flags) +{ + struct umass_scsi_softc *scbus = sc->bus; + int rv = 0; + + if (scbus != NULL) { + if (scbus->sc_child != NULL) + rv = config_detach(scbus->sc_child, flags); + free(scbus, M_DEVBUF, sizeof(*scbus)); + sc->bus = NULL; + } + + return (rv); +} + +int umass_scsi_probe(struct scsi_link *link) { struct umass_softc *sc = link->adapter_softc; @@ -289,7 +303,7 @@ umass_scsi_minphys(struct buf *bp, struct scsi_link *sl) void umass_scsi_cb(struct umass_softc *sc, void *priv, int residue, int status) { - struct umass_scsi_softc *scbus = (struct umass_scsi_softc *)sc->bus; + struct umass_scsi_softc *scbus = sc->bus; struct scsi_xfer *xs = priv; struct scsi_link *link = xs->sc_link; int cmdlen; diff --git a/sys/dev/usb/umass_scsi.h b/sys/dev/usb/umass_scsi.h index 37d1897a1b0..321eb675e3b 100644 --- a/sys/dev/usb/umass_scsi.h +++ b/sys/dev/usb/umass_scsi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: umass_scsi.h,v 1.4 2008/06/26 05:42:19 ray Exp $ */ +/* $OpenBSD: umass_scsi.h,v 1.5 2015/12/16 14:50:26 mpi Exp $ */ /* $NetBSD: umass_scsipi.h,v 1.1 2001/12/24 13:25:53 augustss Exp $ */ /* @@ -33,3 +33,4 @@ int umass_scsi_attach(struct umass_softc *sc); int umass_atapi_attach(struct umass_softc *sc); +int umass_scsi_detach(struct umass_softc *sc, int flags); diff --git a/sys/dev/usb/umassvar.h b/sys/dev/usb/umassvar.h index 9280f8f54bc..d55b671a025 100644 --- a/sys/dev/usb/umassvar.h +++ b/sys/dev/usb/umassvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: umassvar.h,v 1.14 2013/11/06 14:37:31 pirofti Exp $ */ +/* $OpenBSD: umassvar.h,v 1.15 2015/12/16 14:50:26 mpi Exp $ */ /* $NetBSD: umassvar.h,v 1.20 2003/09/08 19:31:01 mycroft Exp $ */ /*- * Copyright (c) 1999 MAEKAWA Masahide <bishop@rr.iij4u.or.jp>, @@ -144,9 +144,7 @@ struct umass_wire_methods { umass_wire_state wire_state; }; -struct umassbus_softc { - struct device *sc_child; /* child device, for detach */ -}; +struct umass_scsi_softc; /* the per device structure */ struct umass_softc { @@ -261,7 +259,7 @@ struct umass_softc { int sc_refcnt; int sc_sense; - struct umassbus_softc *bus; /* bus dependent data */ + struct umass_scsi_softc *bus; /* bus dependent data */ /* For polled transfers */ int polling_depth; |