Module Name:    src
Committed By:   mrg
Date:           Sat Mar 23 02:19:31 UTC 2019

Modified Files:
        src/sys/dev/usb: uhid.c uhidev.h

Log Message:
use sc_lock not sc_access_lock to check UHIDEV_OPEN.

fixes a soft hang when usbhidaction has a uhid open and bzflag
tries to open it as well.

XXX: pullup-7, pullup-8 (where i saw this originally.)


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/usb/uhidev.h

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/uhid.c
diff -u src/sys/dev/usb/uhid.c:1.106 src/sys/dev/usb/uhid.c:1.107
--- src/sys/dev/usb/uhid.c:1.106	Fri Mar  1 11:06:56 2019
+++ src/sys/dev/usb/uhid.c	Sat Mar 23 02:19:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.106 2019/03/01 11:06:56 pgoyette Exp $	*/
+/*	$NetBSD: uhid.c,v 1.107 2019/03/23 02:19:31 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.106 2019/03/01 11:06:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.107 2019/03/23 02:19:31 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -317,21 +317,23 @@ uhidopen(dev_t dev, int flag, int mode, 
 	if (sc->sc_dying)
 		return ENXIO;
 
-	mutex_enter(&sc->sc_access_lock);
+	mutex_enter(&sc->sc_lock);
 
 	/*
 	 * uhid interrupts aren't enabled yet, so setup sc_q now, as
 	 * long as they're not already allocated.
 	 */
 	if (sc->sc_hdev.sc_state & UHIDEV_OPEN) {
-		mutex_exit(&sc->sc_access_lock);
+		mutex_exit(&sc->sc_lock);
 		return EBUSY;
 	}
+	mutex_exit(&sc->sc_lock);
+
 	if (clalloc(&sc->sc_q, UHID_BSIZE, 0) == -1) {
-		mutex_exit(&sc->sc_access_lock);
 		return ENOMEM;
 	}
 
+	mutex_enter(&sc->sc_access_lock);
 	error = uhidev_open(&sc->sc_hdev);
 	if (error) {
 		clfree(&sc->sc_q);

Index: src/sys/dev/usb/uhidev.h
diff -u src/sys/dev/usb/uhidev.h:1.19 src/sys/dev/usb/uhidev.h:1.20
--- src/sys/dev/usb/uhidev.h:1.19	Sat Apr 23 10:15:32 2016
+++ src/sys/dev/usb/uhidev.h	Sat Mar 23 02:19:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhidev.h,v 1.19 2016/04/23 10:15:32 skrll Exp $	*/
+/*	$NetBSD: uhidev.h,v 1.20 2019/03/23 02:19:31 mrg Exp $	*/
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -67,8 +67,8 @@ struct uhidev {
 	struct uhidev_softc *sc_parent;
 	uByte sc_report_id;
 	uint8_t sc_state;
-	int sc_in_rep_size;
 #define	UHIDEV_OPEN	0x01	/* device is open */
+	int sc_in_rep_size;
 	void (*sc_intr)(struct uhidev *, void *, u_int);
 	krndsource_t     rnd_source;
 };

Reply via email to