Module Name:    src
Committed By:   riastradh
Date:           Fri Dec 31 14:24:16 UTC 2021

Modified Files:
        src/sys/dev/usb: umass.c umass_scsipi.c umassvar.h

Log Message:
umass(4): Omit needless reference counting.

autoconf never detaches before attach has completed, so there is no
longer any need for this mechanism.


To generate a diff of this commit:
cvs rdiff -u -r1.186 -r1.187 src/sys/dev/usb/umass.c
cvs rdiff -u -r1.69 -r1.70 src/sys/dev/usb/umass_scsipi.c
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/usb/umassvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/umass.c
diff -u src/sys/dev/usb/umass.c:1.186 src/sys/dev/usb/umass.c:1.187
--- src/sys/dev/usb/umass.c:1.186	Thu Sep 16 22:19:11 2021
+++ src/sys/dev/usb/umass.c	Fri Dec 31 14:24:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass.c,v 1.186 2021/09/16 22:19:11 andvar Exp $	*/
+/*	$NetBSD: umass.c,v 1.187 2021/12/31 14:24:16 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -124,7 +124,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.186 2021/09/16 22:19:11 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.187 2021/12/31 14:24:16 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -392,7 +392,6 @@ umass_attach(device_t parent, device_t s
 	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;

Index: src/sys/dev/usb/umass_scsipi.c
diff -u src/sys/dev/usb/umass_scsipi.c:1.69 src/sys/dev/usb/umass_scsipi.c:1.70
--- src/sys/dev/usb/umass_scsipi.c:1.69	Sat Aug  7 16:19:17 2021
+++ src/sys/dev/usb/umass_scsipi.c	Fri Dec 31 14:24:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass_scsipi.c,v 1.69 2021/08/07 16:19:17 thorpej Exp $	*/
+/*	$NetBSD: umass_scsipi.c,v 1.70 2021/12/31 14:24:16 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.69 2021/08/07 16:19:17 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.70 2021/12/31 14:24:16 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -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 *s
 	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 *s
 	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;
 }

Index: src/sys/dev/usb/umassvar.h
diff -u src/sys/dev/usb/umassvar.h:1.39 src/sys/dev/usb/umassvar.h:1.40
--- src/sys/dev/usb/umassvar.h:1.39	Tue Nov 13 10:30:57 2018
+++ src/sys/dev/usb/umassvar.h	Fri Dec 31 14:24:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umassvar.h,v 1.39 2018/11/13 10:30:57 mlelstv Exp $	*/
+/*	$NetBSD: umassvar.h,v 1.40 2021/12/31 14:24:16 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999 MAEKAWA Masahide <bis...@rr.iij4u.or.jp>,
@@ -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 */

Reply via email to