Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-9]: src/sys/dev/usb Pull up following revision(s) (requested by r...



details:   https://anonhg.NetBSD.org/src/rev/b7b71299fde1
branches:  netbsd-9
changeset: 466307:b7b71299fde1
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Dec 17 12:55:10 2019 +0000

description:
Pull up following revision(s) (requested by riastradh in ticket #565):

        sys/dev/usb/usbnet.c: revision 1.31
        sys/dev/usb/usbnet.c: revision 1.32
        sys/dev/usb/usbnet.c: revision 1.33

Fix order of nulling un->un_pri->unp_ec.ec_mii.

Can't null it until after if_detach prevents further use.

While here, fix conditionals in usbnet_tick_task to use the unp_dying
flag, not the nullness of mii (or of ifp, which never null because
it's an embedded member).

Fix inequality for refcnt drain: -1 here means all refs gone.

Don't assume mii is not null here. Some drivers like urndis don't use
mii, so they always have mii == NULL.
ok riastradh. fixes PR kern/54762

diffstat:

 sys/dev/usb/usbnet.c |  17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diffs (65 lines):

diff -r 5a06414ad10d -r b7b71299fde1 sys/dev/usb/usbnet.c
--- a/sys/dev/usb/usbnet.c      Tue Dec 17 12:52:23 2019 +0000
+++ b/sys/dev/usb/usbnet.c      Tue Dec 17 12:55:10 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbnet.c,v 1.25.2.3 2019/09/13 06:51:58 martin Exp $   */
+/*     $NetBSD: usbnet.c,v 1.25.2.4 2019/12/17 12:55:10 martin Exp $   */
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.25.2.3 2019/09/13 06:51:58 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.25.2.4 2019/12/17 12:55:10 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -1185,16 +1185,17 @@
        struct ifnet * const ifp = usbnet_ifp(un);
        struct mii_data * const mii = usbnet_mii(un);
 
+       KASSERT(ifp != NULL);   /* embedded member */
+
        unp->unp_refcnt++;
        mutex_exit(&unp->unp_lock);
 
-       if (ifp && unp->unp_timer != 0 && --unp->unp_timer == 0)
+       if (unp->unp_timer != 0 && --unp->unp_timer == 0)
                usbnet_watchdog(ifp);
 
-       if (mii && ifp) {
-               DPRINTFN(8, "mii %jx ifp %jx", (uintptr_t)mii, (uintptr_t)ifp, 0, 0);
+       DPRINTFN(8, "mii %jx ifp %jx", (uintptr_t)mii, (uintptr_t)ifp, 0, 0);
+       if (mii) {
                mii_tick(mii);
-
                if (!unp->unp_link)
                        (*mii->mii_statchg)(ifp);
        }
@@ -1517,7 +1518,7 @@
 
        mutex_enter(&unp->unp_lock);
        unp->unp_refcnt--;
-       while (unp->unp_refcnt > 0) {
+       while (unp->unp_refcnt >= 0) {
                /* Wait for processes to go away */
                cv_wait(&unp->unp_detachcv, &unp->unp_lock);
        }
@@ -1532,7 +1533,6 @@
        if (mii) {
                mii_detach(mii, MII_PHY_ANY, MII_OFFSET_ANY);
                ifmedia_delete_instance(&mii->mii_media, IFM_INST_ANY);
-               usbnet_ec(un)->ec_mii = NULL;
        }
        if (ifp->if_softc) {
                if (!usbnet_empty_eaddr(un))
@@ -1541,6 +1541,7 @@
                        bpf_detach(ifp);
                if_detach(ifp);
        }
+       usbnet_ec(un)->ec_mii = NULL;
 
        cv_destroy(&unp->unp_detachcv);
        mutex_destroy(&unp->unp_lock);



Home | Main Index | Thread Index | Old Index