aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/misc/sisusbvga/sisusb.c
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@infradead.org>2006-03-28 04:00:21 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-06-21 18:04:08 -0400
commit2682d27c5884550857cd96231db5b22b3acced53 (patch)
tree94b19f6a04993352d8ce3f189366d9cd4969fb58 /drivers/usb/misc/sisusbvga/sisusb.c
parent7327413c745c2f8e8d4b92f76759821263b095c1 (diff)
[PATCH] USB: convert the semaphores in the sisusb driver to mutexes
From: Arjan van de Ven <arjan@infradead.org> Convert the semaphores-used-as-mutex to mutexes in the sisusb video driver; this required manual checking due to the "return as locked" stuff in this driver, but the ->lock semaphore is still used as mutex in the end. Signed-off-by: Arjan van de Ven <arjan@infradead.org> Cc: Thomas Winischhofer <winischhofer.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/misc/sisusbvga/sisusb.c')
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c77
1 files changed, 39 insertions, 38 deletions
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 196c8794a73c..19aedbc85ea4 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -37,6 +37,7 @@
37 */ 37 */
38 38
39#include <linux/config.h> 39#include <linux/config.h>
40#include <linux/mutex.h>
40#include <linux/module.h> 41#include <linux/module.h>
41#include <linux/kernel.h> 42#include <linux/kernel.h>
42#include <linux/signal.h> 43#include <linux/signal.h>
@@ -102,7 +103,7 @@ MODULE_PARM_DESC(last, "Number of last console to take over (1 - MAX_NR_CONSOLES
102 103
103static struct usb_driver sisusb_driver; 104static struct usb_driver sisusb_driver;
104 105
105DECLARE_MUTEX(disconnect_sem); 106DEFINE_MUTEX(disconnect_mutex);
106 107
107static void 108static void
108sisusb_free_buffers(struct sisusb_usb_data *sisusb) 109sisusb_free_buffers(struct sisusb_usb_data *sisusb)
@@ -2552,39 +2553,39 @@ sisusb_open(struct inode *inode, struct file *file)
2552 struct usb_interface *interface; 2553 struct usb_interface *interface;
2553 int subminor = iminor(inode); 2554 int subminor = iminor(inode);
2554 2555
2555 down(&disconnect_sem); 2556 mutex_lock(&disconnect_mutex);
2556 2557
2557 if (!(interface = usb_find_interface(&sisusb_driver, subminor))) { 2558 if (!(interface = usb_find_interface(&sisusb_driver, subminor))) {
2558 printk(KERN_ERR "sisusb[%d]: Failed to find interface\n", 2559 printk(KERN_ERR "sisusb[%d]: Failed to find interface\n",
2559 subminor); 2560 subminor);
2560 up(&disconnect_sem); 2561 mutex_unlock(&disconnect_mutex);
2561 return -ENODEV; 2562 return -ENODEV;
2562 } 2563 }
2563 2564
2564 if (!(sisusb = usb_get_intfdata(interface))) { 2565 if (!(sisusb = usb_get_intfdata(interface))) {
2565 up(&disconnect_sem); 2566 mutex_unlock(&disconnect_mutex);
2566 return -ENODEV; 2567 return -ENODEV;
2567 } 2568 }
2568 2569
2569 down(&sisusb->lock); 2570 mutex_lock(&sisusb->lock);
2570 2571
2571 if (!sisusb->present || !sisusb->ready) { 2572 if (!sisusb->present || !sisusb->ready) {
2572 up(&sisusb->lock); 2573 mutex_unlock(&sisusb->lock);
2573 up(&disconnect_sem); 2574 mutex_unlock(&disconnect_mutex);
2574 return -ENODEV; 2575 return -ENODEV;
2575 } 2576 }
2576 2577
2577 if (sisusb->isopen) { 2578 if (sisusb->isopen) {
2578 up(&sisusb->lock); 2579 mutex_unlock(&sisusb->lock);
2579 up(&disconnect_sem); 2580 mutex_unlock(&disconnect_mutex);
2580 return -EBUSY; 2581 return -EBUSY;
2581 } 2582 }
2582 2583
2583 if (!sisusb->devinit) { 2584 if (!sisusb->devinit) {
2584 if (sisusb->sisusb_dev->speed == USB_SPEED_HIGH) { 2585 if (sisusb->sisusb_dev->speed == USB_SPEED_HIGH) {
2585 if (sisusb_init_gfxdevice(sisusb, 0)) { 2586 if (sisusb_init_gfxdevice(sisusb, 0)) {
2586 up(&sisusb->lock); 2587 mutex_unlock(&sisusb->lock);
2587 up(&disconnect_sem); 2588 mutex_unlock(&disconnect_mutex);
2588 printk(KERN_ERR 2589 printk(KERN_ERR
2589 "sisusbvga[%d]: Failed to initialize " 2590 "sisusbvga[%d]: Failed to initialize "
2590 "device\n", 2591 "device\n",
@@ -2592,8 +2593,8 @@ sisusb_open(struct inode *inode, struct file *file)
2592 return -EIO; 2593 return -EIO;
2593 } 2594 }
2594 } else { 2595 } else {
2595 up(&sisusb->lock); 2596 mutex_unlock(&sisusb->lock);
2596 up(&disconnect_sem); 2597 mutex_unlock(&disconnect_mutex);
2597 printk(KERN_ERR 2598 printk(KERN_ERR
2598 "sisusbvga[%d]: Device not attached to " 2599 "sisusbvga[%d]: Device not attached to "
2599 "USB 2.0 hub\n", 2600 "USB 2.0 hub\n",
@@ -2609,9 +2610,9 @@ sisusb_open(struct inode *inode, struct file *file)
2609 2610
2610 file->private_data = sisusb; 2611 file->private_data = sisusb;
2611 2612
2612 up(&sisusb->lock); 2613 mutex_unlock(&sisusb->lock);
2613 2614
2614 up(&disconnect_sem); 2615 mutex_unlock(&disconnect_mutex);
2615 2616
2616 return 0; 2617 return 0;
2617} 2618}
@@ -2642,14 +2643,14 @@ sisusb_release(struct inode *inode, struct file *file)
2642 struct sisusb_usb_data *sisusb; 2643 struct sisusb_usb_data *sisusb;
2643 int myminor; 2644 int myminor;
2644 2645
2645 down(&disconnect_sem); 2646 mutex_lock(&disconnect_mutex);
2646 2647
2647 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) { 2648 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) {
2648 up(&disconnect_sem); 2649 mutex_unlock(&disconnect_mutex);
2649 return -ENODEV; 2650 return -ENODEV;
2650 } 2651 }
2651 2652
2652 down(&sisusb->lock); 2653 mutex_lock(&sisusb->lock);
2653 2654
2654 if (sisusb->present) { 2655 if (sisusb->present) {
2655 /* Wait for all URBs to finish if device still present */ 2656 /* Wait for all URBs to finish if device still present */
@@ -2662,12 +2663,12 @@ sisusb_release(struct inode *inode, struct file *file)
2662 sisusb->isopen = 0; 2663 sisusb->isopen = 0;
2663 file->private_data = NULL; 2664 file->private_data = NULL;
2664 2665
2665 up(&sisusb->lock); 2666 mutex_unlock(&sisusb->lock);
2666 2667
2667 /* decrement the usage count on our device */ 2668 /* decrement the usage count on our device */
2668 kref_put(&sisusb->kref, sisusb_delete); 2669 kref_put(&sisusb->kref, sisusb_delete);
2669 2670
2670 up(&disconnect_sem); 2671 mutex_unlock(&disconnect_mutex);
2671 2672
2672 return 0; 2673 return 0;
2673} 2674}
@@ -2685,11 +2686,11 @@ sisusb_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2685 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2686 if (!(sisusb = (struct sisusb_usb_data *)file->private_data))
2686 return -ENODEV; 2687 return -ENODEV;
2687 2688
2688 down(&sisusb->lock); 2689 mutex_lock(&sisusb->lock);
2689 2690
2690 /* Sanity check */ 2691 /* Sanity check */
2691 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev) { 2692 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev) {
2692 up(&sisusb->lock); 2693 mutex_unlock(&sisusb->lock);
2693 return -ENODEV; 2694 return -ENODEV;
2694 } 2695 }
2695 2696
@@ -2784,7 +2785,7 @@ sisusb_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2784 (*ppos) <= SISUSB_PCI_PSEUDO_PCIBASE + 0x5c) { 2785 (*ppos) <= SISUSB_PCI_PSEUDO_PCIBASE + 0x5c) {
2785 2786
2786 if (count != 4) { 2787 if (count != 4) {
2787 up(&sisusb->lock); 2788 mutex_unlock(&sisusb->lock);
2788 return -EINVAL; 2789 return -EINVAL;
2789 } 2790 }
2790 2791
@@ -2808,7 +2809,7 @@ sisusb_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2808 2809
2809 (*ppos) += bytes_read; 2810 (*ppos) += bytes_read;
2810 2811
2811 up(&sisusb->lock); 2812 mutex_unlock(&sisusb->lock);
2812 2813
2813 return errno ? errno : bytes_read; 2814 return errno ? errno : bytes_read;
2814} 2815}
@@ -2827,11 +2828,11 @@ sisusb_write(struct file *file, const char __user *buffer, size_t count,
2827 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2828 if (!(sisusb = (struct sisusb_usb_data *)file->private_data))
2828 return -ENODEV; 2829 return -ENODEV;
2829 2830
2830 down(&sisusb->lock); 2831 mutex_lock(&sisusb->lock);
2831 2832
2832 /* Sanity check */ 2833 /* Sanity check */
2833 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev) { 2834 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev) {
2834 up(&sisusb->lock); 2835 mutex_unlock(&sisusb->lock);
2835 return -ENODEV; 2836 return -ENODEV;
2836 } 2837 }
2837 2838
@@ -2930,7 +2931,7 @@ sisusb_write(struct file *file, const char __user *buffer, size_t count,
2930 (*ppos) <= SISUSB_PCI_PSEUDO_PCIBASE + SISUSB_PCI_PCONFSIZE) { 2931 (*ppos) <= SISUSB_PCI_PSEUDO_PCIBASE + SISUSB_PCI_PCONFSIZE) {
2931 2932
2932 if (count != 4) { 2933 if (count != 4) {
2933 up(&sisusb->lock); 2934 mutex_unlock(&sisusb->lock);
2934 return -EINVAL; 2935 return -EINVAL;
2935 } 2936 }
2936 2937
@@ -2956,7 +2957,7 @@ sisusb_write(struct file *file, const char __user *buffer, size_t count,
2956 2957
2957 (*ppos) += bytes_written; 2958 (*ppos) += bytes_written;
2958 2959
2959 up(&sisusb->lock); 2960 mutex_unlock(&sisusb->lock);
2960 2961
2961 return errno ? errno : bytes_written; 2962 return errno ? errno : bytes_written;
2962} 2963}
@@ -2970,11 +2971,11 @@ sisusb_lseek(struct file *file, loff_t offset, int orig)
2970 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2971 if (!(sisusb = (struct sisusb_usb_data *)file->private_data))
2971 return -ENODEV; 2972 return -ENODEV;
2972 2973
2973 down(&sisusb->lock); 2974 mutex_lock(&sisusb->lock);
2974 2975
2975 /* Sanity check */ 2976 /* Sanity check */
2976 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev) { 2977 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev) {
2977 up(&sisusb->lock); 2978 mutex_unlock(&sisusb->lock);
2978 return -ENODEV; 2979 return -ENODEV;
2979 } 2980 }
2980 2981
@@ -2994,7 +2995,7 @@ sisusb_lseek(struct file *file, loff_t offset, int orig)
2994 ret = -EINVAL; 2995 ret = -EINVAL;
2995 } 2996 }
2996 2997
2997 up(&sisusb->lock); 2998 mutex_unlock(&sisusb->lock);
2998 return ret; 2999 return ret;
2999} 3000}
3000 3001
@@ -3136,7 +3137,7 @@ sisusb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
3136 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 3137 if (!(sisusb = (struct sisusb_usb_data *)file->private_data))
3137 return -ENODEV; 3138 return -ENODEV;
3138 3139
3139 down(&sisusb->lock); 3140 mutex_lock(&sisusb->lock);
3140 3141
3141 /* Sanity check */ 3142 /* Sanity check */
3142 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev) { 3143 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev) {
@@ -3193,7 +3194,7 @@ sisusb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
3193 } 3194 }
3194 3195
3195err_out: 3196err_out:
3196 up(&sisusb->lock); 3197 mutex_unlock(&sisusb->lock);
3197 return retval; 3198 return retval;
3198} 3199}
3199 3200
@@ -3258,7 +3259,7 @@ static int sisusb_probe(struct usb_interface *intf,
3258 } 3259 }
3259 kref_init(&sisusb->kref); 3260 kref_init(&sisusb->kref);
3260 3261
3261 init_MUTEX(&(sisusb->lock)); 3262 mutex_init(&(sisusb->lock));
3262 3263
3263 /* Register device */ 3264 /* Register device */
3264 if ((retval = usb_register_dev(intf, &usb_sisusb_class))) { 3265 if ((retval = usb_register_dev(intf, &usb_sisusb_class))) {
@@ -3429,9 +3430,9 @@ static void sisusb_disconnect(struct usb_interface *intf)
3429 * protect all other routines from the disconnect 3430 * protect all other routines from the disconnect
3430 * case, not the other way round. 3431 * case, not the other way round.
3431 */ 3432 */
3432 down(&disconnect_sem); 3433 mutex_lock(&disconnect_mutex);
3433 3434
3434 down(&sisusb->lock); 3435 mutex_lock(&sisusb->lock);
3435 3436
3436 /* Wait for all URBs to complete and kill them in case (MUST do) */ 3437 /* Wait for all URBs to complete and kill them in case (MUST do) */
3437 if (!sisusb_wait_all_out_complete(sisusb)) 3438 if (!sisusb_wait_all_out_complete(sisusb))
@@ -3462,12 +3463,12 @@ static void sisusb_disconnect(struct usb_interface *intf)
3462 sisusb->present = 0; 3463 sisusb->present = 0;
3463 sisusb->ready = 0; 3464 sisusb->ready = 0;
3464 3465
3465 up(&sisusb->lock); 3466 mutex_unlock(&sisusb->lock);
3466 3467
3467 /* decrement our usage count */ 3468 /* decrement our usage count */
3468 kref_put(&sisusb->kref, sisusb_delete); 3469 kref_put(&sisusb->kref, sisusb_delete);
3469 3470
3470 up(&disconnect_sem); 3471 mutex_unlock(&disconnect_mutex);
3471 3472
3472 printk(KERN_INFO "sisusbvga[%d]: Disconnected\n", minor); 3473 printk(KERN_INFO "sisusbvga[%d]: Disconnected\n", minor);
3473} 3474}