Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb remove redundant checks against sc and sc->sc_dy...



details:   https://anonhg.NetBSD.org/src/rev/ab41fc96b679
branches:  trunk
changeset: 356139:ab41fc96b679
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Sep 05 05:03:02 2017 +0000

description:
remove redundant checks against sc and sc->sc_dying.
check sc_dying in more places.

diffstat:

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

diffs (147 lines):

diff -r ccada5708789 -r ab41fc96b679 sys/dev/usb/ugen.c
--- a/sys/dev/usb/ugen.c        Mon Sep 04 19:57:53 2017 +0000
+++ b/sys/dev/usb/ugen.c        Tue Sep 05 05:03:02 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ugen.c,v 1.134 2016/07/07 06:55:42 msaitoh Exp $       */
+/*     $NetBSD: ugen.c,v 1.135 2017/09/05 05:03:02 mrg 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.134 2016/07/07 06:55:42 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.135 2017/09/05 05:03:02 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -366,15 +366,12 @@
        int i, j;
 
        sc = device_lookup_private(&ugen_cd, unit);
-       if (sc == NULL)
+       if (sc == NULL || sc->sc_dying)
                return ENXIO;
 
        DPRINTFN(5, ("ugenopen: flag=%d, mode=%d, unit=%d endpt=%d\n",
                     flag, mode, unit, endpt));
 
-       if (sc == NULL || sc->sc_dying)
-               return ENXIO;
-
        /* The control endpoint allows multiple opens. */
        if (endpt == USB_CONTROL_ENDPOINT) {
                sc->sc_is_open[USB_CONTROL_ENDPOINT] = 1;
@@ -513,7 +510,7 @@
        int i;
 
        sc = device_lookup_private(& ugen_cd, UGENUNIT(dev));
-       if (sc == NULL)
+       if (sc == NULL || sc->sc_dying)
                return ENXIO;
 
        DPRINTFN(5, ("ugenclose: flag=%d, mode=%d, unit=%d, endpt=%d\n",
@@ -589,9 +586,6 @@
 
        DPRINTFN(5, ("%s: ugenread: %d\n", device_xname(sc->sc_dev), endpt));
 
-       if (sc->sc_dying)
-               return EIO;
-
        if (endpt == USB_CONTROL_ENDPOINT)
                return ENODEV;
 
@@ -801,7 +795,7 @@
        int error;
 
        sc = device_lookup_private(& ugen_cd, UGENUNIT(dev));
-       if (sc == NULL)
+       if (sc == NULL || sc->sc_dying)
                return ENXIO;
 
        mutex_enter(&sc->sc_lock);
@@ -832,9 +826,6 @@
 
        DPRINTFN(5, ("%s: ugenwrite: %d\n", device_xname(sc->sc_dev), endpt));
 
-       if (sc->sc_dying)
-               return EIO;
-
        if (endpt == USB_CONTROL_ENDPOINT)
                return ENODEV;
 
@@ -995,7 +986,7 @@
        int error;
 
        sc = device_lookup_private(& ugen_cd, UGENUNIT(dev));
-       if (sc == NULL)
+       if (sc == NULL || sc->sc_dying)
                return ENXIO;
 
        mutex_enter(&sc->sc_lock);
@@ -1830,7 +1821,7 @@
        int error;
 
        sc = device_lookup_private(& ugen_cd, UGENUNIT(dev));
-       if (sc == NULL)
+       if (sc == NULL || sc->sc_dying)
                return ENXIO;
 
        sc->sc_refcnt++;
@@ -1954,6 +1945,10 @@
 filt_ugenread_intr(struct knote *kn, long hint)
 {
        struct ugen_endpoint *sce = kn->kn_hook;
+       struct ugen_softc *sc = sce->sc;
+
+       if (sc->sc_dying)
+               return 0;
 
        kn->kn_data = sce->q.c_cc;
        return kn->kn_data > 0;
@@ -1963,6 +1958,10 @@
 filt_ugenread_isoc(struct knote *kn, long hint)
 {
        struct ugen_endpoint *sce = kn->kn_hook;
+       struct ugen_softc *sc = sce->sc;
+
+       if (sc->sc_dying)
+               return 0;
 
        if (sce->cur == sce->fill)
                return 0;
@@ -1980,6 +1979,10 @@
 filt_ugenread_bulk(struct knote *kn, long hint)
 {
        struct ugen_endpoint *sce = kn->kn_hook;
+       struct ugen_softc *sc = sce->sc;
+
+       if (sc->sc_dying)
+               return 0;
 
        if (!(sce->state & UGEN_BULK_RA))
                /*
@@ -2001,6 +2004,10 @@
 filt_ugenwrite_bulk(struct knote *kn, long hint)
 {
        struct ugen_endpoint *sce = kn->kn_hook;
+       struct ugen_softc *sc = sce->sc;
+
+       if (sc->sc_dying)
+               return 0;
 
        if (!(sce->state & UGEN_BULK_WB))
                /*
@@ -2038,10 +2045,7 @@
        struct klist *klist;
 
        sc = device_lookup_private(&ugen_cd, UGENUNIT(dev));
-       if (sc == NULL)
-               return ENXIO;
-
-       if (sc->sc_dying)
+       if (sc == NULL || sc->sc_dying)
                return ENXIO;
 
        if (UGENENDPOINT(dev) == USB_CONTROL_ENDPOINT)



Home | Main Index | Thread Index | Old Index