From: Vojtech Pavlik <[email-masked]>

input: The timeout while() loops in iforce-packets.c lack a
set_current_state(TASK_INTERRUPTIBLE); call. The right solution is
to replace them with wait_event_interruptible_timeout().

Reported-by: Nishanth Aravamudan <[email-masked]>
Signed-off-by: Vojtech Pavlik <[email-masked]>

Index: dmitry/drivers/input/joystick/iforce/iforce-usb.c
===================================================================
--- dmitry.orig/drivers/input/joystick/iforce/iforce-usb.c	2005-06-27 15:13:50.000000000 +0200
+++ dmitry/drivers/input/joystick/iforce/iforce-usb.c	2005-07-07 15:23:51.000000000 +0200
@@ -95,6 +95,7 @@
 		goto exit;
 	}
 
+	wake_up(&iforce->wait);
 	iforce_process_packet(iforce,
 		(iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1, regs);
 
Index: dmitry/drivers/input/joystick/iforce/iforce-packets.c
===================================================================
--- dmitry.orig/drivers/input/joystick/iforce/iforce-packets.c	2005-06-27 15:13:50.000000000 +0200
+++ dmitry/drivers/input/joystick/iforce/iforce-packets.c	2005-07-07 15:26:48.000000000 +0200
@@ -249,9 +249,6 @@
 
 int iforce_get_id_packet(struct iforce *iforce, char *packet)
 {
-	DECLARE_WAITQUEUE(wait, current);
-	int timeout = HZ; /* 1 second */
-
 	switch (iforce->bus) {
 
 	case IFORCE_USB:
@@ -260,22 +257,13 @@
 		iforce->cr.bRequest = packet[0];
 		iforce->ctrl->dev = iforce->usbdev;
 
-		set_current_state(TASK_INTERRUPTIBLE);
-		add_wait_queue(&iforce->wait, &wait);
-
-		if (usb_submit_urb(iforce->ctrl, GFP_ATOMIC)) {
-			set_current_state(TASK_RUNNING);
-			remove_wait_queue(&iforce->wait, &wait);
+		if (usb_submit_urb(iforce->ctrl, GFP_ATOMIC))
 			return -1;
-		}
 
-		while (timeout && iforce->ctrl->status == -EINPROGRESS)
-			timeout = schedule_timeout(timeout);
+		wait_event_interruptible_timeout(iforce->wait,
+			iforce->ctrl->status != -EINPROGRESS, HZ);
 
-		set_current_state(TASK_RUNNING);
-		remove_wait_queue(&iforce->wait, &wait);
-
-		if (!timeout) {
+		if (iforce->ctrl->status -= -EINPROGRESS) {
 			usb_unlink_urb(iforce->ctrl);
 			return -1;
 		}
@@ -290,16 +278,10 @@
 		iforce->expect_packet = FF_CMD_QUERY;
 		iforce_send_packet(iforce, FF_CMD_QUERY, packet);
 
-		set_current_state(TASK_INTERRUPTIBLE);
-		add_wait_queue(&iforce->wait, &wait);
-
-		while (timeout && iforce->expect_packet)
-			timeout = schedule_timeout(timeout);
-
-		set_current_state(TASK_RUNNING);
-		remove_wait_queue(&iforce->wait, &wait);
+		wait_event_interruptible_timeout(iforce->wait,
+			!iforce->expect_packet, HZ);
 
-		if (!timeout) {
+		if (iforce->expect_packet) {
 			iforce->expect_packet = 0;
 			return -1;
 		}