diff mbox series

[RFC,8/8] CDC-WDM: reduce scope of wdm_mutex

Message ID 20200921112052.27943-9-oneukum@suse.com (mailing list archive)
State New, archived
Headers show
Series [RFC,1/8] CDC-WDM: fix hangs in flush() | expand

Commit Message

Oliver Neukum Sept. 21, 2020, 11:20 a.m. UTC
Use the global mutex for as short as possible in open()

Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/usb/class/cdc-wdm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 7607ab2bbe07..230fe66828e3 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -704,6 +704,7 @@  static int wdm_open(struct inode *inode, struct file *file)
 
 	/* using write lock to protect desc->count */
 	mutex_lock(&desc->wlock);
+	mutex_unlock(&wdm_mutex);
 	if (!desc->count++) {
 		/* in case flush() had timed out */
 		usb_kill_urb(desc->command);
@@ -716,13 +717,14 @@  static int wdm_open(struct inode *inode, struct file *file)
 				"Error submitting int urb - %d\n", rv);
 			rv = usb_translate_errors(rv);
 		}
+		if (desc->count == 1)
+			desc->manage_power(intf, 1);
 	} else {
 		rv = 0;
 	}
 	mutex_unlock(&desc->wlock);
-	if (desc->count == 1)
-		desc->manage_power(intf, 1);
 	usb_autopm_put_interface(desc->intf);
+	return rv;
 out:
 	mutex_unlock(&wdm_mutex);
 	return rv;