Source-Changes-HG archive

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

[src/netbsd-7]: src/sys/dev/usb Pull up following revision(s) (requested by m...



details:   https://anonhg.NetBSD.org/src/rev/2528de1078e2
branches:  netbsd-7
changeset: 461118:2528de1078e2
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Nov 16 16:13:56 2019 +0000

description:
Pull up following revision(s) (requested by mrg in ticket #1713):

        sys/dev/usb/usbdi.h: revision 1.97 (via patch)
        sys/dev/usb/usbdi.c: revision 1.186 (via patch)
        sys/dev/usb/usb_subr.c: revision 1.239 (via patch)

add new usbd_do_request_len() that can allocate a larger than
request size buffer.  reimplement usbd_do_request_flags() in
terms of this.  use this for fetching string descriptors.

fixes a very strange problem where an axe(4) attaching (either
has ugen(4) or axe(4)) would ask for 2 bytes, usb_mem.c would
allocate a 2 byte fragment, perform the operation, and sometime
shortly afterwards (usually by the time the next allocation
is made for this fragment), would become corrupted (usually
two bytes were written with 0x0304.)
(initial request of 4 bytes also avoids the problem on this
device.  it really seems like a HC problem -- host should not
allow the device to write more than req.wLength!  nor should
it allow this write to happen after completion.)

avoid an (almost) always double-log in usbd_transfer().

diffstat:

 sys/dev/usb/usb_subr.c |  21 ++++++++++++++-------
 sys/dev/usb/usbdi.c    |  18 +++++++++++++++---
 sys/dev/usb/usbdi.h    |   5 ++++-
 3 files changed, 33 insertions(+), 11 deletions(-)

diffs (132 lines):

diff -r a36383f728b4 -r 2528de1078e2 sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c    Thu Nov 14 18:17:19 2019 +0000
+++ b/sys/dev/usb/usb_subr.c    Sat Nov 16 16:13:56 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_subr.c,v 1.196.4.5 2018/08/08 10:17:11 martin Exp $        */
+/*     $NetBSD: usb_subr.c,v 1.196.4.6 2019/11/16 16:13:56 martin Exp $        */
 /*     $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $   */
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.196.4.5 2018/08/08 10:17:11 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.196.4.6 2019/11/16 16:13:56 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -157,13 +157,20 @@
        usbd_status err;
        int actlen;
 
+       /*
+        * Pass a full-sized buffer to usbd_do_request_len().  At least
+        * one device has been seen returning additional data beyond the
+        * provided buffers (2-bytes written shortly after the request
+        * claims to have completed and returned the 2 byte header,
+        * corrupting other memory.)
+        */
        req.bmRequestType = UT_READ_DEVICE;
        req.bRequest = UR_GET_DESCRIPTOR;
        USETW2(req.wValue, UDESC_STRING, sindex);
        USETW(req.wIndex, langid);
        USETW(req.wLength, 2);  /* only size byte first */
-       err = usbd_do_request_flags(dev, &req, sdesc, USBD_SHORT_XFER_OK,
-               &actlen, USBD_DEFAULT_TIMEOUT);
+       err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
+           USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
        if (err)
                return err;
 
@@ -171,8 +178,8 @@
                return USBD_SHORT_XFER;
 
        USETW(req.wLength, sdesc->bLength);     /* the whole string */
-       err = usbd_do_request_flags(dev, &req, sdesc, USBD_SHORT_XFER_OK,
-               &actlen, USBD_DEFAULT_TIMEOUT);
+       err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
+           USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
        if (err)
                return err;
 
@@ -1192,7 +1199,7 @@
        req.bRequest = UR_GET_DESCRIPTOR;
        USETW2(req.wValue, UDESC_DEVICE, 0);
        USETW(req.wIndex, 0);
-       USETW(req.wLength, 64);
+       USETW(req.wLength, 8);
        res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
                &actlen, USBD_DEFAULT_TIMEOUT);
        if (res)
diff -r a36383f728b4 -r 2528de1078e2 sys/dev/usb/usbdi.c
--- a/sys/dev/usb/usbdi.c       Thu Nov 14 18:17:19 2019 +0000
+++ b/sys/dev/usb/usbdi.c       Sat Nov 16 16:13:56 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdi.c,v 1.161.2.4 2019/01/11 15:58:23 martin Exp $   */
+/*     $NetBSD: usbdi.c,v 1.161.2.5 2019/11/16 16:13:56 martin Exp $   */
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.161.2.4 2019/01/11 15:58:23 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.161.2.5 2019/11/16 16:13:56 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -331,6 +331,8 @@
                 * accepted by the HCD for some reason.  It needs removing
                 * from the pipe queue.
                 */
+               USBHIST_LOG(usbdebug, "xfer failed: %s, reinserting",
+                   err, 0, 0, 0);
                usbd_lock_pipe(pipe);
                SIMPLEQ_REMOVE_HEAD(&pipe->up_queue, ux_next);
                if (pipe->up_serialise)
@@ -1072,13 +1074,23 @@
 usbd_do_request_flags(struct usbd_device *dev, usb_device_request_t *req,
     void *data, uint16_t flags, int *actlen, uint32_t timeout)
 {
+       size_t len = UGETW(req->wLength);
+
+       return usbd_do_request_len(dev, req, len, data, flags, actlen, timeout);
+}
+
+usbd_status
+usbd_do_request_len(struct usbd_device *dev, usb_device_request_t *req,
+    size_t len, void *data, uint16_t flags, int *actlen, uint32_t timeout)
+{
        USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
        struct usbd_xfer *xfer;
        usbd_status err;
 
+       KASSERT(len >= UGETW(req->wLength));
+
        ASSERT_SLEEPABLE();
 
-       size_t len = UGETW(req->wLength);
        int error = usbd_create_xfer(dev->ud_pipe0, len, 0, 0, &xfer);
        if (error)
                return error;
diff -r a36383f728b4 -r 2528de1078e2 sys/dev/usb/usbdi.h
--- a/sys/dev/usb/usbdi.h       Thu Nov 14 18:17:19 2019 +0000
+++ b/sys/dev/usb/usbdi.h       Sat Nov 16 16:13:56 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdi.h,v 1.90.2.2 2018/08/08 10:17:11 martin Exp $    */
+/*     $NetBSD: usbdi.h,v 1.90.2.3 2019/11/16 16:13:56 martin Exp $    */
 /*     $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $      */
 
 /*
@@ -141,6 +141,9 @@
 usbd_status usbd_do_request(struct usbd_device *, usb_device_request_t *, void *);
 usbd_status usbd_do_request_flags(struct usbd_device *, usb_device_request_t *,
     void *, uint16_t, int *, uint32_t);
+usbd_status usbd_do_request_len(struct usbd_device *dev,
+    usb_device_request_t *req, size_t len, void *data, uint16_t flags,
+    int *actlen, uint32_t timeout);
 
 usb_interface_descriptor_t *
     usbd_get_interface_descriptor(struct usbd_interface *);



Home | Main Index | Thread Index | Old Index