Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb usb(4): Fix fix for interface change pipe fix.



details:   https://anonhg.NetBSD.org/src/rev/e9db62daae45
branches:  trunk
changeset: 1021656:e9db62daae45
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Jun 12 15:39:46 2021 +0000

description:
usb(4): Fix fix for interface change pipe fix.

If there is an interface:
- Always put the pipe on the list in usbd_setup_pipe (if successful).
- Always have the pipe on the list from _before_ upm_open.
- Always keep the pipe on the list to _after_ upm_close, and after
  the async task has completed.

This brings the logic in usbd_close_pipe and usbd_kill_pipe closer.

diffstat:

 sys/dev/usb/usb_subr.c |  17 +++++++++++++++--
 sys/dev/usb/usbdi.c    |  11 ++++-------
 2 files changed, 19 insertions(+), 9 deletions(-)

diffs (91 lines):

diff -r 4f72adc71322 -r e9db62daae45 sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c    Sat Jun 12 15:09:18 2021 +0000
+++ b/sys/dev/usb/usb_subr.c    Sat Jun 12 15:39:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_subr.c,v 1.256 2021/06/12 14:43:27 riastradh Exp $ */
+/*     $NetBSD: usb_subr.c,v 1.257 2021/06/12 15:39:46 riastradh 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.256 2021/06/12 14:43:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.257 2021/06/12 15:39:46 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -840,10 +840,22 @@
        p->up_interval = ival;
        p->up_flags = flags;
        SIMPLEQ_INIT(&p->up_queue);
+
+       if (iface) {
+               mutex_enter(&iface->ui_pipelock);
+               LIST_INSERT_HEAD(&iface->ui_pipes, p, up_next);
+               mutex_exit(&iface->ui_pipelock);
+       }
+
        err = dev->ud_bus->ub_methods->ubm_open(p);
        if (err) {
                DPRINTF("endpoint=%#jx failed, error=%jd",
                    (uintptr_t)ep->ue_edesc->bEndpointAddress, err, 0, 0);
+               if (iface) {
+                       mutex_enter(&iface->ui_pipelock);
+                       LIST_REMOVE(p, up_next);
+                       mutex_exit(&iface->ui_pipelock);
+               }
                kmem_free(p, dev->ud_bus->ub_pipesize);
                usbd_endpoint_release(dev, ep);
                return err;
@@ -898,6 +910,7 @@
        usbd_unlock_pipe(pipe);
        usb_rem_task_wait(pipe->up_dev, &pipe->up_async_task, USB_TASKQ_DRIVER,
            NULL);
+       KASSERT(pipe->up_iface == NULL);
        usbd_endpoint_release(pipe->up_dev, pipe->up_endpoint);
        kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
 }
diff -r 4f72adc71322 -r e9db62daae45 sys/dev/usb/usbdi.c
--- a/sys/dev/usb/usbdi.c       Sat Jun 12 15:09:18 2021 +0000
+++ b/sys/dev/usb/usbdi.c       Sat Jun 12 15:39:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdi.c,v 1.210 2021/06/12 15:09:18 riastradh Exp $    */
+/*     $NetBSD: usbdi.c,v 1.211 2021/06/12 15:39:46 riastradh 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.210 2021/06/12 15:09:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.211 2021/06/12 15:39:46 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -244,9 +244,6 @@
        err = usbd_setup_pipe_flags(iface->ui_dev, iface, ep, ival, &p, flags);
        if (err)
                return err;
-       mutex_enter(&iface->ui_pipelock);
-       LIST_INSERT_HEAD(&iface->ui_pipes, p, up_next);
-       mutex_exit(&iface->ui_pipelock);
        *pipe = p;
        SDT_PROBE5(usb, device, pipe, open,
            iface, address, flags, ival, p);
@@ -320,11 +317,11 @@
        usbd_unlock_pipe(pipe);
        if (pipe->up_intrxfer != NULL)
                usbd_destroy_xfer(pipe->up_intrxfer);
+       usb_rem_task_wait(pipe->up_dev, &pipe->up_async_task, USB_TASKQ_DRIVER,
+           NULL);
        mutex_enter(&pipe->up_iface->ui_pipelock);
        LIST_REMOVE(pipe, up_next);
        mutex_exit(&pipe->up_iface->ui_pipelock);
-       usb_rem_task_wait(pipe->up_dev, &pipe->up_async_task, USB_TASKQ_DRIVER,
-           NULL);
        usbd_endpoint_release(pipe->up_dev, pipe->up_endpoint);
        kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
 



Home | Main Index | Thread Index | Old Index