Re: [PATCH 03/20] staging/usbip: convert to kthread

From: Arnd Bergmann
Date: Tue Mar 01 2011 - 17:16:04 EST


On Friday 28 January 2011 18:53:48 Max Vozeler wrote:
> I need to leave now for the next couple of days,
> so this is a bit rushed.
>
> I can take a closer look and do tests in different
> setups during the next week.
>

It seems we both forgot about this. This is what I now added to my tree.
Greg, I'll resubmit a folded version with the original patch.

Arnd
8<------

staging/usbip: fix breakage from BKL removal

wait_event_interruptible() in a kthread needs
to check if the kthread should stop.

Thread creation was racy, calling kthread_run
instead of wake_up on an existing kthread
fixes this.

Reported-by: Max Vozeler <max@xxxxxxxxxxx>
Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
---

diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index f2c6148..8214c35 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -139,8 +139,8 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,

spin_unlock(&sdev->ud.lock);

- wake_up_process(sdev->ud.tcp_rx);
- wake_up_process(sdev->ud.tcp_tx);
+ sdev->ud.tcp_rx = kthread_run(stub_rx_loop, &sdev->ud, "stub_rx");
+ sdev->ud.tcp_tx = kthread_run(stub_tx_loop, &sdev->ud, "stub_tx");

spin_lock(&sdev->ud.lock);
sdev->ud.status = SDEV_ST_USED;
@@ -339,9 +339,6 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev,
*/
sdev->devid = (busnum << 16) | devnum;

- sdev->ud.tcp_rx = kthread_create(stub_rx_loop, &sdev->ud, "stub_rx");
- sdev->ud.tcp_tx = kthread_create(stub_tx_loop, &sdev->ud, "stub_tx");
-
sdev->ud.side = USBIP_STUB;
sdev->ud.status = SDEV_ST_AVAILABLE;
/* sdev->ud.lock = SPIN_LOCK_UNLOCKED; */
diff --git a/drivers/staging/usbip/stub_tx.c b/drivers/staging/usbip/stub_tx.c
index 2477481..5523f25 100644
--- a/drivers/staging/usbip/stub_tx.c
+++ b/drivers/staging/usbip/stub_tx.c
@@ -365,7 +365,8 @@ int stub_tx_loop(void *data)

wait_event_interruptible(sdev->tx_waitq,
(!list_empty(&sdev->priv_tx) ||
- !list_empty(&sdev->unlink_tx)));
+ !list_empty(&sdev->unlink_tx) ||
+ kthread_should_stop()));
}

return 0;
diff --git a/drivers/staging/usbip/usbip_event.c b/drivers/staging/usbip/usbip_event.c
index 89aecec..f4b287e 100644
--- a/drivers/staging/usbip/usbip_event.c
+++ b/drivers/staging/usbip/usbip_event.c
@@ -67,12 +67,13 @@ static int event_handler_loop(void *data)
struct usbip_device *ud = data;

while (!kthread_should_stop()) {
- if (event_handler(ud) < 0)
- break;
-
wait_event_interruptible(ud->eh_waitq,
- usbip_event_happened(ud));
+ usbip_event_happened(ud) ||
+ kthread_should_stop());
usbip_dbg_eh("wakeup\n");
+
+ if (event_handler(ud) < 0)
+ break;
}
return 0;
}
diff --git a/drivers/staging/usbip/vhci_tx.c b/drivers/staging/usbip/vhci_tx.c
index 6d065b9..d9ab49d 100644
--- a/drivers/staging/usbip/vhci_tx.c
+++ b/drivers/staging/usbip/vhci_tx.c
@@ -230,7 +230,8 @@ int vhci_tx_loop(void *data)

wait_event_interruptible(vdev->waitq_tx,
(!list_empty(&vdev->priv_tx) ||
- !list_empty(&vdev->unlink_tx)));
+ !list_empty(&vdev->unlink_tx) ||
+ kthread_should_stop()));

usbip_dbg_vhci_tx("pending urbs ?, now wake up\n");
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/