Module Name:    src
Committed By:   martin
Date:           Sat Aug 12 11:21:15 UTC 2017

Modified Files:
        src/sys/dev/mii: nsphy.c

Log Message:
Do not deref a NULL pointer if no current media has been selected.
This error condition does not happen with properly working hardware, but it is
no good reason for a kernel panic either.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/dev/mii/nsphy.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/mii/nsphy.c
diff -u src/sys/dev/mii/nsphy.c:1.60 src/sys/dev/mii/nsphy.c:1.61
--- src/sys/dev/mii/nsphy.c:1.60	Thu Jul  7 06:55:41 2016
+++ src/sys/dev/mii/nsphy.c	Sat Aug 12 11:21:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: nsphy.c,v 1.60 2016/07/07 06:55:41 msaitoh Exp $	*/
+/*	$NetBSD: nsphy.c,v 1.61 2017/08/12 11:21:15 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nsphy.c,v 1.60 2016/07/07 06:55:41 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nsphy.c,v 1.61 2017/08/12 11:21:15 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -153,7 +153,7 @@ nsphy_service(struct mii_softc *sc, stru
 		/*
 		 * If we're not polling our PHY instance, just return.
 		 */
-		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
+		if (ife != NULL && IFM_INST(ife->ifm_media) != sc->mii_inst)
 			return (0);
 		break;
 
@@ -162,7 +162,7 @@ nsphy_service(struct mii_softc *sc, stru
 		 * If the media indicates a different PHY instance,
 		 * isolate ourselves.
 		 */
-		if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
+		if (ife != NULL && IFM_INST(ife->ifm_media) != sc->mii_inst) {
 			reg = PHY_READ(sc, MII_BMCR);
 			PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
 			return (0);
@@ -216,7 +216,7 @@ nsphy_service(struct mii_softc *sc, stru
 		/*
 		 * If we're not currently selected, just return.
 		 */
-		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
+		if (ife != NULL && IFM_INST(ife->ifm_media) != sc->mii_inst)
 			return (0);
 
 		if (mii_phy_tick(sc) == EJUSTRETURN)

Reply via email to