Module Name: src Committed By: mrg Date: Thu Feb 23 09:31:56 UTC 2012
Modified Files: src/sys/dev/usb [jmcneill-usbmp]: uhidev.c uhidev.h Log Message: - remove redundant sc_refcnt member - protect sc_state with a mutex To generate a diff of this commit: cvs rdiff -u -r1.52.6.1 -r1.52.6.2 src/sys/dev/usb/uhidev.c cvs rdiff -u -r1.11.2.1 -r1.11.2.2 src/sys/dev/usb/uhidev.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/uhidev.c diff -u src/sys/dev/usb/uhidev.c:1.52.6.1 src/sys/dev/usb/uhidev.c:1.52.6.2 --- src/sys/dev/usb/uhidev.c:1.52.6.1 Sat Feb 18 07:35:09 2012 +++ src/sys/dev/usb/uhidev.c Thu Feb 23 09:31:56 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: uhidev.c,v 1.52.6.1 2012/02/18 07:35:09 mrg Exp $ */ +/* $NetBSD: uhidev.c,v 1.52.6.2 2012/02/23 09:31:56 mrg Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.52.6.1 2012/02/18 07:35:09 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.52.6.2 2012/02/23 09:31:56 mrg Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -129,6 +129,8 @@ uhidev_attach(device_t parent, device_t aprint_naive("\n"); aprint_normal("\n"); + mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_USB); + id = usbd_get_interface_descriptor(iface); devinfop = usbd_devinfo_alloc(uaa->device, 0); @@ -450,6 +452,7 @@ uhidev_detach(device_t self, int flags) sc->sc_dev); pmf_device_deregister(self); + mutex_destroy(&sc->sc_lock); return (rv); } @@ -534,14 +537,15 @@ uhidev_open(struct uhidev *scd) usbd_status err; int error; - DPRINTF(("uhidev_open: open pipe, state=%d refcnt=%d\n", - scd->sc_state, sc->sc_refcnt)); + DPRINTF(("uhidev_open: open pipe, state=%d\n", scd->sc_state)); - if (scd->sc_state & UHIDEV_OPEN) + mutex_enter(&sc->sc_lock); + if (scd->sc_state & UHIDEV_OPEN) { + mutex_exit(&sc->sc_lock); return (EBUSY); + } scd->sc_state |= UHIDEV_OPEN; - if (sc->sc_refcnt++) - return (0); + mutex_exit(&sc->sc_lock); if (sc->sc_isize == 0) return (0); @@ -598,11 +602,12 @@ out2: out1: DPRINTF(("uhidev_open: failed in someway")); free(sc->sc_ibuf, M_USBDEV); + mutex_enter(&sc->sc_lock); scd->sc_state &= ~UHIDEV_OPEN; - sc->sc_refcnt = 0; sc->sc_ipipe = NULL; sc->sc_opipe = NULL; sc->sc_oxfer = NULL; + mutex_exit(&sc->sc_lock); return error; } @@ -611,11 +616,14 @@ uhidev_close(struct uhidev *scd) { struct uhidev_softc *sc = scd->sc_parent; - if (!(scd->sc_state & UHIDEV_OPEN)) + mutex_enter(&sc->sc_lock); + if (!(scd->sc_state & UHIDEV_OPEN)) { + mutex_exit(&sc->sc_lock); return; + } scd->sc_state &= ~UHIDEV_OPEN; - if (--sc->sc_refcnt) - return; + mutex_exit(&sc->sc_lock); + DPRINTF(("uhidev_close: close pipe\n")); if (sc->sc_oxfer != NULL) Index: src/sys/dev/usb/uhidev.h diff -u src/sys/dev/usb/uhidev.h:1.11.2.1 src/sys/dev/usb/uhidev.h:1.11.2.2 --- src/sys/dev/usb/uhidev.h:1.11.2.1 Sat Feb 18 07:35:09 2012 +++ src/sys/dev/usb/uhidev.h Thu Feb 23 09:31:56 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: uhidev.h,v 1.11.2.1 2012/02/18 07:35:09 mrg Exp $ */ +/* $NetBSD: uhidev.h,v 1.11.2.2 2012/02/23 09:31:56 mrg Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -53,8 +53,9 @@ struct uhidev_softc { u_int sc_nrepid; device_t *sc_subdevs; - int sc_refcnt; u_char sc_dying; + + kmutex_t sc_lock; /* protects writes to sc_state */ }; struct uhidev {