Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9720b4bc authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Greg Kroah-Hartman
Browse files

staging/usbip: convert to kthread



usbip has its own infrastructure for managing kernel
threads, similar to kthread. By changing it to use
the standard functions, we can simplify the code
and get rid of one of the last BKL users at the
same time.

Includes changes suggested by Max Vozeler.

Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Takahiro Hirofuchi <hirofuchi@users.sourceforge.net>
Cc: Max Vozeler <max@vozeler.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 8c811616
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
config USB_IP_COMMON
	tristate "USB IP support (EXPERIMENTAL)"
	depends on USB && NET && EXPERIMENTAL && BKL
	depends on USB && NET && EXPERIMENTAL
	default N
	---help---
	  This enables pushing USB packets over IP to allow remote
+2 −2
Original line number Diff line number Diff line
@@ -95,13 +95,13 @@ extern struct kmem_cache *stub_priv_cache;

/* stub_tx.c */
void stub_complete(struct urb *);
void stub_tx_loop(struct usbip_task *);
int stub_tx_loop(void *data);

/* stub_dev.c */
extern struct usb_driver stub_driver;

/* stub_rx.c */
void stub_rx_loop(struct usbip_task *);
int stub_rx_loop(void *data);
void stub_enqueue_ret_unlink(struct stub_device *, __u32, __u32);

/* stub_main.c */
+6 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
 */

#include <linux/slab.h>
#include <linux/kthread.h>

#include "usbip_common.h"
#include "stub.h"
@@ -138,7 +139,8 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,

		spin_unlock(&sdev->ud.lock);

		usbip_start_threads(&sdev->ud);
		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;
@@ -218,7 +220,8 @@ static void stub_shutdown_connection(struct usbip_device *ud)
	}

	/* 1. stop threads */
	usbip_stop_threads(ud);
	kthread_stop(ud->tcp_rx);
	kthread_stop(ud->tcp_tx);

	/* 2. close the socket */
	/*
@@ -336,9 +339,6 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev,
	 */
	sdev->devid     = (busnum << 16) | devnum;

	usbip_task_init(&sdev->ud.tcp_rx, "stub_rx", stub_rx_loop);
	usbip_task_init(&sdev->ud.tcp_tx, "stub_tx", stub_tx_loop);

	sdev->ud.side = USBIP_STUB;
	sdev->ud.status = SDEV_ST_AVAILABLE;
	/* sdev->ud.lock = SPIN_LOCK_UNLOCKED; */
@@ -543,7 +543,7 @@ static void stub_disconnect(struct usb_interface *interface)
	stub_remove_files(&interface->dev);

	/*If usb reset called from event handler*/
	if (busid_priv->sdev->ud.eh.thread == current) {
	if (busid_priv->sdev->ud.eh == current) {
		busid_priv->interf_count--;
		return;
	}
+5 −8
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
 */

#include <linux/slab.h>
#include <linux/kthread.h>

#include "usbip_common.h"
#include "stub.h"
@@ -616,19 +617,15 @@ static void stub_rx_pdu(struct usbip_device *ud)

}

void stub_rx_loop(struct usbip_task *ut)
int stub_rx_loop(void *data)
{
	struct usbip_device *ud = container_of(ut, struct usbip_device, tcp_rx);

	while (1) {
		if (signal_pending(current)) {
			usbip_dbg_stub_rx("signal caught!\n");
			break;
		}
	struct usbip_device *ud = data;

	while (!kthread_should_stop()) {
		if (usbip_event_happened(ud))
			break;

		stub_rx_pdu(ud);
	}
	return 0;
}
+8 −9
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
 */

#include <linux/slab.h>
#include <linux/kthread.h>

#include "usbip_common.h"
#include "stub.h"
@@ -333,17 +334,12 @@ static int stub_send_ret_unlink(struct stub_device *sdev)

/*-------------------------------------------------------------------------*/

void stub_tx_loop(struct usbip_task *ut)
int stub_tx_loop(void *data)
{
	struct usbip_device *ud = container_of(ut, struct usbip_device, tcp_tx);
	struct usbip_device *ud = data;
	struct stub_device *sdev = container_of(ud, struct stub_device, ud);

	while (1) {
		if (signal_pending(current)) {
			usbip_dbg_stub_tx("signal catched\n");
			break;
		}

	while (!kthread_should_stop()) {
		if (usbip_event_happened(ud))
			break;

@@ -369,6 +365,9 @@ void stub_tx_loop(struct usbip_task *ut)

		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;
}
Loading