From c5c27a1912331b20735f0f83f71ada966843ea13 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sun, 26 Dec 2021 11:56:27 +0000 Subject: [PATCH] umass(4): Omit needless reference counting. autoconf never detaches before attach has completed, so there is no longer any need for this mechanism. --- sys/dev/usb/umass.c | 14 -------------- sys/dev/usb/umass_scsipi.c | 19 ++++--------------- sys/dev/usb/umassvar.h | 2 -- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/sys/dev/usb/umass.c b/sys/dev/usb/umass.c index 6d17cd50e533..4657dfacf1b2 100644 --- a/sys/dev/usb/umass.c +++ b/sys/dev/usb/umass.c @@ -392,7 +392,6 @@ umass_attach(device_t parent, device_t self, void *aux) aprint_normal("\n"); mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); - cv_init(&sc->sc_detach_cv, "umassdet"); devinfop = usbd_devinfo_alloc(uiaa->uiaa_device, 0); aprint_normal_dev(self, "%s\n", devinfop); @@ -872,18 +871,6 @@ umass_detach(device_t self, int flags) } usbd_abort_default_pipe(sc->sc_udev); - /* Do we really need reference counting? Perhaps in ioctl() */ - mutex_enter(&sc->sc_lock); - if (--sc->sc_refcnt >= 0) { -#ifdef DIAGNOSTIC - aprint_normal_dev(self, "waiting for refcnt\n"); -#endif - /* Wait for processes to go away. */ - if (cv_timedwait(&sc->sc_detach_cv, &sc->sc_lock, hz * 60)) - aprint_error_dev(self, ": didn't detach\n"); - } - mutex_exit(&sc->sc_lock); - scbus = sc->bus; if (scbus != NULL) { if (scbus->sc_child != NULL) @@ -925,7 +912,6 @@ umass_detach(device_t self, int flags) usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev); mutex_destroy(&sc->sc_lock); - cv_destroy(&sc->sc_detach_cv); out: SDT_PROBE2(usb, umass, device, detach__done, sc, rv); return rv; diff --git a/sys/dev/usb/umass_scsipi.c b/sys/dev/usb/umass_scsipi.c index d502c248be03..6898c68df290 100644 --- a/sys/dev/usb/umass_scsipi.c +++ b/sys/dev/usb/umass_scsipi.c @@ -131,6 +131,8 @@ umass_scsi_attach(struct umass_softc *sc) UMASSHIST_FUNC(); UMASSHIST_CALLED(); struct umass_scsipi_softc *scbus; + KASSERT(KERNEL_LOCKED_P()); + scbus = umass_scsipi_setup(sc); scbus->sc_channel.chan_bustype = &scsi_bustype; @@ -139,17 +141,9 @@ umass_scsi_attach(struct umass_softc *sc) scbus->sc_channel.chan_id = scbus->sc_channel.chan_ntargets - 1; DPRINTFM(UDMASS_USB, "sc %#jx: SCSI", (uintptr_t)sc, 0, 0, 0); - mutex_enter(&sc->sc_lock); - sc->sc_refcnt++; - mutex_exit(&sc->sc_lock); scbus->base.sc_child = config_found(sc->sc_dev, &scbus->sc_channel, scsiprint, CFARGS(.iattr = "scsi")); - mutex_enter(&sc->sc_lock); - if (--sc->sc_refcnt < 0) - cv_broadcast(&sc->sc_detach_cv); - mutex_exit(&sc->sc_lock); - return 0; } @@ -171,6 +165,8 @@ umass_atapi_attach(struct umass_softc *sc) UMASSHIST_FUNC(); UMASSHIST_CALLED(); struct umass_scsipi_softc *scbus; + KASSERT(KERNEL_LOCKED_P()); + scbus = umass_scsipi_setup(sc); scbus->sc_atapi_adapter.atapi_probe_device = umass_atapi_probe_device; @@ -181,16 +177,9 @@ umass_atapi_attach(struct umass_softc *sc) scbus->sc_channel.chan_defquirks |= sc->sc_busquirks; DPRINTFM(UDMASS_USB, "sc %#jxp: ATAPI", (uintptr_t)sc, 0, 0, 0); - mutex_enter(&sc->sc_lock); - sc->sc_refcnt++; - mutex_exit(&sc->sc_lock); scbus->base.sc_child = config_found(sc->sc_dev, &scbus->sc_channel, atapiprint, CFARGS(.iattr = "atapi")); - mutex_enter(&sc->sc_lock); - if (--sc->sc_refcnt < 0) - cv_broadcast(&sc->sc_detach_cv); - mutex_exit(&sc->sc_lock); return 0; } diff --git a/sys/dev/usb/umassvar.h b/sys/dev/usb/umassvar.h index f434873e8666..7bc5ccf000b5 100644 --- a/sys/dev/usb/umassvar.h +++ b/sys/dev/usb/umassvar.h @@ -167,7 +167,6 @@ struct umass_softc { const struct umass_wire_methods *sc_methods; kmutex_t sc_lock; - kcondvar_t sc_detach_cv; uint8_t sc_wire; /* wire protocol */ #define UMASS_WPROTO_UNSPEC 0 @@ -276,7 +275,6 @@ struct umass_softc { #endif char sc_dying; - int sc_refcnt; int sc_sense; struct umassbus_softc *bus; /* bus dependent data */