Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb clean up ucom parents some more:



details:   https://anonhg.NetBSD.org/src/rev/ca704d914d6f
branches:  trunk
changeset: 451181:ca704d914d6f
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu May 09 02:43:35 2019 +0000

description:
clean up ucom parents some more:
- it's always "bool sc_dying" now, with true/false
- heavy use of static functions
- remove all ucom parent ca_activate callbacks.  they're never called.
- callbacks should generally do little to nothing if sc_dying is set
- open resources should be released in detach after setting sc_dying
- don't complain about usbd_abort_pipe() or usbd_close_pipe() failure
- when releasing resources, zero the softc member as well
- remove ucom_methods members no longer destined to be filled in
- generally, DPRINTF() before sc_dying short circuit
- use EIO when dying, not ENXIO or 0
- add some ucom_open() callbacks that simply return EIO if dying

diffstat:

 sys/dev/usb/u3g.c           |   70 ++++++-----------
 sys/dev/usb/uark.c          |   96 +++++++++++++-----------
 sys/dev/usb/ubsa.c          |   47 +++---------
 sys/dev/usb/ubsa_common.c   |   53 ++++++++-----
 sys/dev/usb/ubsavar.h       |    5 +-
 sys/dev/usb/uchcom.c        |   48 ++++--------
 sys/dev/usb/ucom.c          |   27 +------
 sys/dev/usb/ucomvar.h       |   20 ++++-
 sys/dev/usb/uftdi.c         |   90 +++++++++++------------
 sys/dev/usb/ugensa.c        |   57 +++++---------
 sys/dev/usb/uhmodem.c       |   68 ++++++-----------
 sys/dev/usb/uipaq.c         |   52 +++++++------
 sys/dev/usb/ukyopon.c       |   19 +---
 sys/dev/usb/umcs.c          |   55 +++++--------
 sys/dev/usb/umct.c          |  155 +++++++++++++++++++--------------------
 sys/dev/usb/umodem.c        |   29 ++----
 sys/dev/usb/umodem_common.c |   47 +++++------
 sys/dev/usb/umodemvar.h     |    3 +-
 sys/dev/usb/uplcom.c        |  170 +++++++++++++++++++++----------------------
 sys/dev/usb/uslsa.c         |   45 +++--------
 sys/dev/usb/uvisor.c        |   75 +++++++++---------
 sys/dev/usb/uvscom.c        |  166 ++++++++++++++++++++----------------------
 22 files changed, 625 insertions(+), 772 deletions(-)

diffs (truncated from 3459 to 300 lines):

diff -r ea8b51801ea0 -r ca704d914d6f sys/dev/usb/u3g.c
--- a/sys/dev/usb/u3g.c Thu May 09 01:46:37 2019 +0000
+++ b/sys/dev/usb/u3g.c Thu May 09 02:43:35 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: u3g.c,v 1.36 2019/05/04 08:04:13 mrg Exp $     */
+/*     $NetBSD: u3g.c,v 1.37 2019/05/09 02:43:35 mrg Exp $     */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: u3g.c,v 1.36 2019/05/04 08:04:13 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: u3g.c,v 1.37 2019/05/09 02:43:35 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -148,11 +148,10 @@
 static int u3g_match(device_t, cfdata_t, void *);
 static void u3g_attach(device_t, device_t, void *);
 static int u3g_detach(device_t, int);
-static int u3g_activate(device_t, enum devact);
 static void u3g_childdet(device_t, device_t);
 
 CFATTACH_DECL2_NEW(u3g, sizeof(struct u3g_softc), u3g_match,
-    u3g_attach, u3g_detach, u3g_activate, NULL, u3g_childdet);
+    u3g_attach, u3g_detach, NULL, NULL, u3g_childdet);
 
 
 static void u3g_intr(struct usbd_xfer *, void *, usbd_status);
@@ -348,7 +347,6 @@
        ucaa.ucaa_portno = -1;
        ucaa.ucaa_bulkin = ucaa.ucaa_bulkout = -1;
 
-
        sc->sc_ifaceno = uiaa->uiaa_ifaceno;
        intr_address = -1;
        intr_size = 0;
@@ -431,25 +429,13 @@
 u3g_detach(device_t self, int flags)
 {
        struct u3g_softc *sc = device_private(self);
-       int rv;
-
-       if (sc->sc_dying)
-               return 0;
-
-       pmf_device_deregister(self);
+       int rv = 0;
 
-       for (size_t i = 0; i < sc->sc_ncom; i++)
-               if (sc->sc_com[i].c_dev != NULL) {
-                       rv = config_detach(sc->sc_com[i].c_dev, flags);
-                       if (rv != 0) {
-                               aprint_verbose_dev(self, "Can't deallocate "
-                                   "port (%d)", rv);
-                       }
-               }
+       sc->sc_dying = true;
 
        if (sc->sc_intr_pipe != NULL) {
-               (void) usbd_abort_pipe(sc->sc_intr_pipe);
-               (void) usbd_close_pipe(sc->sc_intr_pipe);
+               usbd_abort_pipe(sc->sc_intr_pipe);
+               usbd_close_pipe(sc->sc_intr_pipe);
                sc->sc_intr_pipe = NULL;
        }
        if (sc->sc_intr_buff != NULL) {
@@ -457,7 +443,22 @@
                sc->sc_intr_buff = NULL;
        }
 
-       return 0;
+       for (size_t i = 0; i < sc->sc_ncom; i++)
+               if (sc->sc_com[i].c_dev != NULL) {
+                       int port_rv;
+
+                       port_rv = config_detach(sc->sc_com[i].c_dev, flags);
+                       if (port_rv != 0) {
+                               aprint_verbose_dev(self, "Can't deallocate "
+                                   "port (%d)", port_rv);
+                       }
+                       rv |= port_rv;
+                       sc->sc_com[i].c_dev = NULL;
+               }
+
+       pmf_device_deregister(self);
+
+       return rv;
 }
 
 static void
@@ -470,29 +471,6 @@
                            sc->sc_com[i].c_dev = NULL;
 }
 
-static int
-u3g_activate(device_t self, enum devact act)
-{
-       struct u3g_softc *sc = device_private(self);
-       int rv = 0;
-
-       switch (act) {
-       case DVACT_DEACTIVATE:
-               for (size_t i = 0; i < sc->sc_ncom; i++)
-                       if (sc->sc_com[i].c_dev != NULL &&
-                           config_deactivate(sc->sc_com[i].c_dev) && rv == 0)
-                       rv = -1;
-               else
-                       rv = 0;
-               break;
-
-       default:
-               break;
-       }
-
-       return rv;
-}
-
 static void
 u3g_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
 {
@@ -602,7 +580,7 @@
        int i, nin;
 
        if (sc->sc_dying)
-               return 0;
+               return EIO;
 
        err = usbd_device2interface_handle(sc->sc_udev, sc->sc_ifaceno, &ih);
        if (err)
diff -r ea8b51801ea0 -r ca704d914d6f sys/dev/usb/uark.c
--- a/sys/dev/usb/uark.c        Thu May 09 01:46:37 2019 +0000
+++ b/sys/dev/usb/uark.c        Thu May 09 02:43:35 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uark.c,v 1.14 2019/05/05 03:17:54 mrg Exp $    */
+/*     $NetBSD: uark.c,v 1.15 2019/05/09 02:43:35 mrg Exp $    */
 /*     $OpenBSD: uark.c,v 1.13 2009/10/13 19:33:17 pirofti Exp $       */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uark.c,v 1.14 2019/05/05 03:17:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uark.c,v 1.15 2019/05/09 02:43:35 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -75,34 +75,35 @@
        u_char                  sc_msr;
        u_char                  sc_lsr;
 
-       u_char                  sc_dying;
+       bool                    sc_dying;
 };
 
-void   uark_get_status(void *, int portno, u_char *lsr, u_char *msr);
-void   uark_set(void *, int, int, int);
-int    uark_param(void *, int, struct termios *);
-void   uark_break(void *, int, int);
-int    uark_cmd(struct uark_softc *, uint16_t, uint16_t);
+static void    uark_get_status(void *, int portno, u_char *lsr, u_char *msr);
+static void    uark_set(void *, int, int, int);
+static int     uark_param(void *, int, struct termios *);
+static int     uark_open(void *, int);
+static void    uark_break(void *, int, int);
+static int     uark_cmd(struct uark_softc *, uint16_t, uint16_t);
 
 struct ucom_methods uark_methods = {
        .ucom_get_status = uark_get_status,
        .ucom_set = uark_set,
        .ucom_param = uark_param,
+       .ucom_open = uark_open,
 };
 
 static const struct usb_devno uark_devs[] = {
        { USB_VENDOR_ARKMICROCHIPS, USB_PRODUCT_ARKMICROCHIPS_USBSERIAL },
 };
 
-int             uark_match(device_t, cfdata_t, void *);
-void            uark_attach(device_t, device_t, void *);
-int             uark_detach(device_t, int);
-int             uark_activate(device_t, enum devact);
+static int     uark_match(device_t, cfdata_t, void *);
+static void    uark_attach(device_t, device_t, void *);
+static int     uark_detach(device_t, int);
 
 CFATTACH_DECL_NEW(uark, sizeof(struct uark_softc), uark_match, uark_attach,
-    uark_detach, uark_activate);
+    uark_detach, NULL);
 
-int
+static int
 uark_match(device_t parent, cfdata_t match, void *aux)
 {
        struct usb_attach_arg *uaa = aux;
@@ -111,7 +112,7 @@
            != NULL) ? UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
 }
 
-void
+static void
 uark_attach(device_t parent, device_t self, void *aux)
 {
        struct uark_softc *sc = device_private(self);
@@ -134,10 +135,11 @@
        usbd_devinfo_free(devinfop);
 
        sc->sc_udev = dev;
+       sc->sc_dying = false;
 
        if (usbd_set_config_index(sc->sc_udev, UARK_CONFIG_NO, 1) != 0) {
                aprint_error_dev(self, "could not set configuration no\n");
-               sc->sc_dying = 1;
+               sc->sc_dying = true;
                return;
        }
 
@@ -146,7 +148,7 @@
            &sc->sc_iface);
        if (error != 0) {
                aprint_error_dev(self, "could not get interface handle\n");
-               sc->sc_dying = 1;
+               sc->sc_dying = true;
                return;
        }
 
@@ -158,7 +160,7 @@
                if (ed == NULL) {
                        aprint_error_dev(self,
                            "no endpoint descriptor found for %d\n", i);
-                       sc->sc_dying = 1;
+                       sc->sc_dying = true;
                        return;
                }
 
@@ -172,7 +174,7 @@
 
        if (ucaa.ucaa_bulkin == -1 || ucaa.ucaa_bulkout == -1) {
                aprint_error_dev(self, "missing endpoint\n");
-               sc->sc_dying = 1;
+               sc->sc_dying = true;
                return;
        }
 
@@ -194,13 +196,14 @@
        return;
 }
 
-int
+static int
 uark_detach(device_t self, int flags)
 {
        struct uark_softc *sc = device_private(self);
        int rv = 0;
 
-       sc->sc_dying = 1;
+       sc->sc_dying = true;
+
        if (sc->sc_subdev != NULL) {
                rv = config_detach(sc->sc_subdev, flags);
                sc->sc_subdev = NULL;
@@ -211,27 +214,14 @@
        return rv;
 }
 
-int
-uark_activate(device_t self, enum devact act)
-{
-       struct uark_softc *sc = device_private(self);
-       int rv = 0;
-
-       switch (act) {
-       case DVACT_DEACTIVATE:
-               if (sc->sc_subdev != NULL)
-                       rv = config_deactivate(sc->sc_subdev);
-               sc->sc_dying = 1;
-               break;
-       }
-       return rv;
-}
-
-void
+static void
 uark_set(void *vsc, int portno, int reg, int onoff)
 {
        struct uark_softc *sc = vsc;
 
+       if (sc->sc_dying)
+               return;
+
        switch (reg) {
        case UCOM_SET_BREAK:
                uark_break(sc, portno, onoff);
@@ -243,12 +233,15 @@
        }
 }
 



Home | Main Index | Thread Index | Old Index