public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: linux-pcmcia@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] pcmcia: use kthread_ API
Date: Tue, 14 Feb 2006 18:50:16 +0100	[thread overview]
Message-ID: <20060214175016.GA19080@lst.de> (raw)

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

Also use wake_up_process instead of an additional per-socket waitqueue.


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

Index: linux-2.6/drivers/pcmcia/cs.c
===================================================================
--- linux-2.6.orig/drivers/pcmcia/cs.c	2006-01-06 10:44:16.000000000 +0100
+++ linux-2.6/drivers/pcmcia/cs.c	2006-02-14 18:34:14.000000000 +0100
@@ -29,6 +29,7 @@
 #include <linux/pm.h>
 #include <linux/pci.h>
 #include <linux/device.h>
+#include <linux/kthread.h>
 #include <asm/system.h>
 #include <asm/irq.h>
 
@@ -235,22 +236,16 @@
 	INIT_LIST_HEAD(&socket->cis_cache);
 
 	init_completion(&socket->socket_released);
-	init_completion(&socket->thread_done);
-	init_waitqueue_head(&socket->thread_wait);
 	init_MUTEX(&socket->skt_sem);
 	spin_lock_init(&socket->thread_lock);
 
-	ret = kernel_thread(pccardd, socket, CLONE_KERNEL);
-	if (ret < 0)
+	socket->thread = kthread_run(pccardd, socket, "pccardd");
+	if (IS_ERR(socket->thread)) {
+		ret = PTR_ERR(socket->thread);
 		goto err;
-
-	wait_for_completion(&socket->thread_done);
-	if(!socket->thread) {
-		printk(KERN_WARNING "PCMCIA: warning: socket thread for socket %p did not start\n", socket);
-		return -EIO;
 	}
-	pcmcia_parse_events(socket, SS_DETECT);
 
+	pcmcia_parse_events(socket, SS_DETECT);
 	return 0;
 
  err:
@@ -273,10 +268,8 @@
 	cs_dbg(socket, 0, "pcmcia_unregister_socket(0x%p)\n", socket->ops);
 
 	if (socket->thread) {
-		init_completion(&socket->thread_done);
+		kthread_stop(socket->thread);
 		socket->thread = NULL;
-		wake_up(&socket->thread_wait);
-		wait_for_completion(&socket->thread_done);
 	}
 	release_cis_mem(socket);
 
@@ -630,12 +623,8 @@
 static int pccardd(void *__skt)
 {
 	struct pcmcia_socket *skt = __skt;
-	DECLARE_WAITQUEUE(wait, current);
 	int ret;
 
-	daemonize("pccardd");
-
-	skt->thread = current;
 	skt->socket = dead_socket;
 	skt->ops->init(skt);
 	skt->ops->set_socket(skt, &skt->socket);
@@ -645,13 +634,9 @@
 	if (ret) {
 		printk(KERN_WARNING "PCMCIA: unable to register socket 0x%p\n",
 			skt);
-		skt->thread = NULL;
-		complete_and_exit(&skt->thread_done, 0);
+		return 0;
 	}
 
-	add_wait_queue(&skt->thread_wait, &wait);
-	complete(&skt->thread_done);
-
 	for (;;) {
 		unsigned long flags;
 		unsigned int events;
@@ -677,7 +662,7 @@
 			continue;
 		}
 
-		if (!skt->thread)
+		if (!kthread_should_stop())
 			break;
 
 		schedule();
@@ -686,12 +671,10 @@
 	/* make sure we are running before we exit */
 	set_current_state(TASK_RUNNING);
 
-	remove_wait_queue(&skt->thread_wait, &wait);
-
 	/* remove from the device core */
 	class_device_unregister(&skt->dev);
 
-	complete_and_exit(&skt->thread_done, 0);
+	return 0;
 }
 
 /*
@@ -706,7 +689,7 @@
 		s->thread_events |= events;
 		spin_unlock(&s->thread_lock);
 
-		wake_up(&s->thread_wait);
+		wake_up_process(s->thread);
 	}
 } /* pcmcia_parse_events */
 EXPORT_SYMBOL(pcmcia_parse_events);
Index: linux-2.6/include/pcmcia/ss.h
===================================================================
--- linux-2.6.orig/include/pcmcia/ss.h	2006-01-06 10:44:17.000000000 +0100
+++ linux-2.6/include/pcmcia/ss.h	2006-02-14 18:32:41.000000000 +0100
@@ -244,8 +244,6 @@
 	struct semaphore		skt_sem;	/* protects socket h/w state */
 
 	struct task_struct		*thread;
-	struct completion		thread_done;
-	wait_queue_head_t		thread_wait;
 	spinlock_t			thread_lock;	/* protects thread_events */
 	unsigned int			thread_events;
 

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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-14 17:50 Christoph Hellwig [this message]
2006-02-14 19:37 ` [PATCH] pcmcia: use kthread_ API Russell King
2006-02-14 19:45   ` Christoph Hellwig

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=20060214175016.GA19080@lst.de \
    --to=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pcmcia@lists.infradead.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