Module Name:    src
Committed By:   mrg
Date:           Thu Aug 29 09:17:51 UTC 2019

Modified Files:
        src/sys/dev/usb: usbnet.c

Log Message:
fix a lock hang reported by sc.dying in PR#54495.

remove locking in usbnet_tick().  assume that all locking
needs are handled inside usbnet_tick_task(), which runs in
the usbtask thread.  ensure that usbnet private is valid
before using it.

also check NULL private pointer in usbnet_isdying().
all the other cases should never happen.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/usb/usbnet.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/usb/usbnet.c
diff -u src/sys/dev/usb/usbnet.c:1.24 src/sys/dev/usb/usbnet.c:1.25
--- src/sys/dev/usb/usbnet.c:1.24	Wed Aug 28 06:07:21 2019
+++ src/sys/dev/usb/usbnet.c	Thu Aug 29 09:17:51 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbnet.c,v 1.24 2019/08/28 06:07:21 mrg Exp $	*/
+/*	$NetBSD: usbnet.c,v 1.25 2019/08/29 09:17:51 mrg Exp $	*/
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.24 2019/08/28 06:07:21 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.25 2019/08/29 09:17:51 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -1101,12 +1101,10 @@ usbnet_tick(void *arg)
 	struct usbnet * const un = arg;
 	struct usbnet_private * const unp = un->un_pri;
 
-	mutex_enter(&unp->unp_lock);
-	if (!unp->unp_stopping && !unp->unp_dying) {
+	if (unp != NULL && !unp->unp_stopping && !unp->unp_dying) {
 		/* Perform periodic stuff in process context */
 		usb_add_task(un->un_udev, &unp->unp_ticktask, USB_TASKQ_DRIVER);
 	}
-	mutex_exit(&unp->unp_lock);
 }
 
 static void
@@ -1225,7 +1223,6 @@ usbnet_rndsrc(struct usbnet *un)
 void *
 usbnet_softc(struct usbnet *un)
 {
-	//return un->un_pri->unp_sc;
 	return un->un_sc;
 }
 
@@ -1238,7 +1235,7 @@ usbnet_havelink(struct usbnet *un)
 bool
 usbnet_isdying(struct usbnet *un)
 {
-	return un->un_pri->unp_dying;
+	return un->un_pri == NULL || un->un_pri->unp_dying;
 }
 
 

Reply via email to