mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usbatm: use kthread_ API
@ 2006-02-14 17:51 Christoph Hellwig
  2006-02-15  9:42 ` Duncan Sands
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2006-02-14 17:51 UTC (permalink / raw)
  To: duncan.sands, dwmw2; +Cc: linux-kernel

Use the kthread_ API instead of opencoding lots of hairy code for kernel
thread creation and teardown.

Note: due to the short thread runtime we don't need a
kthread_should_stop()

Note2: all this is a bit odd and I don't have hardware, Duncan or David,
could you give it a try?


Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: linux-2.6/drivers/usb/atm/usbatm.c
===================================================================
--- linux-2.6.orig/drivers/usb/atm/usbatm.c	2006-02-04 13:35:01.000000000 +0100
+++ linux-2.6/drivers/usb/atm/usbatm.c	2006-02-14 18:08:04.000000000 +0100
@@ -75,6 +75,7 @@
 #include <linux/netdevice.h>
 #include <linux/proc_fs.h>
 #include <linux/sched.h>
+#include <linux/kthread.h>
 #include <linux/signal.h>
 #include <linux/slab.h>
 #include <linux/smp_lock.h>
@@ -999,38 +1000,24 @@
 	struct usbatm_data *instance = arg;
 	int ret;
 
-	daemonize(instance->driver->driver_name);
-	allow_signal(SIGTERM);
-
-	complete(&instance->thread_started);
-
 	ret = instance->driver->heavy_init(instance, instance->usb_intf);
-
 	if (!ret)
 		ret = usbatm_atm_init(instance);
-
-	mutex_lock(&instance->serialize);
-	instance->thread_pid = -1;
-	mutex_unlock(&instance->serialize);
-
-	complete_and_exit(&instance->thread_exited, ret);
+	return 0;
 }
 
 static int usbatm_heavy_init(struct usbatm_data *instance)
 {
-	int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL);
+	int ret;
 
-	if (ret < 0) {
-		usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
+	instance->thread = kthread_run(usbatm_do_heavy_init, instance, "%s",
+			instance->driver->driver_name);
+	if (IS_ERR(instance->thread)) {
+		ret = PTR_ERR(instance->thread);
+		usb_err(instance, "%s: failed to create kernel thread (%d)!\n", __func__, ret);
 		return ret;
 	}
 
-	mutex_lock(&instance->serialize);
-	instance->thread_pid = ret;
-	mutex_unlock(&instance->serialize);
-
-	wait_for_completion(&instance->thread_started);
-
 	return 0;
 }
 
@@ -1112,10 +1099,6 @@
 	kref_init(&instance->refcount);		/* dropped in usbatm_usb_disconnect */
 	mutex_init(&instance->serialize);
 
-	instance->thread_pid = -1;
-	init_completion(&instance->thread_started);
-	init_completion(&instance->thread_exited);
-
 	INIT_LIST_HEAD(&instance->vcc_list);
 	skb_queue_head_init(&instance->sndqueue);
 
@@ -1227,7 +1210,6 @@
 	if (!(instance->flags & UDSL_SKIP_HEAVY_INIT) && driver->heavy_init) {
 		error = usbatm_heavy_init(instance);
 	} else {
-		complete(&instance->thread_exited);	/* pretend that heavy_init was run */
 		error = usbatm_atm_init(instance);
 	}
 
@@ -1275,12 +1257,10 @@
 
 	mutex_lock(&instance->serialize);
 	instance->disconnected = 1;
-	if (instance->thread_pid >= 0)
-		kill_proc(instance->thread_pid, SIGTERM, 1);
+	if (instance->thread);
+		kthread_stop(instance->thread);
 	mutex_unlock(&instance->serialize);
 
-	wait_for_completion(&instance->thread_exited);
-
 	mutex_lock(&instance->serialize);
 	list_for_each_entry(vcc_data, &instance->vcc_list, list)
 		vcc_release_async(vcc_data->vcc, -EPIPE);
Index: linux-2.6/drivers/usb/atm/usbatm.h
===================================================================
--- linux-2.6.orig/drivers/usb/atm/usbatm.h	2006-02-04 13:35:01.000000000 +0100
+++ linux-2.6/drivers/usb/atm/usbatm.h	2006-02-14 18:07:11.000000000 +0100
@@ -176,9 +176,7 @@
 	int disconnected;
 
 	/* heavy init */
-	int thread_pid;
-	struct completion thread_started;
-	struct completion thread_exited;
+	struct task_struct *thread;
 
 	/* ATM device */
 	struct list_head vcc_list;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-02-15  9:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-14 17:51 [PATCH] usbatm: use kthread_ API Christoph Hellwig
2006-02-15  9:42 ` Duncan Sands

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®