mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: duncan.sands@free.fr, dwmw2@infradead.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] usbatm: use kthread_ API
Date: Tue, 14 Feb 2006 18:51:52 +0100	[thread overview]
Message-ID: <20060214175152.GB19080@lst.de> (raw)

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;


             reply	other threads:[~2006-02-14 17:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-14 17:51 Christoph Hellwig [this message]
2006-02-15  9:42 ` Duncan Sands

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060214175152.GB19080@lst.de \
    --to=hch@lst.de \
    --cc=duncan.sands@free.fr \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®