Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Fix order of nulling un->un_pri->unp_ec.ec_mii.



details:   https://anonhg.NetBSD.org/src/rev/ab669fbb14e5
branches:  trunk
changeset: 465744:ab669fbb14e5
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Dec 03 05:01:45 2019 +0000

description:
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).

diffstat:

 sys/dev/usb/usbnet.c |  22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diffs (62 lines):

diff -r 7c46754531f4 -r ab669fbb14e5 sys/dev/usb/usbnet.c
--- a/sys/dev/usb/usbnet.c      Tue Dec 03 04:59:05 2019 +0000
+++ b/sys/dev/usb/usbnet.c      Tue Dec 03 05:01:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbnet.c,v 1.30 2019/11/06 07:30:59 mrg Exp $  */
+/*     $NetBSD: usbnet.c,v 1.31 2019/12/03 05:01:45 riastradh Exp $    */
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.30 2019/11/06 07:30:59 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.31 2019/12/03 05:01:45 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -1187,19 +1187,19 @@
        struct ifnet * const ifp = usbnet_ifp(un);
        struct mii_data * const mii = usbnet_mii(un);
 
+       KASSERT(ifp != NULL);   /* embedded member */
+       KASSERT(mii != NULL);   /* only removed after dying=true and wait */
+
        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);
-               mii_tick(mii);
-
-               if (!unp->unp_link)
-                       (*mii->mii_statchg)(ifp);
-       }
+       DPRINTFN(8, "mii %jx ifp %jx", (uintptr_t)mii, (uintptr_t)ifp, 0, 0);
+       mii_tick(mii);
+       if (!unp->unp_link)
+               (*mii->mii_statchg)(ifp);
 
        /* Call driver if requested. */
        uno_tick(un);
@@ -1534,7 +1534,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))
@@ -1543,6 +1542,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