diff options
author | matthias@kaehlcke.net <matthias@kaehlcke.net> | 2008-02-18 14:45:34 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-04-25 00:16:38 -0400 |
commit | b994d7f70ae59b874843fa2bc9a28b17b41febd5 (patch) | |
tree | bf23d30cac1f1494db3d006b28929abece8cb8b8 /drivers/usb/misc | |
parent | 92983c2121fb46f234add1c36b5e596779899d56 (diff) |
USB: auerswald: Convert stats_sem in a mutex
The semaphore cp->mutex is used as mutex, convert it to the mutex API
Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net>
Cc: Wolfgang Mües <wolfgang@iksw-muees.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/misc')
-rw-r--r-- | drivers/usb/misc/auerswald.c | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c index df7e1ecc810a..498fd4789921 100644 --- a/drivers/usb/misc/auerswald.c +++ b/drivers/usb/misc/auerswald.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/init.h> | 31 | #include <linux/init.h> |
32 | #include <linux/wait.h> | 32 | #include <linux/wait.h> |
33 | #include <linux/usb.h> | 33 | #include <linux/usb.h> |
34 | #include <linux/mutex.h> | ||
34 | 35 | ||
35 | /*-------------------------------------------------------------------*/ | 36 | /*-------------------------------------------------------------------*/ |
36 | /* Debug support */ | 37 | /* Debug support */ |
@@ -232,7 +233,7 @@ typedef struct auerscon | |||
232 | /* USB device context */ | 233 | /* USB device context */ |
233 | typedef struct | 234 | typedef struct |
234 | { | 235 | { |
235 | struct semaphore mutex; /* protection in user context */ | 236 | struct mutex mutex; /* protection in user context */ |
236 | char name[20]; /* name of the /dev/usb entry */ | 237 | char name[20]; /* name of the /dev/usb entry */ |
237 | unsigned int dtindex; /* index in the device table */ | 238 | unsigned int dtindex; /* index in the device table */ |
238 | struct usb_device * usbdev; /* USB device handle */ | 239 | struct usb_device * usbdev; /* USB device handle */ |
@@ -1376,7 +1377,7 @@ static int auerchar_open (struct inode *inode, struct file *file) | |||
1376 | if (cp == NULL) { | 1377 | if (cp == NULL) { |
1377 | return -ENODEV; | 1378 | return -ENODEV; |
1378 | } | 1379 | } |
1379 | if (down_interruptible (&cp->mutex)) { | 1380 | if (mutex_lock_interruptible(&cp->mutex)) { |
1380 | return -ERESTARTSYS; | 1381 | return -ERESTARTSYS; |
1381 | } | 1382 | } |
1382 | 1383 | ||
@@ -1405,7 +1406,7 @@ static int auerchar_open (struct inode *inode, struct file *file) | |||
1405 | cp->open_count++; | 1406 | cp->open_count++; |
1406 | ccp->auerdev = cp; | 1407 | ccp->auerdev = cp; |
1407 | dbg("open %s as /dev/%s", cp->dev_desc, cp->name); | 1408 | dbg("open %s as /dev/%s", cp->dev_desc, cp->name); |
1408 | up (&cp->mutex); | 1409 | mutex_unlock(&cp->mutex); |
1409 | 1410 | ||
1410 | /* file IO stuff */ | 1411 | /* file IO stuff */ |
1411 | file->f_pos = 0; | 1412 | file->f_pos = 0; |
@@ -1413,7 +1414,7 @@ static int auerchar_open (struct inode *inode, struct file *file) | |||
1413 | return nonseekable_open(inode, file); | 1414 | return nonseekable_open(inode, file); |
1414 | 1415 | ||
1415 | /* Error exit */ | 1416 | /* Error exit */ |
1416 | ofail: up (&cp->mutex); | 1417 | ofail: mutex_unlock(&cp->mutex); |
1417 | auerchar_delete (ccp); | 1418 | auerchar_delete (ccp); |
1418 | return ret; | 1419 | return ret; |
1419 | } | 1420 | } |
@@ -1440,14 +1441,14 @@ static int auerchar_ioctl (struct inode *inode, struct file *file, unsigned int | |||
1440 | up (&ccp->mutex); | 1441 | up (&ccp->mutex); |
1441 | return -ENODEV; | 1442 | return -ENODEV; |
1442 | } | 1443 | } |
1443 | if (down_interruptible (&cp->mutex)) { | 1444 | if (mutex_lock_interruptible(&cp->mutex)) { |
1444 | up(&ccp->mutex); | 1445 | up(&ccp->mutex); |
1445 | return -ERESTARTSYS; | 1446 | return -ERESTARTSYS; |
1446 | } | 1447 | } |
1447 | 1448 | ||
1448 | /* Check for removal */ | 1449 | /* Check for removal */ |
1449 | if (!cp->usbdev) { | 1450 | if (!cp->usbdev) { |
1450 | up(&cp->mutex); | 1451 | mutex_unlock(&cp->mutex); |
1451 | up(&ccp->mutex); | 1452 | up(&ccp->mutex); |
1452 | return -ENODEV; | 1453 | return -ENODEV; |
1453 | } | 1454 | } |
@@ -1550,7 +1551,7 @@ static int auerchar_ioctl (struct inode *inode, struct file *file, unsigned int | |||
1550 | break; | 1551 | break; |
1551 | } | 1552 | } |
1552 | /* release the mutexes */ | 1553 | /* release the mutexes */ |
1553 | up(&cp->mutex); | 1554 | mutex_unlock(&cp->mutex); |
1554 | up(&ccp->mutex); | 1555 | up(&ccp->mutex); |
1555 | return ret; | 1556 | return ret; |
1556 | } | 1557 | } |
@@ -1721,12 +1722,12 @@ write_again: | |||
1721 | up (&ccp->mutex); | 1722 | up (&ccp->mutex); |
1722 | return -ERESTARTSYS; | 1723 | return -ERESTARTSYS; |
1723 | } | 1724 | } |
1724 | if (down_interruptible (&cp->mutex)) { | 1725 | if (mutex_lock_interruptible(&cp->mutex)) { |
1725 | up (&ccp->mutex); | 1726 | up (&ccp->mutex); |
1726 | return -ERESTARTSYS; | 1727 | return -ERESTARTSYS; |
1727 | } | 1728 | } |
1728 | if (!cp->usbdev) { | 1729 | if (!cp->usbdev) { |
1729 | up (&cp->mutex); | 1730 | mutex_unlock(&cp->mutex); |
1730 | up (&ccp->mutex); | 1731 | up (&ccp->mutex); |
1731 | return -EIO; | 1732 | return -EIO; |
1732 | } | 1733 | } |
@@ -1750,7 +1751,7 @@ write_again: | |||
1750 | 1751 | ||
1751 | /* are there any buffers left? */ | 1752 | /* are there any buffers left? */ |
1752 | if (!bp) { | 1753 | if (!bp) { |
1753 | up (&cp->mutex); | 1754 | mutex_unlock(&cp->mutex); |
1754 | up (&ccp->mutex); | 1755 | up (&ccp->mutex); |
1755 | 1756 | ||
1756 | /* NONBLOCK: don't wait */ | 1757 | /* NONBLOCK: don't wait */ |
@@ -1783,7 +1784,7 @@ write_again: | |||
1783 | auerbuf_releasebuf (bp); | 1784 | auerbuf_releasebuf (bp); |
1784 | /* Wake up all processes waiting for a buffer */ | 1785 | /* Wake up all processes waiting for a buffer */ |
1785 | wake_up (&cp->bufferwait); | 1786 | wake_up (&cp->bufferwait); |
1786 | up (&cp->mutex); | 1787 | mutex_unlock(&cp->mutex); |
1787 | up (&ccp->mutex); | 1788 | up (&ccp->mutex); |
1788 | return -EFAULT; | 1789 | return -EFAULT; |
1789 | } | 1790 | } |
@@ -1803,7 +1804,7 @@ write_again: | |||
1803 | auerchar_ctrlwrite_complete, bp); | 1804 | auerchar_ctrlwrite_complete, bp); |
1804 | /* up we go */ | 1805 | /* up we go */ |
1805 | ret = auerchain_submit_urb (&cp->controlchain, bp->urbp); | 1806 | ret = auerchain_submit_urb (&cp->controlchain, bp->urbp); |
1806 | up (&cp->mutex); | 1807 | mutex_unlock(&cp->mutex); |
1807 | if (ret) { | 1808 | if (ret) { |
1808 | dbg ("auerchar_write: nonzero result of auerchain_submit_urb %d", ret); | 1809 | dbg ("auerchar_write: nonzero result of auerchain_submit_urb %d", ret); |
1809 | auerbuf_releasebuf (bp); | 1810 | auerbuf_releasebuf (bp); |
@@ -1830,16 +1831,16 @@ static int auerchar_release (struct inode *inode, struct file *file) | |||
1830 | down(&ccp->mutex); | 1831 | down(&ccp->mutex); |
1831 | cp = ccp->auerdev; | 1832 | cp = ccp->auerdev; |
1832 | if (cp) { | 1833 | if (cp) { |
1833 | down(&cp->mutex); | 1834 | mutex_lock(&cp->mutex); |
1834 | /* remove an open service */ | 1835 | /* remove an open service */ |
1835 | auerswald_removeservice (cp, &ccp->scontext); | 1836 | auerswald_removeservice (cp, &ccp->scontext); |
1836 | /* detach from device */ | 1837 | /* detach from device */ |
1837 | if ((--cp->open_count <= 0) && (cp->usbdev == NULL)) { | 1838 | if ((--cp->open_count <= 0) && (cp->usbdev == NULL)) { |
1838 | /* usb device waits for removal */ | 1839 | /* usb device waits for removal */ |
1839 | up (&cp->mutex); | 1840 | mutex_unlock(&cp->mutex); |
1840 | auerswald_delete (cp); | 1841 | auerswald_delete (cp); |
1841 | } else { | 1842 | } else { |
1842 | up (&cp->mutex); | 1843 | mutex_unlock(&cp->mutex); |
1843 | } | 1844 | } |
1844 | cp = NULL; | 1845 | cp = NULL; |
1845 | ccp->auerdev = NULL; | 1846 | ccp->auerdev = NULL; |
@@ -1917,7 +1918,7 @@ static int auerswald_probe (struct usb_interface *intf, | |||
1917 | } | 1918 | } |
1918 | 1919 | ||
1919 | /* Initialize device descriptor */ | 1920 | /* Initialize device descriptor */ |
1920 | init_MUTEX (&cp->mutex); | 1921 | mutex_init(&cp->mutex); |
1921 | cp->usbdev = usbdev; | 1922 | cp->usbdev = usbdev; |
1922 | auerchain_init (&cp->controlchain); | 1923 | auerchain_init (&cp->controlchain); |
1923 | auerbuf_init (&cp->bufctl); | 1924 | auerbuf_init (&cp->bufctl); |
@@ -2042,7 +2043,7 @@ static void auerswald_disconnect (struct usb_interface *intf) | |||
2042 | /* give back our USB minor number */ | 2043 | /* give back our USB minor number */ |
2043 | usb_deregister_dev(intf, &auerswald_class); | 2044 | usb_deregister_dev(intf, &auerswald_class); |
2044 | 2045 | ||
2045 | down (&cp->mutex); | 2046 | mutex_lock(&cp->mutex); |
2046 | info ("device /dev/%s now disconnecting", cp->name); | 2047 | info ("device /dev/%s now disconnecting", cp->name); |
2047 | 2048 | ||
2048 | /* Stop the interrupt endpoint */ | 2049 | /* Stop the interrupt endpoint */ |
@@ -2057,16 +2058,18 @@ static void auerswald_disconnect (struct usb_interface *intf) | |||
2057 | 2058 | ||
2058 | if (cp->open_count == 0) { | 2059 | if (cp->open_count == 0) { |
2059 | /* nobody is using this device. So we can clean up now */ | 2060 | /* nobody is using this device. So we can clean up now */ |
2060 | up (&cp->mutex);/* up() is possible here because no other task | 2061 | mutex_unlock(&cp->mutex); |
2061 | can open the device (see above). I don't want | 2062 | /* mutex_unlock() is possible here because no other task |
2062 | to kfree() a locked mutex. */ | 2063 | can open the device (see above). I don't want |
2064 | to kfree() a locked mutex. */ | ||
2065 | |||
2063 | auerswald_delete (cp); | 2066 | auerswald_delete (cp); |
2064 | } else { | 2067 | } else { |
2065 | /* device is used. Remove the pointer to the | 2068 | /* device is used. Remove the pointer to the |
2066 | usb device (it's not valid any more). The last | 2069 | usb device (it's not valid any more). The last |
2067 | release() will do the clean up */ | 2070 | release() will do the clean up */ |
2068 | cp->usbdev = NULL; | 2071 | cp->usbdev = NULL; |
2069 | up (&cp->mutex); | 2072 | mutex_unlock(&cp->mutex); |
2070 | /* Terminate waiting writers */ | 2073 | /* Terminate waiting writers */ |
2071 | wake_up (&cp->bufferwait); | 2074 | wake_up (&cp->bufferwait); |
2072 | /* Inform all waiting readers */ | 2075 | /* Inform all waiting readers */ |