Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Prevent kernel panic on sleep if network interface ...



details:   https://anonhg.NetBSD.org/src/rev/3fb09b1fc06a
branches:  trunk
changeset: 380018:3fb09b1fc06a
user:      blymn <blymn%NetBSD.org@localhost>
date:      Wed Jun 30 21:52:16 2021 +0000

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

diffstat:

 sys/kern/kern_pmf.c |  21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diffs (42 lines):

diff -r 941489cea5bd -r 3fb09b1fc06a sys/kern/kern_pmf.c
--- a/sys/kern/kern_pmf.c       Wed Jun 30 21:20:29 2021 +0000
+++ b/sys/kern/kern_pmf.c       Wed Jun 30 21:52:16 2021 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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;
 }



Home | Main Index | Thread Index | Old Index