提交 8293c568 编写于 作者: M Matthias Kaehlcke 提交者: Greg Kroah-Hartman

USB: use mutex instead of semaphore in the Adutux driver

The Adutux driver uses a semaphore as mutex. Use the mutex API
instead of the (binary) semaphore.
Signed-off-by: NMatthias Kaehlcke <matthias.kaehlcke@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 d2066eb6
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/mutex.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#ifdef CONFIG_USB_DEBUG #ifdef CONFIG_USB_DEBUG
...@@ -80,7 +81,7 @@ MODULE_DEVICE_TABLE(usb, device_table); ...@@ -80,7 +81,7 @@ MODULE_DEVICE_TABLE(usb, device_table);
/* Structure to hold all of our device specific stuff */ /* Structure to hold all of our device specific stuff */
struct adu_device { struct adu_device {
struct semaphore sem; /* locks this structure */ struct mutex mtx; /* locks this structure */
struct usb_device* udev; /* save off the usb device pointer */ struct usb_device* udev; /* save off the usb device pointer */
struct usb_interface* interface; struct usb_interface* interface;
unsigned char minor; /* the starting minor number for this device */ unsigned char minor; /* the starting minor number for this device */
...@@ -269,8 +270,8 @@ static int adu_open(struct inode *inode, struct file *file) ...@@ -269,8 +270,8 @@ static int adu_open(struct inode *inode, struct file *file)
} }
/* lock this device */ /* lock this device */
if ((retval = down_interruptible(&dev->sem))) { if ((retval = mutex_lock_interruptible(&dev->mtx))) {
dbg(2, "%s : sem down failed", __FUNCTION__); dbg(2, "%s : mutex lock failed", __FUNCTION__);
goto exit_no_device; goto exit_no_device;
} }
...@@ -299,7 +300,7 @@ static int adu_open(struct inode *inode, struct file *file) ...@@ -299,7 +300,7 @@ static int adu_open(struct inode *inode, struct file *file)
if (retval) if (retval)
--dev->open_count; --dev->open_count;
} }
up(&dev->sem); mutex_unlock(&dev->mtx);
exit_no_device: exit_no_device:
dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval); dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval);
...@@ -347,7 +348,7 @@ static int adu_release(struct inode *inode, struct file *file) ...@@ -347,7 +348,7 @@ static int adu_release(struct inode *inode, struct file *file)
} }
/* lock our device */ /* lock our device */
down(&dev->sem); /* not interruptible */ mutex_lock(&dev->mtx); /* not interruptible */
if (dev->open_count <= 0) { if (dev->open_count <= 0) {
dbg(1," %s : device not opened", __FUNCTION__); dbg(1," %s : device not opened", __FUNCTION__);
...@@ -357,7 +358,7 @@ static int adu_release(struct inode *inode, struct file *file) ...@@ -357,7 +358,7 @@ static int adu_release(struct inode *inode, struct file *file)
if (dev->udev == NULL) { if (dev->udev == NULL) {
/* the device was unplugged before the file was released */ /* the device was unplugged before the file was released */
up(&dev->sem); mutex_unlock(&dev->mtx);
adu_delete(dev); adu_delete(dev);
dev = NULL; dev = NULL;
} else { } else {
...@@ -367,7 +368,7 @@ static int adu_release(struct inode *inode, struct file *file) ...@@ -367,7 +368,7 @@ static int adu_release(struct inode *inode, struct file *file)
exit: exit:
if (dev) if (dev)
up(&dev->sem); mutex_unlock(&dev->mtx);
dbg(2," %s : leave, return value %d", __FUNCTION__, retval); dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
return retval; return retval;
} }
...@@ -390,7 +391,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, ...@@ -390,7 +391,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
dev = file->private_data; dev = file->private_data;
dbg(2," %s : dev=%p", __FUNCTION__, dev); dbg(2," %s : dev=%p", __FUNCTION__, dev);
/* lock this object */ /* lock this object */
if (down_interruptible(&dev->sem)) if (mutex_lock_interruptible(&dev->mtx))
return -ERESTARTSYS; return -ERESTARTSYS;
/* verify that the device wasn't unplugged */ /* verify that the device wasn't unplugged */
...@@ -522,7 +523,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, ...@@ -522,7 +523,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
exit: exit:
/* unlock the device */ /* unlock the device */
up(&dev->sem); mutex_unlock(&dev->mtx);
dbg(2," %s : leave, return value %d", __FUNCTION__, retval); dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
return retval; return retval;
...@@ -543,7 +544,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, ...@@ -543,7 +544,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
dev = file->private_data; dev = file->private_data;
/* lock this object */ /* lock this object */
retval = down_interruptible(&dev->sem); retval = mutex_lock_interruptible(&dev->mtx);
if (retval) if (retval)
goto exit_nolock; goto exit_nolock;
...@@ -571,9 +572,9 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, ...@@ -571,9 +572,9 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
retval = -EINTR; retval = -EINTR;
goto exit; goto exit;
} }
up(&dev->sem); mutex_unlock(&dev->mtx);
timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout);
retval = down_interruptible(&dev->sem); retval = mutex_lock_interruptible(&dev->mtx);
if (retval) { if (retval) {
retval = bytes_written ? bytes_written : retval; retval = bytes_written ? bytes_written : retval;
goto exit_nolock; goto exit_nolock;
...@@ -638,7 +639,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, ...@@ -638,7 +639,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
exit: exit:
/* unlock the device */ /* unlock the device */
up(&dev->sem); mutex_unlock(&dev->mtx);
exit_nolock: exit_nolock:
dbg(2," %s : leave, return value %d", __FUNCTION__, retval); dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
...@@ -698,7 +699,7 @@ static int adu_probe(struct usb_interface *interface, ...@@ -698,7 +699,7 @@ static int adu_probe(struct usb_interface *interface,
goto exit; goto exit;
} }
init_MUTEX(&dev->sem); mutex_init(&dev->mtx);
spin_lock_init(&dev->buflock); spin_lock_init(&dev->buflock);
dev->udev = udev; dev->udev = udev;
init_waitqueue_head(&dev->read_wait); init_waitqueue_head(&dev->read_wait);
...@@ -835,16 +836,16 @@ static void adu_disconnect(struct usb_interface *interface) ...@@ -835,16 +836,16 @@ static void adu_disconnect(struct usb_interface *interface)
usb_deregister_dev(interface, &adu_class); usb_deregister_dev(interface, &adu_class);
dev->minor = 0; dev->minor = 0;
down(&dev->sem); /* not interruptible */ mutex_lock(&dev->mtx); /* not interruptible */
/* if the device is not opened, then we clean up right now */ /* if the device is not opened, then we clean up right now */
dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); dbg(2," %s : open count %d", __FUNCTION__, dev->open_count);
if (!dev->open_count) { if (!dev->open_count) {
up(&dev->sem); mutex_unlock(&dev->mtx);
adu_delete(dev); adu_delete(dev);
} else { } else {
dev->udev = NULL; dev->udev = NULL;
up(&dev->sem); mutex_unlock(&dev->mtx);
} }
dev_info(&interface->dev, "ADU device adutux%d now disconnected", dev_info(&interface->dev, "ADU device adutux%d now disconnected",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册