Thu Mar 3 05:49:08 2022 UTC ()
usbnet: Don't issue a detach event if we never issued an attach one.


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

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

--- src/sys/dev/usb/usbnet.c 2022/03/03 05:49:00 1.61
+++ src/sys/dev/usb/usbnet.c 2022/03/03 05:49:07 1.62
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbnet.c,v 1.61 2022/03/03 05:49:00 riastradh Exp $ */ 1/* $NetBSD: usbnet.c,v 1.62 2022/03/03 05:49:07 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.61 2022/03/03 05:49:00 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.62 2022/03/03 05:49:07 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;
@@ -1670,27 +1670,34 @@ usbnet_detach(device_t self, int flags) @@ -1670,27 +1670,34 @@ usbnet_detach(device_t self, int flags)
1670 usbnet_tx_list_free(un); 1670 usbnet_tx_list_free(un);
1671 1671
1672 rnd_detach_source(&unp->unp_rndsrc); 1672 rnd_detach_source(&unp->unp_rndsrc);
1673 1673
1674 cv_destroy(&unp->unp_detachcv); 1674 cv_destroy(&unp->unp_detachcv);
1675 mutex_destroy(&unp->unp_core_lock); 1675 mutex_destroy(&unp->unp_core_lock);
1676 mutex_destroy(&unp->unp_rxlock); 1676 mutex_destroy(&unp->unp_rxlock);
1677 mutex_destroy(&unp->unp_txlock); 1677 mutex_destroy(&unp->unp_txlock);
1678 1678
1679 callout_destroy(&unp->unp_stat_ch); 1679 callout_destroy(&unp->unp_stat_ch);
1680 1680
1681 pmf_device_deregister(un->un_dev); 1681 pmf_device_deregister(un->un_dev);
1682 1682
1683 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, un->un_udev, un->un_dev); 1683 /*
 1684 * Notify userland that we're going away, if we arrived in the
 1685 * first place.
 1686 */
 1687 if (unp->unp_ifp_attached) {
 1688 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, un->un_udev,
 1689 un->un_dev);
 1690 }
1684 1691
1685 kmem_free(unp, sizeof(*unp)); 1692 kmem_free(unp, sizeof(*unp));
1686 un->un_pri = NULL; 1693 un->un_pri = NULL;
1687 1694
1688 return 0; 1695 return 0;
1689} 1696}
1690 1697
1691int 1698int
1692usbnet_activate(device_t self, devact_t act) 1699usbnet_activate(device_t self, devact_t act)
1693{ 1700{
1694 USBNETHIST_FUNC(); USBNETHIST_CALLED(); 1701 USBNETHIST_FUNC(); USBNETHIST_CALLED();
1695 struct usbnet * const un = device_private(self); 1702 struct usbnet * const un = device_private(self);
1696 struct usbnet_private * const unp = un->un_pri; 1703 struct usbnet_private * const unp = un->un_pri;