Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb PR/48908: Cannot open /dev/uhid? when another re...



details:   https://anonhg.NetBSD.org/src/rev/485f33c64b43
branches:  trunk
changeset: 330006:485f33c64b43
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Jun 17 09:35:46 2014 +0000

description:
PR/48908: Cannot open /dev/uhid? when another report id at the same uhidev
was already opened.

Restore the sc reference counting lost in usbmp merge.

diffstat:

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

diffs (65 lines):

diff -r 27c8502d421b -r 485f33c64b43 sys/dev/usb/uhidev.c
--- a/sys/dev/usb/uhidev.c      Tue Jun 17 08:42:35 2014 +0000
+++ b/sys/dev/usb/uhidev.c      Tue Jun 17 09:35:46 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhidev.c,v 1.59 2013/12/26 15:32:48 christos Exp $     */
+/*     $NetBSD: uhidev.c,v 1.60 2014/06/17 09:35:46 skrll Exp $        */
 
 /*
  * Copyright (c) 2001, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.59 2013/12/26 15:32:48 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.60 2014/06/17 09:35:46 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -545,6 +545,10 @@
                return (EBUSY);
        }
        scd->sc_state |= UHIDEV_OPEN;
+       if (sc->sc_refcnt++) {
+               mutex_exit(&sc->sc_lock);
+               return (0);
+       }
        mutex_exit(&sc->sc_lock);
 
        if (sc->sc_isize == 0)
@@ -604,6 +608,7 @@
        free(sc->sc_ibuf, M_USBDEV);
        mutex_enter(&sc->sc_lock);
        scd->sc_state &= ~UHIDEV_OPEN;
+       sc->sc_refcnt = 0;
        sc->sc_ibuf = NULL;
        sc->sc_ipipe = NULL;
        sc->sc_opipe = NULL;
@@ -623,6 +628,10 @@
                return;
        }
        scd->sc_state &= ~UHIDEV_OPEN;
+       if (--sc->sc_refcnt) {
+               mutex_exit(&sc->sc_lock);
+               return;
+       }
        mutex_exit(&sc->sc_lock);
 
        DPRINTF(("uhidev_close: close pipe\n"));
diff -r 27c8502d421b -r 485f33c64b43 sys/dev/usb/uhidev.h
--- a/sys/dev/usb/uhidev.h      Tue Jun 17 08:42:35 2014 +0000
+++ b/sys/dev/usb/uhidev.h      Tue Jun 17 09:35:46 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhidev.h,v 1.14 2013/09/26 07:25:31 skrll Exp $        */
+/*     $NetBSD: uhidev.h,v 1.15 2014/06/17 09:35:46 skrll Exp $        */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -53,6 +53,7 @@
        u_int sc_nrepid;
        device_t *sc_subdevs;
 
+       int sc_refcnt;
        u_char sc_dying;
 
        kmutex_t sc_lock;               /* protects writes to sc_state */



Home | Main Index | Thread Index | Old Index