Thu Mar 3 05:46:50 2022 UTC ()
usbnet: Simplify usbnet_isdying.

usbnet_detach (or its caller) stops all users before it returns.

If un->un_pri is null at this point, there's a bug -- something
didn't wait for everything to finish before calling usbnet_detach.


(riastradh)
diff -r1.44 -r1.45 src/sys/dev/usb/usbnet.c

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

--- src/sys/dev/usb/usbnet.c 2022/01/29 21:37:07 1.44
+++ src/sys/dev/usb/usbnet.c 2022/03/03 05:46:50 1.45
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbnet.c,v 1.44 2022/01/29 21:37:07 riastradh Exp $ */ 1/* $NetBSD: usbnet.c,v 1.45 2022/03/03 05:46:50 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.44 2022/01/29 21:37:07 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.45 2022/03/03 05:46:50 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;
@@ -1312,27 +1312,27 @@ usbnet_softc(struct usbnet *un) @@ -1312,27 +1312,27 @@ usbnet_softc(struct usbnet *un)
1312{ 1312{
1313 return un->un_sc; 1313 return un->un_sc;
1314} 1314}
1315 1315
1316bool 1316bool
1317usbnet_havelink(struct usbnet *un) 1317usbnet_havelink(struct usbnet *un)
1318{ 1318{
1319 return un->un_pri->unp_link; 1319 return un->un_pri->unp_link;
1320} 1320}
1321 1321
1322bool 1322bool
1323usbnet_isdying(struct usbnet *un) 1323usbnet_isdying(struct usbnet *un)
1324{ 1324{
1325 return un->un_pri == NULL || un->un_pri->unp_dying; 1325 return un->un_pri->unp_dying;
1326} 1326}
1327 1327
1328 1328
1329/* Locking. */ 1329/* Locking. */
1330 1330
1331void 1331void
1332usbnet_lock_core(struct usbnet *un) 1332usbnet_lock_core(struct usbnet *un)
1333{ 1333{
1334 mutex_enter(&un->un_pri->unp_core_lock); 1334 mutex_enter(&un->un_pri->unp_core_lock);
1335} 1335}
1336 1336
1337void 1337void
1338usbnet_unlock_core(struct usbnet *un) 1338usbnet_unlock_core(struct usbnet *un)