Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb ugen(4): Refuse non-forced detach with EBUSY if ...



details:   https://anonhg.NetBSD.org/src/rev/a689576a7703
branches:  trunk
changeset: 985773:a689576a7703
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Sep 07 10:42:59 2021 +0000

description:
ugen(4): Refuse non-forced detach with EBUSY if endpoints are open.

Sprinkle some comments.

diffstat:

 sys/dev/usb/ugen.c |  22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diffs (46 lines):

diff -r 6f13c76b6278 -r a689576a7703 sys/dev/usb/ugen.c
--- a/sys/dev/usb/ugen.c        Tue Sep 07 10:42:48 2021 +0000
+++ b/sys/dev/usb/ugen.c        Tue Sep 07 10:42:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ugen.c,v 1.161 2021/09/07 10:42:48 riastradh Exp $     */
+/*     $NetBSD: ugen.c,v 1.162 2021/09/07 10:42:59 riastradh Exp $     */
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.161 2021/09/07 10:42:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.162 2021/09/07 10:42:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1167,9 +1167,27 @@
 
        DPRINTF(("ugen_detach: sc=%p flags=%d\n", sc, flags));
 
+       KASSERT(KERNEL_LOCKED_P()); /* sc_is_open */
+
+       /*
+        * Fail if we're not forced to detach and userland has any
+        * endpoints open.
+        */
+       if ((flags & DETACH_FORCE) == 0) {
+               for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
+                       if (sc->sc_is_open[i])
+                               return EBUSY;
+               }
+       }
+
+       /* Prevent new users.  Prevent suspend/resume.  */
        sc->sc_dying = 1;
        pmf_device_deregister(self);
 
+       /*
+        * If we never finished attaching, skip nixing endpoints and
+        * users because there aren't any.
+        */
        if (!sc->sc_attached)
                goto out;
 



Home | Main Index | Thread Index | Old Index