Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb make sure kernel lock is held when calling into ...



details:   https://anonhg.NetBSD.org/src/rev/ee4856450f7e
branches:  trunk
changeset: 772578:ee4856450f7e
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Jan 09 10:57:34 2012 +0000

description:
make sure kernel lock is held when calling into usb stack

diffstat:

 sys/dev/usb/auvitek.c     |  10 ++++++++--
 sys/dev/usb/auvitek_dtv.c |  13 +++++++++++--
 sys/dev/usb/emdtv.c       |  10 ++++++++--
 sys/dev/usb/emdtv_dtv.c   |  11 +++++++++--
 4 files changed, 36 insertions(+), 8 deletions(-)

diffs (196 lines):

diff -r 5710eff26f01 -r ee4856450f7e sys/dev/usb/auvitek.c
--- a/sys/dev/usb/auvitek.c     Mon Jan 09 06:49:25 2012 +0000
+++ b/sys/dev/usb/auvitek.c     Mon Jan 09 10:57:34 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: auvitek.c,v 1.7 2011/10/02 19:15:39 jmcneill Exp $ */
+/* $NetBSD: auvitek.c,v 1.8 2012/01/09 10:57:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: auvitek.c,v 1.7 2011/10/02 19:15:39 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auvitek.c,v 1.8 2012/01/09 10:57:34 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -359,8 +359,11 @@
        USETW(req.wIndex, reg);
        USETW(req.wLength, sizeof(data));
 
+       KERNEL_LOCK(1, curlwp);
        err = usbd_do_request_flags(sc->sc_udev, &req, &data, 0,
            &actlen, USBD_DEFAULT_TIMEOUT);
+       KERNEL_UNLOCK_ONE(curlwp);
+
        if (err)
                printf("%s: read failed: %s\n", device_xname(sc->sc_dev),
                    usbd_errstr(err));
@@ -381,8 +384,11 @@
        USETW(req.wIndex, reg);
        USETW(req.wLength, 0);
 
+       KERNEL_LOCK(1, curlwp);
        err = usbd_do_request_flags(sc->sc_udev, &req, NULL, 0,
            &actlen, USBD_DEFAULT_TIMEOUT);
+       KERNEL_UNLOCK_ONE(curlwp);
+
        if (err)
                printf("%s: write failed: %s\n", device_xname(sc->sc_dev),
                    usbd_errstr(err));
diff -r 5710eff26f01 -r ee4856450f7e sys/dev/usb/auvitek_dtv.c
--- a/sys/dev/usb/auvitek_dtv.c Mon Jan 09 06:49:25 2012 +0000
+++ b/sys/dev/usb/auvitek_dtv.c Mon Jan 09 10:57:34 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: auvitek_dtv.c,v 1.4 2011/10/02 19:15:40 jmcneill Exp $ */
+/* $NetBSD: auvitek_dtv.c,v 1.5 2012/01/09 10:57:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: auvitek_dtv.c,v 1.4 2011/10/02 19:15:40 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auvitek_dtv.c,v 1.5 2012/01/09 10:57:34 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -257,8 +257,11 @@
 {
        usbd_status err;
 
+       KERNEL_LOCK(1, curlwp);
        err = usbd_open_pipe(sc->sc_bulk_iface, sc->sc_ab.ab_endpt,
            USBD_EXCLUSIVE_USE, &sc->sc_ab.ab_pipe);
+       KERNEL_UNLOCK_ONE(curlwp);
+
        if (err) {
                aprint_error_dev(sc->sc_dev, "couldn't open bulk-in pipe: %s\n",
                    usbd_errstr(err));
@@ -272,8 +275,10 @@
 auvitek_dtv_close_pipes(struct auvitek_softc *sc)
 {
        if (sc->sc_ab.ab_pipe != NULL) {
+               KERNEL_LOCK(1, curlwp);
                usbd_abort_pipe(sc->sc_ab.ab_pipe);
                usbd_close_pipe(sc->sc_ab.ab_pipe);
+               KERNEL_UNLOCK_ONE(curlwp);
                sc->sc_ab.ab_pipe = NULL;
        }
 
@@ -348,7 +353,11 @@
            //USBD_SHORT_XFER_OK|USBD_NO_COPY, USBD_NO_TIMEOUT,
            USBD_NO_COPY, 100,
            auvitek_dtv_bulk_cb);
+
+       KERNEL_LOCK(1, curlwp);
        err = usbd_transfer(bx->bx_xfer);
+       KERNEL_UNLOCK_ONE(curlwp);
+
        if (err != USBD_IN_PROGRESS) {
                aprint_error_dev(sc->sc_dev, "USB error: %s\n",
                    usbd_errstr(err));
diff -r 5710eff26f01 -r ee4856450f7e sys/dev/usb/emdtv.c
--- a/sys/dev/usb/emdtv.c       Mon Jan 09 06:49:25 2012 +0000
+++ b/sys/dev/usb/emdtv.c       Mon Jan 09 10:57:34 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emdtv.c,v 1.6 2011/12/23 00:51:43 jakllsch Exp $ */
+/* $NetBSD: emdtv.c,v 1.7 2012/01/09 11:02:18 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2008, 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: emdtv.c,v 1.6 2011/12/23 00:51:43 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emdtv.c,v 1.7 2012/01/09 11:02:18 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -319,7 +319,10 @@
        USETW(request.wIndex, index);
        USETW(request.wLength, count);
 
+       KERNEL_LOCK(1, curlwp);
        status = usbd_do_request(sc->sc_udev, &request, datap);
+       KERNEL_UNLOCK_ONE(curlwp);
+
        if (status != USBD_NORMAL_COMPLETION)
                aprint_error_dev(sc->sc_dev, "couldn't read %x/%x: %s\n",
                    req, index, usbd_errstr(status));
@@ -347,7 +350,10 @@
        USETW(request.wIndex, index);
        USETW(request.wLength, count);
 
+       KERNEL_LOCK(1, curlwp);
        status = usbd_do_request(sc->sc_udev, &request, __UNCONST(datap));
+       KERNEL_UNLOCK_ONE(curlwp);
+
        if (status != USBD_NORMAL_COMPLETION)
                aprint_error_dev(sc->sc_dev, "couldn't read %x/%x: %s\n",
                    req, index, usbd_errstr(status));
diff -r 5710eff26f01 -r ee4856450f7e sys/dev/usb/emdtv_dtv.c
--- a/sys/dev/usb/emdtv_dtv.c   Mon Jan 09 06:49:25 2012 +0000
+++ b/sys/dev/usb/emdtv_dtv.c   Mon Jan 09 10:57:34 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emdtv_dtv.c,v 1.7 2011/12/23 00:51:43 jakllsch Exp $ */
+/* $NetBSD: emdtv_dtv.c,v 1.8 2012/01/09 11:02:18 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2008, 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: emdtv_dtv.c,v 1.7 2011/12/23 00:51:43 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emdtv_dtv.c,v 1.8 2012/01/09 11:02:18 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -306,6 +306,7 @@
        aprint_debug_dev(sc->sc_dev, "allocating isoc xfers (pktsz %d)\n",
            sc->sc_isoc_maxpacketsize);
 
+       KERNEL_LOCK(1, curlwp);
        for (i = 0; i < EMDTV_NXFERS; i++) {
                sc->sc_ix[i].ix_xfer = usbd_alloc_xfer(sc->sc_udev);
                sc->sc_ix[i].ix_buf = usbd_alloc_buffer(sc->sc_ix[i].ix_xfer,
@@ -313,6 +314,7 @@
                aprint_debug_dev(sc->sc_dev, "  ix[%d] xfer %p buf %p\n",
                    i, sc->sc_ix[i].ix_xfer, sc->sc_ix[i].ix_buf);
        }
+       KERNEL_UNLOCK_ONE(curlwp);
 
        aprint_debug_dev(sc->sc_dev, "starting isoc transactions\n");
 
@@ -332,6 +334,7 @@
 
        sc->sc_streaming = false;
 
+       KERNEL_LOCK(1, curlwp);
        if (sc->sc_isoc_pipe != NULL)
                usbd_abort_pipe(sc->sc_isoc_pipe);
 
@@ -341,6 +344,7 @@
                        sc->sc_ix[i].ix_xfer = NULL;
                        sc->sc_ix[i].ix_buf = NULL;
                }
+       KERNEL_UNLOCK_ONE(curlwp);
 
        sc->sc_dtvsubmitcb = NULL;
        sc->sc_dtvsubmitarg = NULL;
@@ -378,7 +382,10 @@
                             EMDTV_NFRAMES,
                             USBD_NO_COPY | USBD_SHORT_XFER_OK,
                             emdtv_dtv_isoc);
+
+       KERNEL_LOCK(1, curlwp);
        usbd_transfer(ix->ix_xfer);
+       KERNEL_UNLOCK_ONE(curlwp);
 
        return 0;
 }



Home | Main Index | Thread Index | Old Index