diff options
Diffstat (limited to 'drivers/usb/misc/adutux.c')
-rw-r--r-- | drivers/usb/misc/adutux.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c index d72c42e5f22d..e9fdbc8997b3 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 */ |
82 | struct adu_device { | 83 | struct 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 */ |
@@ -178,17 +179,18 @@ static void adu_delete(struct adu_device *dev) | |||
178 | static void adu_interrupt_in_callback(struct urb *urb) | 179 | static void adu_interrupt_in_callback(struct urb *urb) |
179 | { | 180 | { |
180 | struct adu_device *dev = urb->context; | 181 | struct adu_device *dev = urb->context; |
182 | int status = urb->status; | ||
181 | 183 | ||
182 | dbg(4," %s : enter, status %d", __FUNCTION__, urb->status); | 184 | dbg(4," %s : enter, status %d", __FUNCTION__, status); |
183 | adu_debug_data(5, __FUNCTION__, urb->actual_length, | 185 | adu_debug_data(5, __FUNCTION__, urb->actual_length, |
184 | urb->transfer_buffer); | 186 | urb->transfer_buffer); |
185 | 187 | ||
186 | spin_lock(&dev->buflock); | 188 | spin_lock(&dev->buflock); |
187 | 189 | ||
188 | if (urb->status != 0) { | 190 | if (status != 0) { |
189 | if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)) { | 191 | if ((status != -ENOENT) && (status != -ECONNRESET)) { |
190 | dbg(1," %s : nonzero status received: %d", | 192 | dbg(1," %s : nonzero status received: %d", |
191 | __FUNCTION__, urb->status); | 193 | __FUNCTION__, status); |
192 | } | 194 | } |
193 | goto exit; | 195 | goto exit; |
194 | } | 196 | } |
@@ -216,21 +218,22 @@ exit: | |||
216 | wake_up_interruptible(&dev->read_wait); | 218 | wake_up_interruptible(&dev->read_wait); |
217 | adu_debug_data(5, __FUNCTION__, urb->actual_length, | 219 | adu_debug_data(5, __FUNCTION__, urb->actual_length, |
218 | urb->transfer_buffer); | 220 | urb->transfer_buffer); |
219 | dbg(4," %s : leave, status %d", __FUNCTION__, urb->status); | 221 | dbg(4," %s : leave, status %d", __FUNCTION__, status); |
220 | } | 222 | } |
221 | 223 | ||
222 | static void adu_interrupt_out_callback(struct urb *urb) | 224 | static void adu_interrupt_out_callback(struct urb *urb) |
223 | { | 225 | { |
224 | struct adu_device *dev = urb->context; | 226 | struct adu_device *dev = urb->context; |
227 | int status = urb->status; | ||
225 | 228 | ||
226 | dbg(4," %s : enter, status %d", __FUNCTION__, urb->status); | 229 | dbg(4," %s : enter, status %d", __FUNCTION__, status); |
227 | adu_debug_data(5,__FUNCTION__, urb->actual_length, urb->transfer_buffer); | 230 | adu_debug_data(5,__FUNCTION__, urb->actual_length, urb->transfer_buffer); |
228 | 231 | ||
229 | if (urb->status != 0) { | 232 | if (status != 0) { |
230 | if ((urb->status != -ENOENT) && | 233 | if ((status != -ENOENT) && |
231 | (urb->status != -ECONNRESET)) { | 234 | (status != -ECONNRESET)) { |
232 | dbg(1, " %s :nonzero status received: %d", | 235 | dbg(1, " %s :nonzero status received: %d", |
233 | __FUNCTION__, urb->status); | 236 | __FUNCTION__, status); |
234 | } | 237 | } |
235 | goto exit; | 238 | goto exit; |
236 | } | 239 | } |
@@ -240,7 +243,7 @@ exit: | |||
240 | 243 | ||
241 | adu_debug_data(5, __FUNCTION__, urb->actual_length, | 244 | adu_debug_data(5, __FUNCTION__, urb->actual_length, |
242 | urb->transfer_buffer); | 245 | urb->transfer_buffer); |
243 | dbg(4," %s : leave, status %d", __FUNCTION__, urb->status); | 246 | dbg(4," %s : leave, status %d", __FUNCTION__, status); |
244 | } | 247 | } |
245 | 248 | ||
246 | static int adu_open(struct inode *inode, struct file *file) | 249 | static int adu_open(struct inode *inode, struct file *file) |
@@ -269,8 +272,8 @@ static int adu_open(struct inode *inode, struct file *file) | |||
269 | } | 272 | } |
270 | 273 | ||
271 | /* lock this device */ | 274 | /* lock this device */ |
272 | if ((retval = down_interruptible(&dev->sem))) { | 275 | if ((retval = mutex_lock_interruptible(&dev->mtx))) { |
273 | dbg(2, "%s : sem down failed", __FUNCTION__); | 276 | dbg(2, "%s : mutex lock failed", __FUNCTION__); |
274 | goto exit_no_device; | 277 | goto exit_no_device; |
275 | } | 278 | } |
276 | 279 | ||
@@ -299,7 +302,7 @@ static int adu_open(struct inode *inode, struct file *file) | |||
299 | if (retval) | 302 | if (retval) |
300 | --dev->open_count; | 303 | --dev->open_count; |
301 | } | 304 | } |
302 | up(&dev->sem); | 305 | mutex_unlock(&dev->mtx); |
303 | 306 | ||
304 | exit_no_device: | 307 | exit_no_device: |
305 | dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval); | 308 | dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval); |
@@ -347,7 +350,7 @@ static int adu_release(struct inode *inode, struct file *file) | |||
347 | } | 350 | } |
348 | 351 | ||
349 | /* lock our device */ | 352 | /* lock our device */ |
350 | down(&dev->sem); /* not interruptible */ | 353 | mutex_lock(&dev->mtx); /* not interruptible */ |
351 | 354 | ||
352 | if (dev->open_count <= 0) { | 355 | if (dev->open_count <= 0) { |
353 | dbg(1," %s : device not opened", __FUNCTION__); | 356 | dbg(1," %s : device not opened", __FUNCTION__); |
@@ -357,7 +360,7 @@ static int adu_release(struct inode *inode, struct file *file) | |||
357 | 360 | ||
358 | if (dev->udev == NULL) { | 361 | if (dev->udev == NULL) { |
359 | /* the device was unplugged before the file was released */ | 362 | /* the device was unplugged before the file was released */ |
360 | up(&dev->sem); | 363 | mutex_unlock(&dev->mtx); |
361 | adu_delete(dev); | 364 | adu_delete(dev); |
362 | dev = NULL; | 365 | dev = NULL; |
363 | } else { | 366 | } else { |
@@ -367,7 +370,7 @@ static int adu_release(struct inode *inode, struct file *file) | |||
367 | 370 | ||
368 | exit: | 371 | exit: |
369 | if (dev) | 372 | if (dev) |
370 | up(&dev->sem); | 373 | mutex_unlock(&dev->mtx); |
371 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); | 374 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); |
372 | return retval; | 375 | return retval; |
373 | } | 376 | } |
@@ -390,7 +393,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, | |||
390 | dev = file->private_data; | 393 | dev = file->private_data; |
391 | dbg(2," %s : dev=%p", __FUNCTION__, dev); | 394 | dbg(2," %s : dev=%p", __FUNCTION__, dev); |
392 | /* lock this object */ | 395 | /* lock this object */ |
393 | if (down_interruptible(&dev->sem)) | 396 | if (mutex_lock_interruptible(&dev->mtx)) |
394 | return -ERESTARTSYS; | 397 | return -ERESTARTSYS; |
395 | 398 | ||
396 | /* verify that the device wasn't unplugged */ | 399 | /* verify that the device wasn't unplugged */ |
@@ -522,7 +525,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, | |||
522 | 525 | ||
523 | exit: | 526 | exit: |
524 | /* unlock the device */ | 527 | /* unlock the device */ |
525 | up(&dev->sem); | 528 | mutex_unlock(&dev->mtx); |
526 | 529 | ||
527 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); | 530 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); |
528 | return retval; | 531 | return retval; |
@@ -543,7 +546,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
543 | dev = file->private_data; | 546 | dev = file->private_data; |
544 | 547 | ||
545 | /* lock this object */ | 548 | /* lock this object */ |
546 | retval = down_interruptible(&dev->sem); | 549 | retval = mutex_lock_interruptible(&dev->mtx); |
547 | if (retval) | 550 | if (retval) |
548 | goto exit_nolock; | 551 | goto exit_nolock; |
549 | 552 | ||
@@ -571,9 +574,9 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
571 | retval = -EINTR; | 574 | retval = -EINTR; |
572 | goto exit; | 575 | goto exit; |
573 | } | 576 | } |
574 | up(&dev->sem); | 577 | mutex_unlock(&dev->mtx); |
575 | timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); | 578 | timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); |
576 | retval = down_interruptible(&dev->sem); | 579 | retval = mutex_lock_interruptible(&dev->mtx); |
577 | if (retval) { | 580 | if (retval) { |
578 | retval = bytes_written ? bytes_written : retval; | 581 | retval = bytes_written ? bytes_written : retval; |
579 | goto exit_nolock; | 582 | goto exit_nolock; |
@@ -638,7 +641,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
638 | 641 | ||
639 | exit: | 642 | exit: |
640 | /* unlock the device */ | 643 | /* unlock the device */ |
641 | up(&dev->sem); | 644 | mutex_unlock(&dev->mtx); |
642 | exit_nolock: | 645 | exit_nolock: |
643 | 646 | ||
644 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); | 647 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); |
@@ -698,7 +701,7 @@ static int adu_probe(struct usb_interface *interface, | |||
698 | goto exit; | 701 | goto exit; |
699 | } | 702 | } |
700 | 703 | ||
701 | init_MUTEX(&dev->sem); | 704 | mutex_init(&dev->mtx); |
702 | spin_lock_init(&dev->buflock); | 705 | spin_lock_init(&dev->buflock); |
703 | dev->udev = udev; | 706 | dev->udev = udev; |
704 | init_waitqueue_head(&dev->read_wait); | 707 | init_waitqueue_head(&dev->read_wait); |
@@ -835,16 +838,16 @@ static void adu_disconnect(struct usb_interface *interface) | |||
835 | usb_deregister_dev(interface, &adu_class); | 838 | usb_deregister_dev(interface, &adu_class); |
836 | dev->minor = 0; | 839 | dev->minor = 0; |
837 | 840 | ||
838 | down(&dev->sem); /* not interruptible */ | 841 | mutex_lock(&dev->mtx); /* not interruptible */ |
839 | 842 | ||
840 | /* if the device is not opened, then we clean up right now */ | 843 | /* if the device is not opened, then we clean up right now */ |
841 | dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); | 844 | dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); |
842 | if (!dev->open_count) { | 845 | if (!dev->open_count) { |
843 | up(&dev->sem); | 846 | mutex_unlock(&dev->mtx); |
844 | adu_delete(dev); | 847 | adu_delete(dev); |
845 | } else { | 848 | } else { |
846 | dev->udev = NULL; | 849 | dev->udev = NULL; |
847 | up(&dev->sem); | 850 | mutex_unlock(&dev->mtx); |
848 | } | 851 | } |
849 | 852 | ||
850 | dev_info(&interface->dev, "ADU device adutux%d now disconnected", | 853 | dev_info(&interface->dev, "ADU device adutux%d now disconnected", |