Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb usbnet: Omit needless locking around usbnet_isdy...



details:   https://anonhg.NetBSD.org/src/rev/ef1099e64451
branches:  trunk
changeset: 362514:ef1099e64451
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Mar 03 05:50:47 2022 +0000

description:
usbnet: Omit needless locking around usbnet_isdying.

Now that is tested and set with atomic_load/store, there is no need
to hold the lock -- which means we can set it while the core lock is
held during, e.g., a reset sequence, and use that to interrupt the
sequence so it doesn't get stuck waiting to time out when the device
is physically removed.

diffstat:

 sys/dev/usb/usbnet.c |  24 ++++++------------------
 1 files changed, 6 insertions(+), 18 deletions(-)

diffs (85 lines):

diff -r f2f8824849b5 -r ef1099e64451 sys/dev/usb/usbnet.c
--- a/sys/dev/usb/usbnet.c      Thu Mar 03 05:50:39 2022 +0000
+++ b/sys/dev/usb/usbnet.c      Thu Mar 03 05:50:47 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbnet.c,v 1.73 2022/03/03 05:50:39 riastradh Exp $    */
+/*     $NetBSD: usbnet.c,v 1.74 2022/03/03 05:50:47 riastradh Exp $    */
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.73 2022/03/03 05:50:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.74 2022/03/03 05:50:47 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -1075,12 +1075,11 @@
 {
        USBNETHIST_FUNC();
        struct usbnet * const un = arg;
-       struct usbnet_private * const unp = un->un_pri;
        struct ifnet * const ifp = usbnet_ifp(un);
-       bool dying;
        struct ifreq ifr;
 
-       USBNETHIST_CALLARGSN(10, "%jd: enter", unp->unp_number, 0, 0, 0);
+       USBNETHIST_CALLARGSN(10, "%jd: enter",
+           un->un_pri->unp_number, 0, 0, 0);
 
        /*
         * If we're detaching, we must check usbnet_isdying _before_
@@ -1091,10 +1090,7 @@
         * issuing if_detach, and necessary, so that we don't touch
         * IFNET_LOCK after if_detach.  See usbnet_detach for details.
         */
-       mutex_enter(&unp->unp_core_lock);
-       dying = usbnet_isdying(un);
-       mutex_exit(&unp->unp_core_lock);
-       if (dying)
+       if (usbnet_isdying(un))
                return;
 
        /*
@@ -1288,7 +1284,6 @@
 {
        USBNETHIST_FUNC(); USBNETHIST_CALLED();
        struct usbnet * const un = ifp->if_softc;
-       bool dying;
        int error;
 
        KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname);
@@ -1297,10 +1292,7 @@
         * Prevent anyone from bringing the interface back up once
         * we're detaching.
         */
-       mutex_enter(&un->un_pri->unp_core_lock);
-       dying = usbnet_isdying(un);
-       mutex_exit(&un->un_pri->unp_core_lock);
-       if (dying)
+       if (usbnet_isdying(un))
                return EIO;
 
        mutex_enter(&un->un_pri->unp_core_lock);
@@ -1591,9 +1583,7 @@
         * Prevent new activity.  After we stop the interface, it
         * cannot be brought back up.
         */
-       mutex_enter(&unp->unp_core_lock);
        atomic_store_relaxed(&unp->unp_dying, true);
-       mutex_exit(&unp->unp_core_lock);
 
        /*
         * If we're still running on the network, stop and wait for all
@@ -1720,9 +1710,7 @@
        case DVACT_DEACTIVATE:
                if_deactivate(ifp);
 
-               mutex_enter(&unp->unp_core_lock);
                atomic_store_relaxed(&unp->unp_dying, true);
-               mutex_exit(&unp->unp_core_lock);
 
                mutex_enter(&unp->unp_rxlock);
                mutex_enter(&unp->unp_txlock);



Home | Main Index | Thread Index | Old Index