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: Refuse to bring interfaces back up once ...
details: https://anonhg.NetBSD.org/src/rev/af89d25ed3c6
branches: trunk
changeset: 362497:af89d25ed3c6
user: riastradh <riastradh%NetBSD.org@localhost>
date: Thu Mar 03 05:48:37 2022 +0000
description:
usbnet: Refuse to bring interfaces back up once dying.
Make this happen uniformly across all usbnet drivers, not on a
per-driver basis.
This ensures new activity on the interface can't happen by the time
we have stopped existing activity and waited for it to complete.
diffstat:
sys/dev/usb/usbnet.c | 23 +++++++++++++++++++++--
1 files changed, 21 insertions(+), 2 deletions(-)
diffs (58 lines):
diff -r 32263407adc7 -r af89d25ed3c6 sys/dev/usb/usbnet.c
--- a/sys/dev/usb/usbnet.c Thu Mar 03 05:48:30 2022 +0000
+++ b/sys/dev/usb/usbnet.c Thu Mar 03 05:48:37 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usbnet.c,v 1.57 2022/03/03 05:48:30 riastradh Exp $ */
+/* $NetBSD: usbnet.c,v 1.58 2022/03/03 05:48:37 riastradh Exp $ */
/*
* Copyright (c) 2019 Matthew R. Green
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.57 2022/03/03 05:48:30 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.58 2022/03/03 05:48:37 riastradh Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -1289,9 +1289,20 @@
{
USBNETHIST_FUNC(); USBNETHIST_CALLED();
struct usbnet * const un = ifp->if_softc;
+ bool dying;
KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname);
+ /*
+ * Prevent anyone from bringing the interface back up once
+ * we're detaching.
+ */
+ mutex_enter(&un->un_pri->unp_core_lock);
+ dying = un->un_pri->unp_dying;
+ mutex_exit(&un->un_pri->unp_core_lock);
+ if (dying)
+ return EIO;
+
return uno_init(un, ifp);
}
@@ -1572,10 +1583,18 @@
struct ifnet * const ifp = usbnet_ifp(un);
struct mii_data * const mii = usbnet_mii(un);
+ /*
+ * Prevent new activity. After we stop the interface, it
+ * cannot be brought back up.
+ */
mutex_enter(&unp->unp_core_lock);
unp->unp_dying = true;
mutex_exit(&unp->unp_core_lock);
+ /*
+ * If we're still running on the network, stop and wait for all
+ * asynchronous activity to finish.
+ */
IFNET_LOCK(ifp);
if (ifp->if_flags & IFF_RUNNING) {
usbnet_if_stop(ifp, 1);
Home |
Main Index |
Thread Index |
Old Index