aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorMatthias Kaehlcke <matthias.kaehlcke@gmail.com>2007-07-13 15:28:31 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-19 20:46:03 -0400
commit8293c568b25611cdc4ac54ded438d8d7938c593c (patch)
tree0aab0b1031fdbe247d1eee674c2d617da63f7012 /drivers/usb
parentd2066eb659e6ee915383510c136da38eff86ef15 (diff)
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: Matthias Kaehlcke <matthias.kaehlcke@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/misc/adutux.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index d72c42e5f22..274d08ecf29 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -24,6 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/mutex.h>
27#include <asm/uaccess.h> 28#include <asm/uaccess.h>
28 29
29#ifdef CONFIG_USB_DEBUG 30#ifdef CONFIG_USB_DEBUG
@@ -80,7 +81,7 @@ MODULE_DEVICE_TABLE(usb, device_table);
80 81
81/* Structure to hold all of our device specific stuff */ 82/* Structure to hold all of our device specific stuff */
82struct adu_device { 83struct adu_device {
83 struct semaphore sem; /* locks this structure */ 84 struct mutex mtx; /* locks this structure */
84 struct usb_device* udev; /* save off the usb device pointer */ 85 struct usb_device* udev; /* save off the usb device pointer */
85 struct usb_interface* interface; 86 struct usb_interface* interface;
86 unsigned char minor; /* the starting minor number for this device */ 87 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 } 270 }
270 271
271 /* lock this device */ 272 /* lock this device */
272 if ((retval = down_interruptible(&dev->sem))) { 273 if ((retval = mutex_lock_interruptible(&dev->mtx))) {
273 dbg(2, "%s : sem down failed", __FUNCTION__); 274 dbg(2, "%s : mutex lock failed", __FUNCTION__);
274 goto exit_no_device; 275 goto exit_no_device;
275 } 276 }
276 277
@@ -299,7 +300,7 @@ static int adu_open(struct inode *inode, struct file *file)
299 if (retval) 300 if (retval)
300 --dev->open_count; 301 --dev->open_count;
301 } 302 }
302 up(&dev->sem); 303 mutex_unlock(&dev->mtx);
303 304
304exit_no_device: 305exit_no_device:
305 dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval); 306 dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval);
@@ -347,7 +348,7 @@ static int adu_release(struct inode *inode, struct file *file)
347 } 348 }
348 349
349 /* lock our device */ 350 /* lock our device */
350 down(&dev->sem); /* not interruptible */ 351 mutex_lock(&dev->mtx); /* not interruptible */
351 352
352 if (dev->open_count <= 0) { 353 if (dev->open_count <= 0) {
353 dbg(1," %s : device not opened", __FUNCTION__); 354 dbg(1," %s : device not opened", __FUNCTION__);
@@ -357,7 +358,7 @@ static int adu_release(struct inode *inode, struct file *file)
357 358
358 if (dev->udev == NULL) { 359 if (dev->udev == NULL) {
359 /* the device was unplugged before the file was released */ 360 /* the device was unplugged before the file was released */
360 up(&dev->sem); 361 mutex_unlock(&dev->mtx);
361 adu_delete(dev); 362 adu_delete(dev);
362 dev = NULL; 363 dev = NULL;
363 } else { 364 } else {
@@ -367,7 +368,7 @@ static int adu_release(struct inode *inode, struct file *file)
367 368
368exit: 369exit:
369 if (dev) 370 if (dev)
370 up(&dev->sem); 371 mutex_unlock(&dev->mtx);
371 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 372 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
372 return retval; 373 return retval;
373} 374}
@@ -390,7 +391,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
390 dev = file->private_data; 391 dev = file->private_data;
391 dbg(2," %s : dev=%p", __FUNCTION__, dev); 392 dbg(2," %s : dev=%p", __FUNCTION__, dev);
392 /* lock this object */ 393 /* lock this object */
393 if (down_interruptible(&dev->sem)) 394 if (mutex_lock_interruptible(&dev->mtx))
394 return -ERESTARTSYS; 395 return -ERESTARTSYS;
395 396
396 /* verify that the device wasn't unplugged */ 397 /* 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 523
523exit: 524exit:
524 /* unlock the device */ 525 /* unlock the device */
525 up(&dev->sem); 526 mutex_unlock(&dev->mtx);
526 527
527 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 528 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
528 return retval; 529 return retval;
@@ -543,7 +544,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
543 dev = file->private_data; 544 dev = file->private_data;
544 545
545 /* lock this object */ 546 /* lock this object */
546 retval = down_interruptible(&dev->sem); 547 retval = mutex_lock_interruptible(&dev->mtx);
547 if (retval) 548 if (retval)
548 goto exit_nolock; 549 goto exit_nolock;
549 550
@@ -571,9 +572,9 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
571 retval = -EINTR; 572 retval = -EINTR;
572 goto exit; 573 goto exit;
573 } 574 }
574 up(&dev->sem); 575 mutex_unlock(&dev->mtx);
575 timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); 576 timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout);
576 retval = down_interruptible(&dev->sem); 577 retval = mutex_lock_interruptible(&dev->mtx);
577 if (retval) { 578 if (retval) {
578 retval = bytes_written ? bytes_written : retval; 579 retval = bytes_written ? bytes_written : retval;
579 goto exit_nolock; 580 goto exit_nolock;
@@ -638,7 +639,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
638 639
639exit: 640exit:
640 /* unlock the device */ 641 /* unlock the device */
641 up(&dev->sem); 642 mutex_unlock(&dev->mtx);
642exit_nolock: 643exit_nolock:
643 644
644 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 645 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
@@ -698,7 +699,7 @@ static int adu_probe(struct usb_interface *interface,
698 goto exit; 699 goto exit;
699 } 700 }
700 701
701 init_MUTEX(&dev->sem); 702 mutex_init(&dev->mtx);
702 spin_lock_init(&dev->buflock); 703 spin_lock_init(&dev->buflock);
703 dev->udev = udev; 704 dev->udev = udev;
704 init_waitqueue_head(&dev->read_wait); 705 init_waitqueue_head(&dev->read_wait);
@@ -835,16 +836,16 @@ static void adu_disconnect(struct usb_interface *interface)
835 usb_deregister_dev(interface, &adu_class); 836 usb_deregister_dev(interface, &adu_class);
836 dev->minor = 0; 837 dev->minor = 0;
837 838
838 down(&dev->sem); /* not interruptible */ 839 mutex_lock(&dev->mtx); /* not interruptible */
839 840
840 /* if the device is not opened, then we clean up right now */ 841 /* if the device is not opened, then we clean up right now */
841 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); 842 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count);
842 if (!dev->open_count) { 843 if (!dev->open_count) {
843 up(&dev->sem); 844 mutex_unlock(&dev->mtx);
844 adu_delete(dev); 845 adu_delete(dev);
845 } else { 846 } else {
846 dev->udev = NULL; 847 dev->udev = NULL;
847 up(&dev->sem); 848 mutex_unlock(&dev->mtx);
848 } 849 }
849 850
850 dev_info(&interface->dev, "ADU device adutux%d now disconnected", 851 dev_info(&interface->dev, "ADU device adutux%d now disconnected",