aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/misc/adutux.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/misc/adutux.c')
-rw-r--r--drivers/usb/misc/adutux.c97
1 files changed, 58 insertions, 39 deletions
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index e8a9e16789f5..885f99322a84 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -147,10 +147,8 @@ static void adu_abort_transfers(struct adu_device *dev)
147{ 147{
148 unsigned long flags; 148 unsigned long flags;
149 149
150 if (dev->udev == NULL) { 150 if (dev->udev == NULL)
151 dbg(1, " %s : udev is null", __func__);
152 return; 151 return;
153 }
154 152
155 /* shutdown transfer */ 153 /* shutdown transfer */
156 154
@@ -195,8 +193,9 @@ static void adu_interrupt_in_callback(struct urb *urb)
195 if (status != 0) { 193 if (status != 0) {
196 if ((status != -ENOENT) && (status != -ECONNRESET) && 194 if ((status != -ENOENT) && (status != -ECONNRESET) &&
197 (status != -ESHUTDOWN)) { 195 (status != -ESHUTDOWN)) {
198 dbg(1, " %s : nonzero status received: %d", 196 dev_dbg(&dev->udev->dev,
199 __func__, status); 197 "%s : nonzero status received: %d\n",
198 __func__, status);
200 } 199 }
201 goto exit; 200 goto exit;
202 } 201 }
@@ -210,10 +209,11 @@ static void adu_interrupt_in_callback(struct urb *urb)
210 dev->interrupt_in_buffer, urb->actual_length); 209 dev->interrupt_in_buffer, urb->actual_length);
211 210
212 dev->read_buffer_length += urb->actual_length; 211 dev->read_buffer_length += urb->actual_length;
213 dbg(2, " %s reading %d ", __func__, 212 dev_dbg(&dev->udev->dev,"%s reading %d\n", __func__,
214 urb->actual_length); 213 urb->actual_length);
215 } else { 214 } else {
216 dbg(1, " %s : read_buffer overflow", __func__); 215 dev_dbg(&dev->udev->dev,"%s : read_buffer overflow\n",
216 __func__);
217 } 217 }
218 } 218 }
219 219
@@ -236,8 +236,9 @@ static void adu_interrupt_out_callback(struct urb *urb)
236 if (status != 0) { 236 if (status != 0) {
237 if ((status != -ENOENT) && 237 if ((status != -ENOENT) &&
238 (status != -ECONNRESET)) { 238 (status != -ECONNRESET)) {
239 dbg(1, " %s :nonzero status received: %d", 239 dev_dbg(&dev->udev->dev,
240 __func__, status); 240 "%s :nonzero status received: %d\n", __func__,
241 status);
241 } 242 }
242 goto exit; 243 goto exit;
243 } 244 }
@@ -262,10 +263,8 @@ static int adu_open(struct inode *inode, struct file *file)
262 subminor = iminor(inode); 263 subminor = iminor(inode);
263 264
264 retval = mutex_lock_interruptible(&adutux_mutex); 265 retval = mutex_lock_interruptible(&adutux_mutex);
265 if (retval) { 266 if (retval)
266 dbg(2, "%s : mutex lock failed", __func__);
267 goto exit_no_lock; 267 goto exit_no_lock;
268 }
269 268
270 interface = usb_find_interface(&adu_driver, subminor); 269 interface = usb_find_interface(&adu_driver, subminor);
271 if (!interface) { 270 if (!interface) {
@@ -288,7 +287,8 @@ static int adu_open(struct inode *inode, struct file *file)
288 } 287 }
289 288
290 ++dev->open_count; 289 ++dev->open_count;
291 dbg(2, "%s : open count %d", __func__, dev->open_count); 290 dev_dbg(&dev->udev->dev, "%s: open count %d\n", __func__,
291 dev->open_count);
292 292
293 /* save device in the file's private structure */ 293 /* save device in the file's private structure */
294 file->private_data = dev; 294 file->private_data = dev;
@@ -325,7 +325,8 @@ static void adu_release_internal(struct adu_device *dev)
325{ 325{
326 /* decrement our usage count for the device */ 326 /* decrement our usage count for the device */
327 --dev->open_count; 327 --dev->open_count;
328 dbg(2, " %s : open count %d", __func__, dev->open_count); 328 dev_dbg(&dev->udev->dev, "%s : open count %d\n", __func__,
329 dev->open_count);
329 if (dev->open_count <= 0) { 330 if (dev->open_count <= 0) {
330 adu_abort_transfers(dev); 331 adu_abort_transfers(dev);
331 dev->open_count = 0; 332 dev->open_count = 0;
@@ -338,14 +339,12 @@ static int adu_release(struct inode *inode, struct file *file)
338 int retval = 0; 339 int retval = 0;
339 340
340 if (file == NULL) { 341 if (file == NULL) {
341 dbg(1, " %s : file is NULL", __func__);
342 retval = -ENODEV; 342 retval = -ENODEV;
343 goto exit; 343 goto exit;
344 } 344 }
345 345
346 dev = file->private_data; 346 dev = file->private_data;
347 if (dev == NULL) { 347 if (dev == NULL) {
348 dbg(1, " %s : object is NULL", __func__);
349 retval = -ENODEV; 348 retval = -ENODEV;
350 goto exit; 349 goto exit;
351 } 350 }
@@ -353,7 +352,7 @@ static int adu_release(struct inode *inode, struct file *file)
353 mutex_lock(&adutux_mutex); /* not interruptible */ 352 mutex_lock(&adutux_mutex); /* not interruptible */
354 353
355 if (dev->open_count <= 0) { 354 if (dev->open_count <= 0) {
356 dbg(1, " %s : device not opened", __func__); 355 dev_dbg(&dev->udev->dev, "%s : device not opened\n", __func__);
357 retval = -ENODEV; 356 retval = -ENODEV;
358 goto unlock; 357 goto unlock;
359 } 358 }
@@ -397,17 +396,19 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
397 396
398 /* verify that some data was requested */ 397 /* verify that some data was requested */
399 if (count == 0) { 398 if (count == 0) {
400 dbg(1, " %s : read request of 0 bytes", __func__); 399 dev_dbg(&dev->udev->dev, "%s : read request of 0 bytes\n",
400 __func__);
401 goto exit; 401 goto exit;
402 } 402 }
403 403
404 timeout = COMMAND_TIMEOUT; 404 timeout = COMMAND_TIMEOUT;
405 dbg(2, " %s : about to start looping", __func__); 405 dev_dbg(&dev->udev->dev, "%s : about to start looping\n", __func__);
406 while (bytes_to_read) { 406 while (bytes_to_read) {
407 int data_in_secondary = dev->secondary_tail - dev->secondary_head; 407 int data_in_secondary = dev->secondary_tail - dev->secondary_head;
408 dbg(2, " %s : while, data_in_secondary=%d, status=%d", 408 dev_dbg(&dev->udev->dev,
409 __func__, data_in_secondary, 409 "%s : while, data_in_secondary=%d, status=%d\n",
410 dev->interrupt_in_urb->status); 410 __func__, data_in_secondary,
411 dev->interrupt_in_urb->status);
411 412
412 if (data_in_secondary) { 413 if (data_in_secondary) {
413 /* drain secondary buffer */ 414 /* drain secondary buffer */
@@ -430,8 +431,9 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
430 if (dev->read_buffer_length) { 431 if (dev->read_buffer_length) {
431 /* we secure access to the primary */ 432 /* we secure access to the primary */
432 char *tmp; 433 char *tmp;
433 dbg(2, " %s : swap, read_buffer_length = %d", 434 dev_dbg(&dev->udev->dev,
434 __func__, dev->read_buffer_length); 435 "%s : swap, read_buffer_length = %d\n",
436 __func__, dev->read_buffer_length);
435 tmp = dev->read_buffer_secondary; 437 tmp = dev->read_buffer_secondary;
436 dev->read_buffer_secondary = dev->read_buffer_primary; 438 dev->read_buffer_secondary = dev->read_buffer_primary;
437 dev->read_buffer_primary = tmp; 439 dev->read_buffer_primary = tmp;
@@ -446,10 +448,14 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
446 if (!dev->read_urb_finished) { 448 if (!dev->read_urb_finished) {
447 /* somebody is doing IO */ 449 /* somebody is doing IO */
448 spin_unlock_irqrestore(&dev->buflock, flags); 450 spin_unlock_irqrestore(&dev->buflock, flags);
449 dbg(2, " %s : submitted already", __func__); 451 dev_dbg(&dev->udev->dev,
452 "%s : submitted already\n",
453 __func__);
450 } else { 454 } else {
451 /* we must initiate input */ 455 /* we must initiate input */
452 dbg(2, " %s : initiate input", __func__); 456 dev_dbg(&dev->udev->dev,
457 "%s : initiate input\n",
458 __func__);
453 dev->read_urb_finished = 0; 459 dev->read_urb_finished = 0;
454 spin_unlock_irqrestore(&dev->buflock, flags); 460 spin_unlock_irqrestore(&dev->buflock, flags);
455 461
@@ -467,7 +473,9 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
467 if (retval == -ENOMEM) { 473 if (retval == -ENOMEM) {
468 retval = bytes_read ? bytes_read : -ENOMEM; 474 retval = bytes_read ? bytes_read : -ENOMEM;
469 } 475 }
470 dbg(2, " %s : submit failed", __func__); 476 dev_dbg(&dev->udev->dev,
477 "%s : submit failed\n",
478 __func__);
471 goto exit; 479 goto exit;
472 } 480 }
473 } 481 }
@@ -486,13 +494,16 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
486 remove_wait_queue(&dev->read_wait, &wait); 494 remove_wait_queue(&dev->read_wait, &wait);
487 495
488 if (timeout <= 0) { 496 if (timeout <= 0) {
489 dbg(2, " %s : timeout", __func__); 497 dev_dbg(&dev->udev->dev,
498 "%s : timeout\n", __func__);
490 retval = bytes_read ? bytes_read : -ETIMEDOUT; 499 retval = bytes_read ? bytes_read : -ETIMEDOUT;
491 goto exit; 500 goto exit;
492 } 501 }
493 502
494 if (signal_pending(current)) { 503 if (signal_pending(current)) {
495 dbg(2, " %s : signal pending", __func__); 504 dev_dbg(&dev->udev->dev,
505 "%s : signal pending\n",
506 __func__);
496 retval = bytes_read ? bytes_read : -EINTR; 507 retval = bytes_read ? bytes_read : -EINTR;
497 goto exit; 508 goto exit;
498 } 509 }
@@ -555,7 +566,8 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
555 566
556 /* verify that we actually have some data to write */ 567 /* verify that we actually have some data to write */
557 if (count == 0) { 568 if (count == 0) {
558 dbg(1, " %s : write request of 0 bytes", __func__); 569 dev_dbg(&dev->udev->dev, "%s : write request of 0 bytes\n",
570 __func__);
559 goto exit; 571 goto exit;
560 } 572 }
561 573
@@ -568,13 +580,15 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
568 580
569 mutex_unlock(&dev->mtx); 581 mutex_unlock(&dev->mtx);
570 if (signal_pending(current)) { 582 if (signal_pending(current)) {
571 dbg(1, " %s : interrupted", __func__); 583 dev_dbg(&dev->udev->dev, "%s : interrupted\n",
584 __func__);
572 set_current_state(TASK_RUNNING); 585 set_current_state(TASK_RUNNING);
573 retval = -EINTR; 586 retval = -EINTR;
574 goto exit_onqueue; 587 goto exit_onqueue;
575 } 588 }
576 if (schedule_timeout(COMMAND_TIMEOUT) == 0) { 589 if (schedule_timeout(COMMAND_TIMEOUT) == 0) {
577 dbg(1, "%s - command timed out.", __func__); 590 dev_dbg(&dev->udev->dev,
591 "%s - command timed out.\n", __func__);
578 retval = -ETIMEDOUT; 592 retval = -ETIMEDOUT;
579 goto exit_onqueue; 593 goto exit_onqueue;
580 } 594 }
@@ -585,18 +599,22 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
585 goto exit_nolock; 599 goto exit_nolock;
586 } 600 }
587 601
588 dbg(4, " %s : in progress, count = %Zd", __func__, count); 602 dev_dbg(&dev->udev->dev,
603 "%s : in progress, count = %Zd\n",
604 __func__, count);
589 } else { 605 } else {
590 spin_unlock_irqrestore(&dev->buflock, flags); 606 spin_unlock_irqrestore(&dev->buflock, flags);
591 set_current_state(TASK_RUNNING); 607 set_current_state(TASK_RUNNING);
592 remove_wait_queue(&dev->write_wait, &waita); 608 remove_wait_queue(&dev->write_wait, &waita);
593 dbg(4, " %s : sending, count = %Zd", __func__, count); 609 dev_dbg(&dev->udev->dev, "%s : sending, count = %Zd\n",
610 __func__, count);
594 611
595 /* write the data into interrupt_out_buffer from userspace */ 612 /* write the data into interrupt_out_buffer from userspace */
596 buffer_size = usb_endpoint_maxp(dev->interrupt_out_endpoint); 613 buffer_size = usb_endpoint_maxp(dev->interrupt_out_endpoint);
597 bytes_to_write = count > buffer_size ? buffer_size : count; 614 bytes_to_write = count > buffer_size ? buffer_size : count;
598 dbg(4, " %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd", 615 dev_dbg(&dev->udev->dev,
599 __func__, buffer_size, count, bytes_to_write); 616 "%s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd\n",
617 __func__, buffer_size, count, bytes_to_write);
600 618
601 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) { 619 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) {
602 retval = -EFAULT; 620 retval = -EFAULT;
@@ -779,7 +797,7 @@ static int adu_probe(struct usb_interface *interface,
779 dev_err(&interface->dev, "Could not retrieve serial number\n"); 797 dev_err(&interface->dev, "Could not retrieve serial number\n");
780 goto error; 798 goto error;
781 } 799 }
782 dbg(2, " %s : serial_number=%s", __func__, dev->serial_number); 800 dev_dbg(&interface->dev,"serial_number=%s", dev->serial_number);
783 801
784 /* we can register the device now, as it is ready */ 802 /* we can register the device now, as it is ready */
785 usb_set_intfdata(interface, dev); 803 usb_set_intfdata(interface, dev);
@@ -829,7 +847,8 @@ static void adu_disconnect(struct usb_interface *interface)
829 usb_set_intfdata(interface, NULL); 847 usb_set_intfdata(interface, NULL);
830 848
831 /* if the device is not opened, then we clean up right now */ 849 /* if the device is not opened, then we clean up right now */
832 dbg(2, " %s : open count %d", __func__, dev->open_count); 850 dev_dbg(&dev->udev->dev, "%s : open count %d\n",
851 __func__, dev->open_count);
833 if (!dev->open_count) 852 if (!dev->open_count)
834 adu_delete(dev); 853 adu_delete(dev);
835 854