Thu Mar 3 05:55:10 2022 UTC ()
usbnet: Do nothing on if_init/stop if already in the target state.

The network stack _shouldn't_ ever call us if so, but I'm not yet
sure it _won't_.


(riastradh)
diff -r1.84 -r1.85 src/sys/dev/usb/usbnet.c

cvs diff -r1.84 -r1.85 src/sys/dev/usb/usbnet.c (expand / switch to unified diff)

--- src/sys/dev/usb/usbnet.c 2022/03/03 05:54:52 1.84
+++ src/sys/dev/usb/usbnet.c 2022/03/03 05:55:10 1.85
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbnet.c,v 1.84 2022/03/03 05:54:52 riastradh Exp $ */ 1/* $NetBSD: usbnet.c,v 1.85 2022/03/03 05:55:10 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2019 Matthew R. Green 4 * Copyright (c) 2019 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * Common code shared between USB network drivers. 30 * Common code shared between USB network drivers.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.84 2022/03/03 05:54:52 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.85 2022/03/03 05:55:10 riastradh Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/kmem.h> 38#include <sys/kmem.h>
39#include <sys/module.h> 39#include <sys/module.h>
40#include <sys/atomic.h> 40#include <sys/atomic.h>
41 41
42#include <dev/usb/usbnet.h> 42#include <dev/usb/usbnet.h>
43#include <dev/usb/usbhist.h> 43#include <dev/usb/usbhist.h>
44 44
45struct usbnet_cdata { 45struct usbnet_cdata {
46 struct usbnet_chain *uncd_tx_chain; 46 struct usbnet_chain *uncd_tx_chain;
47 struct usbnet_chain *uncd_rx_chain; 47 struct usbnet_chain *uncd_rx_chain;
@@ -1152,26 +1152,36 @@ usbnet_stop(struct usbnet *un, struct if @@ -1152,26 +1152,36 @@ usbnet_stop(struct usbnet *un, struct if
1152 KASSERTMSG(!unp->unp_ifp_attached || IFNET_LOCKED(ifp), 1152 KASSERTMSG(!unp->unp_ifp_attached || IFNET_LOCKED(ifp),
1153 "%s", ifp->if_xname); 1153 "%s", ifp->if_xname);
1154 ifp->if_flags &= ~IFF_RUNNING; 1154 ifp->if_flags &= ~IFF_RUNNING;
1155} 1155}
1156 1156
1157static void 1157static void
1158usbnet_if_stop(struct ifnet *ifp, int disable) 1158usbnet_if_stop(struct ifnet *ifp, int disable)
1159{ 1159{
1160 struct usbnet * const un = ifp->if_softc; 1160 struct usbnet * const un = ifp->if_softc;
1161 struct usbnet_private * const unp = un->un_pri; 1161 struct usbnet_private * const unp = un->un_pri;
1162 1162
1163 KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname); 1163 KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname);
1164 1164
 1165 /*
 1166 * If we're already stopped, nothing to do.
 1167 *
 1168 * XXX This should be an assertion, but it may require some
 1169 * analysis -- and possibly some tweaking -- of sys/net to
 1170 * ensure.
 1171 */
 1172 if ((ifp->if_flags & IFF_RUNNING) == 0)
 1173 return;
 1174
1165 mutex_enter(&unp->unp_core_lock); 1175 mutex_enter(&unp->unp_core_lock);
1166 usbnet_stop(un, ifp, disable); 1176 usbnet_stop(un, ifp, disable);
1167 mutex_exit(&unp->unp_core_lock); 1177 mutex_exit(&unp->unp_core_lock);
1168} 1178}
1169 1179
1170/* 1180/*
1171 * Generic tick task function. 1181 * Generic tick task function.
1172 * 1182 *
1173 * usbnet_tick() is triggered from a callout, and triggers a call to 1183 * usbnet_tick() is triggered from a callout, and triggers a call to
1174 * usbnet_tick_task() from the usb_task subsystem. 1184 * usbnet_tick_task() from the usb_task subsystem.
1175 */ 1185 */
1176static void 1186static void
1177usbnet_tick(void *arg) 1187usbnet_tick(void *arg)
@@ -1253,26 +1263,36 @@ usbnet_if_init(struct ifnet *ifp) @@ -1253,26 +1263,36 @@ usbnet_if_init(struct ifnet *ifp)
1253 USBNETHIST_FUNC(); USBNETHIST_CALLED(); 1263 USBNETHIST_FUNC(); USBNETHIST_CALLED();
1254 struct usbnet * const un = ifp->if_softc; 1264 struct usbnet * const un = ifp->if_softc;
1255 int error; 1265 int error;
1256 1266
1257 KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname); 1267 KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname);
1258 1268
1259 /* 1269 /*
1260 * Prevent anyone from bringing the interface back up once 1270 * Prevent anyone from bringing the interface back up once
1261 * we're detaching. 1271 * we're detaching.
1262 */ 1272 */
1263 if (usbnet_isdying(un)) 1273 if (usbnet_isdying(un))
1264 return EIO; 1274 return EIO;
1265 1275
 1276 /*
 1277 * If we're already running, nothing to do.
 1278 *
 1279 * XXX This should be an assertion, but it may require some
 1280 * analysis -- and possibly some tweaking -- of sys/net to
 1281 * ensure.
 1282 */
 1283 if (ifp->if_flags & IFF_RUNNING)
 1284 return 0;
 1285
1266 mutex_enter(&un->un_pri->unp_core_lock); 1286 mutex_enter(&un->un_pri->unp_core_lock);
1267 error = uno_init(un, ifp); 1287 error = uno_init(un, ifp);
1268 mutex_exit(&un->un_pri->unp_core_lock); 1288 mutex_exit(&un->un_pri->unp_core_lock);
1269 1289
1270 return error; 1290 return error;
1271} 1291}
1272 1292
1273 1293
1274/* Various accessors. */ 1294/* Various accessors. */
1275 1295
1276void 1296void
1277usbnet_set_link(struct usbnet *un, bool link) 1297usbnet_set_link(struct usbnet *un, bool link)
1278{ 1298{