Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/jmcneill-usbmp]: src/sys/dev/usb - remove redundant sc_refcnt member



details:   https://anonhg.NetBSD.org/src/rev/996fa333a356
branches:  jmcneill-usbmp
changeset: 771809:996fa333a356
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Feb 23 09:31:56 2012 +0000

description:
- remove redundant sc_refcnt member
- protect sc_state with a mutex

diffstat:

 sys/dev/usb/uhidev.c |  30 +++++++++++++++++++-----------
 sys/dev/usb/uhidev.h |   5 +++--
 2 files changed, 22 insertions(+), 13 deletions(-)

diffs (108 lines):

diff -r 857d762dc000 -r 996fa333a356 sys/dev/usb/uhidev.c
--- a/sys/dev/usb/uhidev.c      Thu Feb 23 09:25:03 2012 +0000
+++ b/sys/dev/usb/uhidev.c      Thu Feb 23 09:31:56 2012 +0000
@@ -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 @@
        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 @@
                           sc->sc_dev);
 
        pmf_device_deregister(self);
+       mutex_destroy(&sc->sc_lock);
 
        return (rv);
 }
@@ -534,14 +537,15 @@
        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 @@
 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 @@
 {
        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)
diff -r 857d762dc000 -r 996fa333a356 sys/dev/usb/uhidev.h
--- a/sys/dev/usb/uhidev.h      Thu Feb 23 09:25:03 2012 +0000
+++ b/sys/dev/usb/uhidev.h      Thu Feb 23 09:31:56 2012 +0000
@@ -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 @@
        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 {



Home | Main Index | Thread Index | Old Index