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 NULL checks after dereference.



details:   https://anonhg.NetBSD.org/src/rev/86f848afda9d
branches:  trunk
changeset: 839057:86f848afda9d
user:      rin <rin%NetBSD.org@localhost>
date:      Wed Feb 06 08:23:08 2019 +0000

description:
Fix NULL checks after dereference.

diffstat:

 sys/dev/usb/if_mue.c |  32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)

diffs (69 lines):

diff -r 973b2ca9452e -r 86f848afda9d sys/dev/usb/if_mue.c
--- a/sys/dev/usb/if_mue.c      Wed Feb 06 08:20:23 2019 +0000
+++ b/sys/dev/usb/if_mue.c      Wed Feb 06 08:23:08 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_mue.c,v 1.33 2019/02/06 08:20:23 rin Exp $  */
+/*     $NetBSD: if_mue.c,v 1.34 2019/02/06 08:23:08 rin Exp $  */
 /*     $OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $  */
 
 /*
@@ -20,7 +20,7 @@
 /* Driver for Microchip LAN7500/LAN7800 chipsets. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.33 2019/02/06 08:20:23 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.34 2019/02/06 08:23:08 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -359,12 +359,25 @@
 static void
 mue_miibus_statchg(struct ifnet *ifp)
 {
-       struct mue_softc *sc = ifp->if_softc;
-       struct mii_data *mii = GET_MII(sc);
+       struct mue_softc *sc;
+       struct mii_data *mii;
        uint32_t flow, threshold;
 
-       if (mii == NULL || ifp == NULL || (ifp->if_flags & IFF_RUNNING) == 0) {
-               DPRINTF(sc, "not ready\n");
+       if (ifp == NULL) {
+               DPRINTF(sc, "ifp not ready\n");
+               return;
+       }
+
+       if ((ifp->if_flags & IFF_RUNNING) == 0) {
+               DPRINTF(sc, "not running\n");
+               return;
+       }
+
+       sc = ifp->if_softc;
+       mii = GET_MII(sc);
+
+       if (mii == NULL) {
+               DPRINTF(sc, "mii not ready\n");
                return;
        }
 
@@ -1900,8 +1913,8 @@
 mue_tick_task(void *xsc)
 {
        struct mue_softc *sc = xsc;
-       struct ifnet *ifp = GET_IFP(sc);
-       struct mii_data *mii = GET_MII(sc);
+       struct ifnet *ifp;
+       struct mii_data *mii;
        int s;
 
        if (sc == NULL)
@@ -1910,6 +1923,9 @@
        if (sc->mue_dying)
                return;
 
+       ifp = GET_IFP(sc);
+       mii = GET_MII(sc);
+
        s = splnet();
        mii_tick(mii);
        if (sc->mue_link == 0)



Home | Main Index | Thread Index | Old Index