Index: usb-devel/drivers/usb/misc/yurex.c =================================================================== --- usb-devel.orig/drivers/usb/misc/yurex.c +++ usb-devel/drivers/usb/misc/yurex.c @@ -62,6 +62,7 @@ struct usb_yurex { struct mutex io_mutex; struct fasync_struct *async_queue; wait_queue_head_t waitq; + int command_finished; spinlock_t lock; __s64 bbu; /* BBU from device */ @@ -80,6 +81,7 @@ static void yurex_control_callback(struc if (status) { dev_err(&urb->dev->dev, "%s - control failed: %d\n", __func__, status); + dev->command_finished = 1; wake_up_interruptible(&dev->waitq); return; } @@ -173,6 +175,7 @@ static void yurex_interrupt(struct urb * case CMD_ACK: dev_dbg(&dev->interface->dev, "%s ack: %c\n", __func__, buf[1]); + dev->command_finished = 1; wake_up_interruptible(&dev->waitq); break; } @@ -321,6 +324,7 @@ static void yurex_disconnect(struct usb_ /* wakeup waiters */ kill_fasync(&dev->async_queue, SIGIO, POLL_IN); + dev->command_finished = 1; wake_up_interruptible(&dev->waitq); /* decrement our usage count */ @@ -428,8 +432,7 @@ static ssize_t yurex_write(struct file * char buffer[16 + 1]; char *data = buffer; unsigned long long c, c2 = 0; - signed long timeout = 0; - DEFINE_WAIT(wait); + signed long time_remaining = 0; count = min(sizeof(buffer) - 1, count); dev = file->private_data; @@ -485,14 +488,16 @@ static ssize_t yurex_write(struct file * } /* send the data as the control msg */ - prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE); dev_dbg(&dev->interface->dev, "%s - submit %c\n", __func__, dev->cntl_buffer[0]); retval = usb_submit_urb(dev->cntl_urb, GFP_KERNEL); - if (retval >= 0) - timeout = schedule_timeout(YUREX_WRITE_TIMEOUT); - finish_wait(&dev->waitq, &wait); - + if (retval >= 0) { + dev->command_finished = 0; + time_remaining = wait_event_interruptible_timeout(dev->waitq, + dev->command_finished, YUREX_WRITE_TIMEOUT); + if (time_remaining < 0) + retval = -EINTR; + } mutex_unlock(&dev->io_mutex); if (retval < 0) { @@ -501,9 +506,9 @@ static ssize_t yurex_write(struct file * __func__, retval); goto error; } - if (set && timeout) + if (set && time_remaining) dev->bbu = c2; - return timeout ? count : -EIO; + return time_remaining ? count : -EIO; error: return retval;