| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: usbnet.c,v 1.71 2022/03/03 05:50:22 riastradh Exp $ */ | | 1 | /* $NetBSD: usbnet.c,v 1.72 2022/03/03 05:50:31 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.71 2022/03/03 05:50:22 riastradh Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.72 2022/03/03 05:50:31 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 | |
45 | struct usbnet_cdata { | | 45 | struct 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; |
| @@ -1661,26 +1661,30 @@ usbnet_detach(device_t self, int flags) | | | @@ -1661,26 +1661,30 @@ usbnet_detach(device_t self, int flags) |
1661 | * coordination with if_mcast_op and doifioctl probably under a | | 1661 | * coordination with if_mcast_op and doifioctl probably under a |
1662 | * new lock. So we'll use this kludge until that mechanism is | | 1662 | * new lock. So we'll use this kludge until that mechanism is |
1663 | * invented. | | 1663 | * invented. |
1664 | * | | 1664 | * |
1665 | * [*] This is not exactly a documented property of the API, | | 1665 | * [*] This is not exactly a documented property of the API, |
1666 | * but it is implied by the single lock in the task queue | | 1666 | * but it is implied by the single lock in the task queue |
1667 | * serializing changes to the task state. | | 1667 | * serializing changes to the task state. |
1668 | */ | | 1668 | */ |
1669 | usb_rem_task_wait(un->un_udev, &unp->unp_mcasttask, USB_TASKQ_DRIVER, | | 1669 | usb_rem_task_wait(un->un_udev, &unp->unp_mcasttask, USB_TASKQ_DRIVER, |
1670 | NULL); | | 1670 | NULL); |
1671 | | | 1671 | |
1672 | mutex_enter(&unp->unp_core_lock); | | 1672 | mutex_enter(&unp->unp_core_lock); |
1673 | unp->unp_refcnt--; | | 1673 | unp->unp_refcnt--; |
| | | 1674 | if (unp->unp_refcnt >= 0) { |
| | | 1675 | aprint_error_dev(un->un_dev, "%d stragglers\n", |
| | | 1676 | unp->unp_refcnt + 1); |
| | | 1677 | } |
1674 | while (unp->unp_refcnt >= 0) { | | 1678 | while (unp->unp_refcnt >= 0) { |
1675 | /* Wait for processes to go away */ | | 1679 | /* Wait for processes to go away */ |
1676 | cv_wait(&unp->unp_detachcv, &unp->unp_core_lock); | | 1680 | cv_wait(&unp->unp_detachcv, &unp->unp_core_lock); |
1677 | } | | 1681 | } |
1678 | mutex_exit(&unp->unp_core_lock); | | 1682 | mutex_exit(&unp->unp_core_lock); |
1679 | | | 1683 | |
1680 | usbnet_rx_list_free(un); | | 1684 | usbnet_rx_list_free(un); |
1681 | usbnet_tx_list_free(un); | | 1685 | usbnet_tx_list_free(un); |
1682 | | | 1686 | |
1683 | rnd_detach_source(&unp->unp_rndsrc); | | 1687 | rnd_detach_source(&unp->unp_rndsrc); |
1684 | | | 1688 | |
1685 | cv_destroy(&unp->unp_detachcv); | | 1689 | cv_destroy(&unp->unp_detachcv); |
1686 | mutex_destroy(&unp->unp_core_lock); | | 1690 | mutex_destroy(&unp->unp_core_lock); |