Commit 7c5b971d authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

USB: iowarrior: drop redundant disconnect mutex

Drop the redundant disconnect mutex which was introduced after the
open-disconnect race had been addressed generally in USB core by commit
d4ead16f ("USB: prevent char device open/deregister race").

Specifically, the rw-semaphore in core guarantees that all calls to
open() will have completed and that no new calls to open() will occur
after usb_deregister_dev() returns. Hence there is no need use the
driver data as an inverted disconnected flag.
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20191009104846.5925-5-johan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b5f8d468
...@@ -58,7 +58,6 @@ MODULE_LICENSE("GPL"); ...@@ -58,7 +58,6 @@ MODULE_LICENSE("GPL");
static DEFINE_MUTEX(iowarrior_mutex); static DEFINE_MUTEX(iowarrior_mutex);
static struct usb_driver iowarrior_driver; static struct usb_driver iowarrior_driver;
static DEFINE_MUTEX(iowarrior_open_disc_lock);
/*--------------*/ /*--------------*/
/* data */ /* data */
...@@ -601,16 +600,13 @@ static int iowarrior_open(struct inode *inode, struct file *file) ...@@ -601,16 +600,13 @@ static int iowarrior_open(struct inode *inode, struct file *file)
return -ENODEV; return -ENODEV;
} }
mutex_lock(&iowarrior_open_disc_lock);
dev = usb_get_intfdata(interface); dev = usb_get_intfdata(interface);
if (!dev) { if (!dev) {
mutex_unlock(&iowarrior_open_disc_lock);
mutex_unlock(&iowarrior_mutex); mutex_unlock(&iowarrior_mutex);
return -ENODEV; return -ENODEV;
} }
mutex_lock(&dev->mutex); mutex_lock(&dev->mutex);
mutex_unlock(&iowarrior_open_disc_lock);
/* Only one process can open each device, no sharing. */ /* Only one process can open each device, no sharing. */
if (dev->opened) { if (dev->opened) {
...@@ -842,7 +838,6 @@ static int iowarrior_probe(struct usb_interface *interface, ...@@ -842,7 +838,6 @@ static int iowarrior_probe(struct usb_interface *interface,
if (retval) { if (retval) {
/* something prevented us from registering this driver */ /* something prevented us from registering this driver */
dev_err(&interface->dev, "Not able to get a minor for this device.\n"); dev_err(&interface->dev, "Not able to get a minor for this device.\n");
usb_set_intfdata(interface, NULL);
goto error; goto error;
} }
...@@ -866,16 +861,8 @@ static int iowarrior_probe(struct usb_interface *interface, ...@@ -866,16 +861,8 @@ static int iowarrior_probe(struct usb_interface *interface,
*/ */
static void iowarrior_disconnect(struct usb_interface *interface) static void iowarrior_disconnect(struct usb_interface *interface)
{ {
struct iowarrior *dev; struct iowarrior *dev = usb_get_intfdata(interface);
int minor; int minor = dev->minor;
dev = usb_get_intfdata(interface);
mutex_lock(&iowarrior_open_disc_lock);
usb_set_intfdata(interface, NULL);
minor = dev->minor;
mutex_unlock(&iowarrior_open_disc_lock);
/* give back our minor - this will call close() locks need to be dropped at this point*/
usb_deregister_dev(interface, &iowarrior_class); usb_deregister_dev(interface, &iowarrior_class);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment