NetBSD-Bugs archive

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

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




would you please try this patch, see if it helps?  (thank's to skrll@
for pointing this out to me.)  i've compile-tested this only, i'm not
in a good position to test it against my own systems right now.

thanks.


.mrg.


Index: uhidev.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/uhidev.c,v
retrieving revision 1.59
diff -p -r1.59 uhidev.c
*** uhidev.c    26 Dec 2013 15:32:48 -0000      1.59
--- uhidev.c    14 Jun 2014 22:15:50 -0000
*************** uhidev_open(struct uhidev *scd)
*** 537,543 ****
        usbd_status err;
        int error;
  
!       DPRINTF(("uhidev_open: open pipe, state=%d\n", scd->sc_state));
  
        mutex_enter(&sc->sc_lock);
        if (scd->sc_state & UHIDEV_OPEN) {
--- 537,544 ----
        usbd_status err;
        int error;
  
!       DPRINTF(("uhidev_open: open pipe, state=%d refcnt=%d\n",
!                scd->sc_state, sc->sc_refcnt));
  
        mutex_enter(&sc->sc_lock);
        if (scd->sc_state & UHIDEV_OPEN) {
*************** uhidev_open(struct uhidev *scd)
*** 545,550 ****
--- 546,553 ----
                return (EBUSY);
        }
        scd->sc_state |= UHIDEV_OPEN;
+       if (sc->sc_refcnt++)
+               return (0);
        mutex_exit(&sc->sc_lock);
  
        if (sc->sc_isize == 0)
*************** out1:
*** 604,609 ****
--- 607,613 ----
        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;
*************** uhidev_close(struct uhidev *scd)
*** 623,628 ****
--- 627,634 ----
                return;
        }
        scd->sc_state &= ~UHIDEV_OPEN;
+       if (--sc->sc_refcnt)
+               return;
        mutex_exit(&sc->sc_lock);
  
        DPRINTF(("uhidev_close: close pipe\n"));
Index: uhidev.h
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/uhidev.h,v
retrieving revision 1.14
diff -p -r1.14 uhidev.h
*** uhidev.h    26 Sep 2013 07:25:31 -0000      1.14
--- uhidev.h    14 Jun 2014 22:15:50 -0000
*************** struct uhidev_softc {
*** 53,58 ****
--- 53,59 ----
        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