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 a lock hang reported by sc.dying in PR#54495.



details:   https://anonhg.NetBSD.org/src/rev/fc7d56869675
branches:  trunk
changeset: 453851:fc7d56869675
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Aug 29 09:17:51 2019 +0000

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

diffstat:

 sys/dev/usb/usbnet.c |  11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diffs (49 lines):

diff -r b3f8d03e9d5b -r fc7d56869675 sys/dev/usb/usbnet.c
--- a/sys/dev/usb/usbnet.c      Thu Aug 29 06:43:13 2019 +0000
+++ b/sys/dev/usb/usbnet.c      Thu Aug 29 09:17:51 2019 +0000
@@ -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 @@
        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 @@
 void *
 usbnet_softc(struct usbnet *un)
 {
-       //return un->un_pri->unp_sc;
        return un->un_sc;
 }
 
@@ -1238,7 +1235,7 @@
 bool
 usbnet_isdying(struct usbnet *un)
 {
-       return un->un_pri->unp_dying;
+       return un->un_pri == NULL || un->un_pri->unp_dying;
 }
 
 



Home | Main Index | Thread Index | Old Index