Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb uatp(4): Fix detach logic.



details:   https://anonhg.NetBSD.org/src/rev/b8f5eedd80d8
branches:  trunk
changeset: 364548:b8f5eedd80d8
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Mar 28 12:44:54 2022 +0000

description:
uatp(4): Fix detach logic.

Let wsmouse child decide whether it's in use or close if mandatory.
If config_detach_children succeeds, this must no longer be open and
we can commit to freeing everything.

diffstat:

 sys/dev/usb/uatp.c |  33 +++++++++++++++------------------
 1 files changed, 15 insertions(+), 18 deletions(-)

diffs (92 lines):

diff -r b41cd037d784 -r b8f5eedd80d8 sys/dev/usb/uatp.c
--- a/sys/dev/usb/uatp.c        Mon Mar 28 12:44:45 2022 +0000
+++ b/sys/dev/usb/uatp.c        Mon Mar 28 12:44:54 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uatp.c,v 1.29 2022/03/28 12:44:17 riastradh Exp $      */
+/*     $NetBSD: uatp.c,v 1.30 2022/03/28 12:44:54 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2011-2014 The NetBSD Foundation, Inc.
@@ -146,7 +146,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uatp.c,v 1.29 2022/03/28 12:44:17 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uatp.c,v 1.30 2022/03/28 12:44:54 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -298,7 +298,7 @@
 static int uatp_ioctl(void *, unsigned long, void *, int, struct lwp *);
 static void geyser34_enable_raw_mode(struct uatp_softc *);
 static void geyser34_initialize(struct uatp_softc *);
-static int geyser34_finalize(struct uatp_softc *);
+static void geyser34_finalize(struct uatp_softc *);
 static void geyser34_deferred_reset(struct uatp_softc *);
 static void geyser34_reset_task(void *);
 static void uatp_intr(void *, void *, unsigned int);
@@ -553,8 +553,8 @@
        /* Device-specific initialization routine.  May be null.  */
        void (*initialize)(struct uatp_softc *);
 
-       /* Device-specific finalization routine.  May be null.  May fail.  */
-       int (*finalize)(struct uatp_softc *);
+       /* Device-specific finalization routine.  May be null.  */
+       void (*finalize)(struct uatp_softc *);
 
        /* Tests whether this is a base sample.  Second argument is
         * input_size bytes long.  */
@@ -1182,19 +1182,18 @@
 uatp_detach(device_t self, int flags)
 {
        struct uatp_softc *sc = device_private(self);
+       int error;
 
        DPRINTF(sc, UATP_DEBUG_MISC, ("detaching with flags %d\n", flags));
 
-        if (sc->sc_status & UATP_ENABLED) {
-               aprint_error_dev(uatp_dev(sc), "can't detach while enabled\n");
-               return EBUSY;
-        }
+       error = config_detach_children(self, flags);
+       if (error)
+               return error;
 
-       if (sc->sc_parameters->finalize) {
-               int error = sc->sc_parameters->finalize(sc);
-               if (error != 0)
-                       return error;
-       }
+       KASSERT((sc->sc_status & UATP_ENABLED) == 0);
+
+       if (sc->sc_parameters->finalize)
+               sc->sc_parameters->finalize(sc);
 
        pmf_device_deregister(self);
 
@@ -1203,7 +1202,7 @@
 
        tap_finalize(sc);
 
-       return config_detach_children(self, flags);
+       return 0;
 }
 
 static int
@@ -1363,15 +1362,13 @@
        usb_init_task(&sc->sc_reset_task, &geyser34_reset_task, sc, 0);
 }
 
-static int
+static void
 geyser34_finalize(struct uatp_softc *sc)
 {
 
        DPRINTF(sc, UATP_DEBUG_MISC, ("finalizing\n"));
        usb_rem_task_wait(sc->sc_udev, &sc->sc_reset_task, USB_TASKQ_DRIVER,
            NULL);
-
-       return 0;
 }
 
 static void



Home | Main Index | Thread Index | Old Index