diff options
Diffstat (limited to 'drivers/usb/misc/rio500.c')
-rw-r--r-- | drivers/usb/misc/rio500.c | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c index 384fa3769805..fdf68479a166 100644 --- a/drivers/usb/misc/rio500.c +++ b/drivers/usb/misc/rio500.c | |||
@@ -69,7 +69,7 @@ struct rio_usb_data { | |||
69 | char *obuf, *ibuf; /* transfer buffers */ | 69 | char *obuf, *ibuf; /* transfer buffers */ |
70 | char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */ | 70 | char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */ |
71 | wait_queue_head_t wait_q; /* for timeouts */ | 71 | wait_queue_head_t wait_q; /* for timeouts */ |
72 | struct semaphore lock; /* general race avoidance */ | 72 | struct mutex lock; /* general race avoidance */ |
73 | }; | 73 | }; |
74 | 74 | ||
75 | static struct rio_usb_data rio_instance; | 75 | static struct rio_usb_data rio_instance; |
@@ -78,17 +78,17 @@ static int open_rio(struct inode *inode, struct file *file) | |||
78 | { | 78 | { |
79 | struct rio_usb_data *rio = &rio_instance; | 79 | struct rio_usb_data *rio = &rio_instance; |
80 | 80 | ||
81 | down(&(rio->lock)); | 81 | mutex_lock(&(rio->lock)); |
82 | 82 | ||
83 | if (rio->isopen || !rio->present) { | 83 | if (rio->isopen || !rio->present) { |
84 | up(&(rio->lock)); | 84 | mutex_unlock(&(rio->lock)); |
85 | return -EBUSY; | 85 | return -EBUSY; |
86 | } | 86 | } |
87 | rio->isopen = 1; | 87 | rio->isopen = 1; |
88 | 88 | ||
89 | init_waitqueue_head(&rio->wait_q); | 89 | init_waitqueue_head(&rio->wait_q); |
90 | 90 | ||
91 | up(&(rio->lock)); | 91 | mutex_unlock(&(rio->lock)); |
92 | 92 | ||
93 | info("Rio opened."); | 93 | info("Rio opened."); |
94 | 94 | ||
@@ -117,7 +117,7 @@ ioctl_rio(struct inode *inode, struct file *file, unsigned int cmd, | |||
117 | int retries; | 117 | int retries; |
118 | int retval=0; | 118 | int retval=0; |
119 | 119 | ||
120 | down(&(rio->lock)); | 120 | mutex_lock(&(rio->lock)); |
121 | /* Sanity check to make sure rio is connected, powered, etc */ | 121 | /* Sanity check to make sure rio is connected, powered, etc */ |
122 | if ( rio == NULL || | 122 | if ( rio == NULL || |
123 | rio->present == 0 || | 123 | rio->present == 0 || |
@@ -257,7 +257,7 @@ ioctl_rio(struct inode *inode, struct file *file, unsigned int cmd, | |||
257 | 257 | ||
258 | 258 | ||
259 | err_out: | 259 | err_out: |
260 | up(&(rio->lock)); | 260 | mutex_unlock(&(rio->lock)); |
261 | return retval; | 261 | return retval; |
262 | } | 262 | } |
263 | 263 | ||
@@ -275,14 +275,17 @@ write_rio(struct file *file, const char __user *buffer, | |||
275 | int result = 0; | 275 | int result = 0; |
276 | int maxretry; | 276 | int maxretry; |
277 | int errn = 0; | 277 | int errn = 0; |
278 | int intr; | ||
278 | 279 | ||
279 | down(&(rio->lock)); | 280 | intr = mutex_lock_interruptible(&(rio->lock)); |
281 | if (intr) | ||
282 | return -EINTR; | ||
280 | /* Sanity check to make sure rio is connected, powered, etc */ | 283 | /* Sanity check to make sure rio is connected, powered, etc */ |
281 | if ( rio == NULL || | 284 | if ( rio == NULL || |
282 | rio->present == 0 || | 285 | rio->present == 0 || |
283 | rio->rio_dev == NULL ) | 286 | rio->rio_dev == NULL ) |
284 | { | 287 | { |
285 | up(&(rio->lock)); | 288 | mutex_unlock(&(rio->lock)); |
286 | return -ENODEV; | 289 | return -ENODEV; |
287 | } | 290 | } |
288 | 291 | ||
@@ -305,7 +308,7 @@ write_rio(struct file *file, const char __user *buffer, | |||
305 | goto error; | 308 | goto error; |
306 | } | 309 | } |
307 | if (signal_pending(current)) { | 310 | if (signal_pending(current)) { |
308 | up(&(rio->lock)); | 311 | mutex_unlock(&(rio->lock)); |
309 | return bytes_written ? bytes_written : -EINTR; | 312 | return bytes_written ? bytes_written : -EINTR; |
310 | } | 313 | } |
311 | 314 | ||
@@ -341,12 +344,12 @@ write_rio(struct file *file, const char __user *buffer, | |||
341 | buffer += copy_size; | 344 | buffer += copy_size; |
342 | } while (count > 0); | 345 | } while (count > 0); |
343 | 346 | ||
344 | up(&(rio->lock)); | 347 | mutex_unlock(&(rio->lock)); |
345 | 348 | ||
346 | return bytes_written ? bytes_written : -EIO; | 349 | return bytes_written ? bytes_written : -EIO; |
347 | 350 | ||
348 | error: | 351 | error: |
349 | up(&(rio->lock)); | 352 | mutex_unlock(&(rio->lock)); |
350 | return errn; | 353 | return errn; |
351 | } | 354 | } |
352 | 355 | ||
@@ -361,14 +364,17 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) | |||
361 | int result; | 364 | int result; |
362 | int maxretry = 10; | 365 | int maxretry = 10; |
363 | char *ibuf; | 366 | char *ibuf; |
367 | int intr; | ||
364 | 368 | ||
365 | down(&(rio->lock)); | 369 | intr = mutex_lock_interruptible(&(rio->lock)); |
370 | if (intr) | ||
371 | return -EINTR; | ||
366 | /* Sanity check to make sure rio is connected, powered, etc */ | 372 | /* Sanity check to make sure rio is connected, powered, etc */ |
367 | if ( rio == NULL || | 373 | if ( rio == NULL || |
368 | rio->present == 0 || | 374 | rio->present == 0 || |
369 | rio->rio_dev == NULL ) | 375 | rio->rio_dev == NULL ) |
370 | { | 376 | { |
371 | up(&(rio->lock)); | 377 | mutex_unlock(&(rio->lock)); |
372 | return -ENODEV; | 378 | return -ENODEV; |
373 | } | 379 | } |
374 | 380 | ||
@@ -379,11 +385,11 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) | |||
379 | 385 | ||
380 | while (count > 0) { | 386 | while (count > 0) { |
381 | if (signal_pending(current)) { | 387 | if (signal_pending(current)) { |
382 | up(&(rio->lock)); | 388 | mutex_unlock(&(rio->lock)); |
383 | return read_count ? read_count : -EINTR; | 389 | return read_count ? read_count : -EINTR; |
384 | } | 390 | } |
385 | if (!rio->rio_dev) { | 391 | if (!rio->rio_dev) { |
386 | up(&(rio->lock)); | 392 | mutex_unlock(&(rio->lock)); |
387 | return -ENODEV; | 393 | return -ENODEV; |
388 | } | 394 | } |
389 | this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count; | 395 | this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count; |
@@ -400,7 +406,7 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) | |||
400 | count = this_read = partial; | 406 | count = this_read = partial; |
401 | } else if (result == -ETIMEDOUT || result == 15) { /* FIXME: 15 ??? */ | 407 | } else if (result == -ETIMEDOUT || result == 15) { /* FIXME: 15 ??? */ |
402 | if (!maxretry--) { | 408 | if (!maxretry--) { |
403 | up(&(rio->lock)); | 409 | mutex_unlock(&(rio->lock)); |
404 | err("read_rio: maxretry timeout"); | 410 | err("read_rio: maxretry timeout"); |
405 | return -ETIME; | 411 | return -ETIME; |
406 | } | 412 | } |
@@ -409,18 +415,18 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) | |||
409 | finish_wait(&rio->wait_q, &wait); | 415 | finish_wait(&rio->wait_q, &wait); |
410 | continue; | 416 | continue; |
411 | } else if (result != -EREMOTEIO) { | 417 | } else if (result != -EREMOTEIO) { |
412 | up(&(rio->lock)); | 418 | mutex_unlock(&(rio->lock)); |
413 | err("Read Whoops - result:%u partial:%u this_read:%u", | 419 | err("Read Whoops - result:%u partial:%u this_read:%u", |
414 | result, partial, this_read); | 420 | result, partial, this_read); |
415 | return -EIO; | 421 | return -EIO; |
416 | } else { | 422 | } else { |
417 | up(&(rio->lock)); | 423 | mutex_unlock(&(rio->lock)); |
418 | return (0); | 424 | return (0); |
419 | } | 425 | } |
420 | 426 | ||
421 | if (this_read) { | 427 | if (this_read) { |
422 | if (copy_to_user(buffer, ibuf, this_read)) { | 428 | if (copy_to_user(buffer, ibuf, this_read)) { |
423 | up(&(rio->lock)); | 429 | mutex_unlock(&(rio->lock)); |
424 | return -EFAULT; | 430 | return -EFAULT; |
425 | } | 431 | } |
426 | count -= this_read; | 432 | count -= this_read; |
@@ -428,7 +434,7 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos) | |||
428 | buffer += this_read; | 434 | buffer += this_read; |
429 | } | 435 | } |
430 | } | 436 | } |
431 | up(&(rio->lock)); | 437 | mutex_unlock(&(rio->lock)); |
432 | return read_count; | 438 | return read_count; |
433 | } | 439 | } |
434 | 440 | ||
@@ -480,7 +486,7 @@ static int probe_rio(struct usb_interface *intf, | |||
480 | } | 486 | } |
481 | dbg("probe_rio: ibuf address:%p", rio->ibuf); | 487 | dbg("probe_rio: ibuf address:%p", rio->ibuf); |
482 | 488 | ||
483 | init_MUTEX(&(rio->lock)); | 489 | mutex_init(&(rio->lock)); |
484 | 490 | ||
485 | usb_set_intfdata (intf, rio); | 491 | usb_set_intfdata (intf, rio); |
486 | rio->present = 1; | 492 | rio->present = 1; |
@@ -496,12 +502,12 @@ static void disconnect_rio(struct usb_interface *intf) | |||
496 | if (rio) { | 502 | if (rio) { |
497 | usb_deregister_dev(intf, &usb_rio_class); | 503 | usb_deregister_dev(intf, &usb_rio_class); |
498 | 504 | ||
499 | down(&(rio->lock)); | 505 | mutex_lock(&(rio->lock)); |
500 | if (rio->isopen) { | 506 | if (rio->isopen) { |
501 | rio->isopen = 0; | 507 | rio->isopen = 0; |
502 | /* better let it finish - the release will do whats needed */ | 508 | /* better let it finish - the release will do whats needed */ |
503 | rio->rio_dev = NULL; | 509 | rio->rio_dev = NULL; |
504 | up(&(rio->lock)); | 510 | mutex_unlock(&(rio->lock)); |
505 | return; | 511 | return; |
506 | } | 512 | } |
507 | kfree(rio->ibuf); | 513 | kfree(rio->ibuf); |
@@ -510,7 +516,7 @@ static void disconnect_rio(struct usb_interface *intf) | |||
510 | info("USB Rio disconnected."); | 516 | info("USB Rio disconnected."); |
511 | 517 | ||
512 | rio->present = 0; | 518 | rio->present = 0; |
513 | up(&(rio->lock)); | 519 | mutex_unlock(&(rio->lock)); |
514 | } | 520 | } |
515 | } | 521 | } |
516 | 522 | ||