Thu Mar 3 05:49:00 2022 UTC ()
usbnet: Make detach order reverse attach order, for unp_stat_ch.

No functional change intended.


(riastradh)
diff -r1.60 -r1.61 src/sys/dev/usb/usbnet.c

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

--- src/sys/dev/usb/usbnet.c 2022/03/03 05:48:52 1.60
+++ src/sys/dev/usb/usbnet.c 2022/03/03 05:49:00 1.61
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbnet.c,v 1.60 2022/03/03 05:48:52 riastradh Exp $ */ 1/* $NetBSD: usbnet.c,v 1.61 2022/03/03 05:49:00 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.60 2022/03/03 05:48:52 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.61 2022/03/03 05:49:00 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;
@@ -1659,34 +1659,35 @@ usbnet_detach(device_t self, int flags) @@ -1659,34 +1659,35 @@ usbnet_detach(device_t self, int flags)
1659 NULL); 1659 NULL);
1660 1660
1661 mutex_enter(&unp->unp_core_lock); 1661 mutex_enter(&unp->unp_core_lock);
1662 unp->unp_refcnt--; 1662 unp->unp_refcnt--;
1663 while (unp->unp_refcnt >= 0) { 1663 while (unp->unp_refcnt >= 0) {
1664 /* Wait for processes to go away */ 1664 /* Wait for processes to go away */
1665 cv_wait(&unp->unp_detachcv, &unp->unp_core_lock); 1665 cv_wait(&unp->unp_detachcv, &unp->unp_core_lock);
1666 } 1666 }
1667 mutex_exit(&unp->unp_core_lock); 1667 mutex_exit(&unp->unp_core_lock);
1668 1668
1669 usbnet_rx_list_free(un); 1669 usbnet_rx_list_free(un);
1670 usbnet_tx_list_free(un); 1670 usbnet_tx_list_free(un);
1671 1671
1672 callout_destroy(&unp->unp_stat_ch); 
1673 rnd_detach_source(&unp->unp_rndsrc); 1672 rnd_detach_source(&unp->unp_rndsrc);
1674 1673
1675 cv_destroy(&unp->unp_detachcv); 1674 cv_destroy(&unp->unp_detachcv);
1676 mutex_destroy(&unp->unp_core_lock); 1675 mutex_destroy(&unp->unp_core_lock);
1677 mutex_destroy(&unp->unp_rxlock); 1676 mutex_destroy(&unp->unp_rxlock);
1678 mutex_destroy(&unp->unp_txlock); 1677 mutex_destroy(&unp->unp_txlock);
1679 1678
 1679 callout_destroy(&unp->unp_stat_ch);
 1680
1680 pmf_device_deregister(un->un_dev); 1681 pmf_device_deregister(un->un_dev);
1681 1682
1682 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, un->un_udev, un->un_dev); 1683 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, un->un_udev, un->un_dev);
1683 1684
1684 kmem_free(unp, sizeof(*unp)); 1685 kmem_free(unp, sizeof(*unp));
1685 un->un_pri = NULL; 1686 un->un_pri = NULL;
1686 1687
1687 return 0; 1688 return 0;
1688} 1689}
1689 1690
1690int 1691int
1691usbnet_activate(device_t self, devact_t act) 1692usbnet_activate(device_t self, devact_t act)
1692{ 1693{