Module Name:    src
Committed By:   blymn
Date:           Wed Jun 30 21:52:16 UTC 2021

Modified Files:
        src/sys/kern: kern_pmf.c

Log Message:
Prevent kernel panic on sleep if network interface driver does not
have if_stop defined.  This is a common problem with usb adaptors.
This is a temporary fix, the printf needs to be converted to an
assert once the drivers are cleaned up.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/kern/kern_pmf.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/kern/kern_pmf.c
diff -u src/sys/kern/kern_pmf.c:1.45 src/sys/kern/kern_pmf.c:1.46
--- src/sys/kern/kern_pmf.c:1.45	Thu Jun 11 02:30:21 2020
+++ src/sys/kern/kern_pmf.c	Wed Jun 30 21:52:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_pmf.c,v 1.45 2020/06/11 02:30:21 thorpej Exp $ */
+/* $NetBSD: kern_pmf.c,v 1.46 2021/06/30 21:52:16 blymn Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_pmf.c,v 1.45 2020/06/11 02:30:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_pmf.c,v 1.46 2021/06/30 21:52:16 blymn Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -892,11 +892,18 @@ pmf_class_network_suspend(device_t dev, 
 	struct ifnet *ifp = device_pmf_class_private(dev);
 	int s;
 
-	s = splnet();
-	IFNET_LOCK(ifp);
-	(*ifp->if_stop)(ifp, 0);
-	IFNET_UNLOCK(ifp);
-	splx(s);
+	if (ifp == NULL)
+		return true;
+
+	if ((*ifp->if_stop) == NULL)
+		printf("device %s has no if_stop\n", ifp->if_xname);
+	else {
+		s = splnet();
+		IFNET_LOCK(ifp);
+		(*ifp->if_stop)(ifp, 0);
+		IFNET_UNLOCK(ifp);
+		splx(s);
+	}
 
 	return true;
 }

Reply via email to