[PATCH] USB: convert a bunch of USB semaphores to mutexes
the patch below converts a bunch of semaphores-used-as-mutex in the USB
code to mutexes
Signed-off-by: Arjan van de Ven <arjan@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index b3aca51..d0b1672 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -25,6 +25,7 @@
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <linux/completion.h>
+#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <linux/usb.h>
@@ -121,7 +122,7 @@
};
/* prevent races between open() and disconnect() */
-static DECLARE_MUTEX(disconnect_sem);
+static DEFINE_MUTEX(disconnect_mutex);
static int idmouse_create_image(struct usb_idmouse *dev)
{
@@ -213,18 +214,18 @@
int result = 0;
/* prevent disconnects */
- down(&disconnect_sem);
+ mutex_lock(&disconnect_mutex);
/* get the interface from minor number and driver information */
interface = usb_find_interface (&idmouse_driver, iminor (inode));
if (!interface) {
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
return -ENODEV;
}
/* get the device information block from the interface */
dev = usb_get_intfdata(interface);
if (!dev) {
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
return -ENODEV;
}
@@ -258,7 +259,7 @@
up(&dev->sem);
/* unlock the disconnect semaphore */
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
return result;
}
@@ -267,12 +268,12 @@
struct usb_idmouse *dev;
/* prevent a race condition with open() */
- down(&disconnect_sem);
+ mutex_lock(&disconnect_mutex);
dev = (struct usb_idmouse *) file->private_data;
if (dev == NULL) {
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
return -ENODEV;
}
@@ -282,7 +283,7 @@
/* are we really open? */
if (dev->open <= 0) {
up(&dev->sem);
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
return -ENODEV;
}
@@ -292,12 +293,12 @@
/* the device was unplugged before the file was released */
up(&dev->sem);
idmouse_delete(dev);
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
return 0;
}
up(&dev->sem);
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
return 0;
}
@@ -399,7 +400,7 @@
struct usb_idmouse *dev;
/* prevent races with open() */
- down(&disconnect_sem);
+ mutex_lock(&disconnect_mutex);
/* get device structure */
dev = usb_get_intfdata(interface);
@@ -421,7 +422,7 @@
if (!dev->open)
idmouse_delete(dev);
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
info("%s disconnected", DRIVER_DESC);
}
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index f6bdaf0..966acb4 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -33,6 +33,7 @@
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <linux/input.h>
@@ -172,7 +173,7 @@
};
/* prevent races between open() and disconnect() */
-static DECLARE_MUTEX(disconnect_sem);
+static DEFINE_MUTEX(disconnect_mutex);
static struct usb_driver ld_usb_driver;
@@ -293,7 +294,7 @@
nonseekable_open(inode, file);
subminor = iminor(inode);
- down(&disconnect_sem);
+ mutex_lock(&disconnect_mutex);
interface = usb_find_interface(&ld_usb_driver, subminor);
@@ -355,7 +356,7 @@
up(&dev->sem);
unlock_disconnect_exit:
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
return retval;
}
@@ -740,7 +741,7 @@
struct ld_usb *dev;
int minor;
- down(&disconnect_sem);
+ mutex_lock(&disconnect_mutex);
dev = usb_get_intfdata(intf);
usb_set_intfdata(intf, NULL);
@@ -761,7 +762,7 @@
up(&dev->sem);
}
- up(&disconnect_sem);
+ mutex_unlock(&disconnect_mutex);
dev_info(&intf->dev, "LD USB Device #%d now disconnected\n",
(minor - USB_LD_MINOR_BASE));
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 1336745..779bcf0 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -83,6 +83,7 @@
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <linux/completion.h>
+#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <linux/usb.h>
#include <linux/poll.h>
@@ -256,7 +257,7 @@
/* prevent races between open() and disconnect */
-static DECLARE_MUTEX (disconnect_sem);
+static DEFINE_MUTEX (disconnect_mutex);
/* file operations needed when we register this driver */
static struct file_operations tower_fops = {
@@ -349,7 +350,7 @@
nonseekable_open(inode, file);
subminor = iminor(inode);
- down (&disconnect_sem);
+ mutex_lock (&disconnect_mutex);
interface = usb_find_interface (&tower_driver, subminor);
@@ -427,7 +428,7 @@
up (&dev->sem);
unlock_disconnect_exit:
- up (&disconnect_sem);
+ mutex_unlock (&disconnect_mutex);
dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval);
@@ -1005,7 +1006,7 @@
dbg(2, "%s: enter", __FUNCTION__);
- down (&disconnect_sem);
+ mutex_lock (&disconnect_mutex);
dev = usb_get_intfdata (interface);
usb_set_intfdata (interface, NULL);
@@ -1027,7 +1028,7 @@
up (&dev->sem);
}
- up (&disconnect_sem);
+ mutex_unlock (&disconnect_mutex);
info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE));