All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Eric W. Biederman" <ebiederm@xmission.com>
To: "<Andrew Morton" <akpm@osdl.org>
Cc: <containers@lists.osdl.org>, Oleg Nesterov <oleg@tv-sign.ru>,
	Christoph Hellwig <hch@infradead.org>,
	<linux-kernel@vger.kernel.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Subject: [PATCH] dvb_en_50221: Convert to kthread API
Date: Thu, 19 Apr 2007 00:55:59 -0600	[thread overview]
Message-ID: <11769658182698-git-send-email-ebiederm@xmission.com> (raw)
In-Reply-To: <m1slawn9eb.fsf@ebiederm.dsl.xmission.com>

From: Eric W. Biederman <ebiederm@xmission.com> - unquoted

This patch is a minimal transformation to use the kthread API
doing it's best to preserve the existing logic.

Instead of starting kdvb-ca by calling kernel_thread,
daemonize and sigfillset we kthread_run is used.

Instead of tracking the pid of the running thread we instead
simply keep a flag to indicate that the current thread is
running, as that is all the pid is really used for.

And finally the kill_proc sending signal 0 to the kernel thread to
ensure it is alive before we wait for it to shutdown is removed.
The kthread API does not provide the pid so we don't have that
information readily available and the test is just silly.  If there
is no shutdown race the test is a useless confirmation of that the
thread is running.  If there is a race the test doesn't fix it and
we should fix the race properly.

Cc: Andrew de Quincey <adq_dvb@lidskialf.net>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 drivers/media/dvb/dvb-core/dvb_ca_en50221.c |   46 ++++++++++----------------
 1 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index 2a03bf5..b28bc15 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -37,6 +37,7 @@
 #include <linux/delay.h>
 #include <linux/spinlock.h>
 #include <linux/sched.h>
+#include <linux/kthread.h>
 
 #include "dvb_ca_en50221.h"
 #include "dvb_ringbuffer.h"
@@ -139,8 +140,8 @@ struct dvb_ca_private {
 	/* wait queues for read() and write() operations */
 	wait_queue_head_t wait_queue;
 
-	/* PID of the monitoring thread */
-	pid_t thread_pid;
+	/* Flag indicating the monitoring thread is running */
+	int thread_running;
 
 	/* Wait queue used when shutting thread down */
 	wait_queue_head_t thread_queue;
@@ -982,7 +983,6 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca)
 static int dvb_ca_en50221_thread(void *data)
 {
 	struct dvb_ca_private *ca = data;
-	char name[15];
 	int slot;
 	int flags;
 	int status;
@@ -991,14 +991,6 @@ static int dvb_ca_en50221_thread(void *data)
 
 	dprintk("%s\n", __FUNCTION__);
 
-	/* setup kernel thread */
-	snprintf(name, sizeof(name), "kdvb-ca-%i:%i", ca->dvbdev->adapter->num, ca->dvbdev->id);
-
-	lock_kernel();
-	daemonize(name);
-	sigfillset(&current->blocked);
-	unlock_kernel();
-
 	/* choose the correct initial delay */
 	dvb_ca_en50221_thread_update_delay(ca);
 
@@ -1182,7 +1174,7 @@ static int dvb_ca_en50221_thread(void *data)
 	}
 
 	/* completed */
-	ca->thread_pid = 0;
+	ca->thread_running = 0;
 	mb();
 	wake_up_interruptible(&ca->thread_queue);
 	return 0;
@@ -1660,6 +1652,7 @@ static struct dvb_device dvbdev_ca = {
 int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 			struct dvb_ca_en50221 *pubca, int flags, int slot_count)
 {
+	struct task_struct *task;
 	int ret;
 	struct dvb_ca_private *ca = NULL;
 	int i;
@@ -1682,7 +1675,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 		goto error;
 	}
 	init_waitqueue_head(&ca->wait_queue);
-	ca->thread_pid = 0;
+	ca->thread_running = 0;
 	init_waitqueue_head(&ca->thread_queue);
 	ca->exit = 0;
 	ca->open = 0;
@@ -1711,13 +1704,15 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 
 	/* create a kthread for monitoring this CA device */
 
-	ret = kernel_thread(dvb_ca_en50221_thread, ca, 0);
-
-	if (ret < 0) {
-		printk("dvb_ca_init: failed to start kernel_thread (%d)\n", ret);
+	task = kthread_run(dvb_ca_en50221_thread, ca,
+			   "kdvb-ca-%i:%i",
+			   ca->dvbdev->adapter->num, ca->dvbdev->id);
+	if (IS_ERR(task)) {
+		ret = PTR_ERR(task);
+		printk("dvb_ca_init: failed to start kthread (%d)\n", ret);
 		goto error;
 	}
-	ca->thread_pid = ret;
+	ca->thread_running = 1;
 	return 0;
 
 error:
@@ -1748,16 +1743,11 @@ void dvb_ca_en50221_release(struct dvb_ca_en50221 *pubca)
 	dprintk("%s\n", __FUNCTION__);
 
 	/* shutdown the thread if there was one */
-	if (ca->thread_pid) {
-		if (kill_proc(ca->thread_pid, 0, 1) == -ESRCH) {
-			printk("dvb_ca_release adapter %d: thread PID %d already died\n",
-			       ca->dvbdev->adapter->num, ca->thread_pid);
-		} else {
-			ca->exit = 1;
-			mb();
-			dvb_ca_en50221_thread_wakeup(ca);
-			wait_event_interruptible(ca->thread_queue, ca->thread_pid == 0);
-		}
+	if (ca->thread_running) {
+		ca->exit = 1;
+		mb();
+		dvb_ca_en50221_thread_wakeup(ca);
+		wait_event_interruptible(ca->thread_queue, ca->thread_running == 0);
 	}
 
 	for (i = 0; i < ca->slot_count; i++) {
-- 
1.5.0.g53756


  parent reply	other threads:[~2007-04-19  7:10 UTC|newest]

Thread overview: 237+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-19  6:52 Remaining straight forward kthread API conversions Eric W. Biederman
2007-04-19  6:55 ` [PATCH] i386 balance_irq: Convert to the kthread api Eric W. Biederman
2007-04-19  6:55 ` [PATCH] i386 voyager: Convert the monitor thread to use the kthread API Eric W. Biederman
2007-04-22 19:30   ` Christoph Hellwig
2007-04-19  6:55 ` [PATCH] mtd_blkdevs: Convert " Eric W. Biederman
2007-04-19 16:47   ` Christoph Hellwig
2007-04-19 19:13     ` Eric W. Biederman
2007-04-19 22:26       ` Andrew Morton
2007-04-22 12:24   ` Christoph Hellwig
2007-04-22 13:23     ` David Woodhouse
2007-04-22 19:26       ` Christoph Hellwig
2007-04-22 19:40     ` Christoph Hellwig
2007-04-19  6:55 ` [PATCH] cpci_hotplug: " Eric W. Biederman
2007-04-22 12:05   ` Christoph Hellwig
2007-04-23 16:19     ` Scott Murray
2007-04-27 22:07     ` Scott Murray
2007-05-04 11:12       ` Christoph Hellwig
2007-05-07 18:18         ` Scott Murray
2007-05-09 23:24           ` Andrew Morton
2007-05-10  0:00             ` Kristen Carlson Accardi
2007-05-10 18:29             ` Scott Murray
2007-05-10 19:30               ` Andrew Morton
2007-04-19  6:55 ` [PATCH] ibmphp: Convert to use the kthreads API Eric W. Biederman
2007-04-22 12:09   ` Christoph Hellwig
2007-04-19  6:55 ` [PATCH] cpqphp: Convert to use the kthread API Eric W. Biederman
2007-04-22 12:12   ` Christoph Hellwig
2007-04-19  6:55 ` [PATCH] pnpbios: Conert " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] sas_scsi_host: Convert " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] sparc64/power.c: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] s390/net/lcs: Convert to " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] s390 qeth: Convert to use " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] s390/scsi/zfcp_erp: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] arm ecard: Conver " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] ia64 sn xpc: Convert to use " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] powerpc pseries eeh: Convert to " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] powerpc pseries rtasd: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] macintosh/therm_pm72.c: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] macintosh/therm_windtunnel.c: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] macintosh/adb: Convert to the " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] macintosh/mediabay: Convert to " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] bluetooth bnep: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] bluetooth cmtp: Convert to use " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] bluetooth hidp: Convert to " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] bluetooth rfcomm: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] fs/afs: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] net/rxrpc: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] ipv4/ipvs: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] saa7134-tvaudio: " Eric W. Biederman
2007-04-20 12:48   ` Cedric Le Goater
2007-04-20 13:05     ` Christoph Hellwig
2007-04-19  6:55 ` [PATCH] nfs lockd reclaimer: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] nfsv4 delegation: " Eric W. Biederman
2007-04-19  6:55 ` [PATCH] nfsd/nfs4state: Remove unnecessary daemonize call Eric W. Biederman
2007-04-19  6:55 ` [PATCH] nfs4state reclaimer: Remove unnecessary allow_signal Eric W. Biederman
2007-04-19  6:55 ` [PATCH] smbfs: " Eric W. Biederman
2007-04-19  6:55 ` Eric W. Biederman [this message]
2007-04-19  6:56 ` [PATCH] md: Remove broken SIGKILL support Eric W. Biederman
2007-04-19  6:56 ` [PATCH] synchro_test: Convert to the kthread API Eric W. Biederman
2007-04-19  6:56 ` Eric W. Biederman
2007-04-19  7:58 ` [PATCH] i386 balance_irq: Convert to the kthread api Eric W. Biederman
2007-04-19  7:58 ` [PATCH] i386 voyager: Convert the monitor thread to use the kthread API Eric W. Biederman
2007-04-19  7:58 ` [PATCH] mtd_blkdevs: Convert " Eric W. Biederman
2007-04-19  7:58 ` [PATCH] cpci_hotplug: " Eric W. Biederman
2007-04-19  7:58 ` [PATCH] ibmphp: Convert to use the kthreads API Eric W. Biederman
2007-04-19  7:58 ` [PATCH] cpqphp: Convert to use the kthread API Eric W. Biederman
2007-04-20  1:54   ` Andrew Morton
2007-04-19  7:58 ` [PATCH] pnpbios: Conert " Eric W. Biederman
2007-04-19  7:58 ` [PATCH] sas_scsi_host: Convert " Eric W. Biederman
2007-04-20  0:37   ` Andrew Morton
2007-04-22 19:38     ` Christoph Hellwig
2007-04-22 21:37       ` James Bottomley
2007-04-22 21:48         ` Eric W. Biederman
2007-04-19  7:58 ` [PATCH] sparc64/power.c: " Eric W. Biederman
2007-04-20  0:30   ` Andrew Morton
2007-04-19  7:58 ` [PATCH] s390/net/lcs: Convert to " Eric W. Biederman
2007-04-19  8:19   ` Frank Pavlic
2007-04-19  7:58 ` [PATCH] s390 qeth: Convert to use " Eric W. Biederman
2007-04-19  7:58 ` [PATCH] s390/scsi/zfcp_erp: " Eric W. Biederman
2007-04-22 20:17   ` Christoph Hellwig
2007-04-30 10:41     ` Swen Schillig
2007-04-19  7:58 ` [PATCH] arm ecard: Conver " Eric W. Biederman
2007-04-22 20:18   ` Christoph Hellwig
2007-04-19  7:58 ` [PATCH] ia64 sn xpc: Convert to use " Eric W. Biederman
2007-04-19 23:51   ` Andrew Morton
2007-04-20  6:23     ` Jes Sorensen
2007-04-20 14:21       ` Robin Holt
2007-04-21 19:53         ` Eric W. Biederman
2007-04-22 20:36   ` Christoph Hellwig
2007-04-23 17:11     ` Jes Sorensen
2007-04-23 17:11       ` Jes Sorensen
2007-04-23 17:36       ` Eric W. Biederman
2007-04-23 17:36         ` Eric W. Biederman
2007-04-23 19:03       ` Russ Anderson
2007-04-23 19:03         ` Russ Anderson
2007-04-27 17:41     ` Dean Nelson
2007-04-27 18:34       ` Eric W. Biederman
2007-04-27 20:12         ` Dean Nelson
2007-04-27 20:33           ` Eric W. Biederman
2007-04-30 15:22             ` Dean Nelson
2007-05-02 15:16               ` Dean Nelson
2007-05-02 15:44                 ` Eric W. Biederman
2007-05-17 13:44                   ` Dean Nelson
2007-04-26 20:00   ` Dean Nelson
2007-04-19  7:58 ` [PATCH] powerpc pseries eeh: Convert to " Eric W. Biederman
2007-04-19 23:47   ` Andrew Morton
2007-04-22 12:31   ` Christoph Hellwig
2007-04-22 12:31     ` Christoph Hellwig
2007-04-23 20:50     ` Linas Vepstas
2007-04-24  1:38       ` Benjamin Herrenschmidt
2007-04-24  1:38         ` Benjamin Herrenschmidt
2007-04-24  2:08         ` Eric W. Biederman
2007-04-24  2:08           ` Eric W. Biederman
2007-04-24  2:42           ` Benjamin Herrenschmidt
2007-04-24  2:42             ` Benjamin Herrenschmidt
2007-04-24  3:20             ` Eric W. Biederman
2007-04-24  3:20               ` Eric W. Biederman
2007-04-24  4:34               ` Paul Mackerras
2007-04-24  4:34                 ` Paul Mackerras
2007-04-24  4:34                 ` Paul Mackerras
2007-04-24  4:51                 ` Eric W. Biederman
2007-04-24  4:51                   ` Eric W. Biederman
2007-04-24  5:00               ` Benjamin Herrenschmidt
2007-04-24  5:00                 ` Benjamin Herrenschmidt
2007-04-24  5:43                 ` Eric W. Biederman
2007-04-24  5:43                   ` Eric W. Biederman
2007-04-24  5:58                   ` Benjamin Herrenschmidt
2007-04-24  5:58                     ` Benjamin Herrenschmidt
2007-04-24  6:17                   ` SOME STUFF ABOUT REISER4 lkml777
2007-04-24  6:17                     ` lkml777
2007-04-24 17:26                     ` Eric M. Hopper
2007-04-24  7:46                 ` [PATCH] powerpc pseries eeh: Convert to kthread API Cornelia Huck
2007-04-24  7:46                   ` Cornelia Huck
2007-04-24 17:24         ` Linas Vepstas
2007-04-24 17:24           ` Linas Vepstas
2007-04-24  5:55     ` Paul Mackerras
2007-04-24  5:55       ` Paul Mackerras
2007-04-24  8:37       ` Christoph Hellwig
2007-04-24  8:37         ` Christoph Hellwig
2007-04-24 17:35     ` Linas Vepstas
2007-04-19  7:58 ` [PATCH] powerpc pseries rtasd: " Eric W. Biederman
2007-04-22 12:34   ` Christoph Hellwig
2007-04-19  7:58 ` [PATCH] macintosh/therm_pm72.c: " Eric W. Biederman
2007-04-22 19:16   ` Christoph Hellwig
2007-04-22 22:46     ` Paul Mackerras
2007-04-19  7:58 ` [PATCH] macintosh/therm_windtunnel.c: " Eric W. Biederman
2007-04-19 23:37   ` Andrew Morton
2007-04-20  8:53     ` Benjamin Herrenschmidt
2007-04-19  7:58 ` [PATCH] macintosh/adb: Convert to the " Eric W. Biederman
2007-04-19  7:58 ` [PATCH] macintosh/mediabay: Convert to " Eric W. Biederman
2007-04-19 23:30   ` Andrew Morton
2007-04-20  8:51     ` Benjamin Herrenschmidt
2007-04-19  7:58 ` [PATCH] bluetooth bnep: " Eric W. Biederman
2007-04-19 23:24   ` Andrew Morton
2007-04-20 10:20     ` [Devel] " Cedric Le Goater
2007-04-20 12:37       ` Cedric Le Goater
2007-04-21 16:11         ` Satyam Sharma
2007-04-22 19:44     ` Christoph Hellwig
2007-04-23  3:12       ` [PATCH] kthread: Spontaneous exit support Eric W. Biederman
2007-04-23 11:25         ` Christoph Hellwig
2007-04-23 16:58           ` Oleg Nesterov
2007-04-23 17:45             ` Eric W. Biederman
2007-04-23 18:09               ` Christoph Hellwig
2007-04-23 18:20               ` Oleg Nesterov
2007-04-24 13:08           ` Jan Engelhardt
2007-04-24 13:34             ` Christoph Hellwig
2007-04-19  7:58 ` [PATCH] bluetooth cmtp: Convert to use kthread API Eric W. Biederman
2007-04-19  7:58 ` [PATCH] bluetooth hidp: Convert to " Eric W. Biederman
2007-04-19 23:20   ` Andrew Morton
2007-04-19  7:58 ` [PATCH] bluetooth rfcomm: " Eric W. Biederman
2007-04-19 23:12   ` Andrew Morton
2007-04-20 15:20     ` [Devel] " Cedric Le Goater
2007-04-22 20:14     ` Christoph Hellwig
2007-04-19  7:58 ` [PATCH] fs/afs: " Eric W. Biederman
2007-04-19  9:32   ` David Howells
2007-04-19  7:58 ` [PATCH] net/rxrpc: " Eric W. Biederman
2007-04-19  9:32   ` David Howells
2007-04-19 13:05     ` Eric W. Biederman
2007-04-19 14:18       ` Getting the new RxRPC patches upstream David Howells
2007-04-19 15:50         ` Eric W. Biederman
2007-04-19 16:18           ` David Howells
2007-04-19 19:14             ` Eric W. Biederman
2007-04-19 20:14         ` David Miller
2007-04-20  1:15           ` Herbert Xu
2007-04-20  8:02           ` David Howells
2007-04-20  8:58             ` David Miller
2007-04-20 10:41               ` David Howells
2007-04-20 18:38                 ` Andrew Morton
2007-04-20 21:28                   ` Oleg Nesterov
2007-04-23  8:32                     ` David Howells
2007-04-23 17:11                       ` Oleg Nesterov
2007-04-24 13:37                         ` David Howells
2007-04-24 14:22                           ` Oleg Nesterov
2007-04-24 15:51                             ` David Howells
2007-04-24 16:40                               ` Oleg Nesterov
2007-04-24 16:58                                 ` David Howells
2007-04-24 17:33                                   ` Oleg Nesterov
2007-04-24 18:22                                     ` David Howells
2007-04-24 19:34                                       ` Oleg Nesterov
2007-04-25  8:10                                         ` David Howells
2007-04-25 10:41                                           ` Oleg Nesterov
2007-04-25 10:45                                             ` David Howells
2007-04-25 13:48               ` David Howells
2007-04-19 23:05     ` [PATCH] net/rxrpc: Convert to kthread API Andrew Morton
2007-04-20  7:47       ` David Howells
2007-04-19  7:58 ` [PATCH] ipv4/ipvs: " Eric W. Biederman
2007-04-19  9:04   ` Simon Horman
2007-04-19 22:59     ` Andrew Morton
2007-04-22 19:50       ` Christoph Hellwig
2007-04-19  7:58 ` [PATCH] saa7134-tvaudio: " Eric W. Biederman
2007-04-19 22:52   ` Andrew Morton
2007-04-19  7:58 ` [PATCH] nfs lockd reclaimer: " Eric W. Biederman
2007-04-19 16:21   ` Trond Myklebust
2007-04-19 19:20     ` Eric W. Biederman
2007-04-19 21:19       ` Trond Myklebust
2007-04-19 21:25         ` Dave Hansen
2007-04-21 19:04           ` Eric W. Biederman
2007-04-19 21:40         ` Andrew Morton
2007-04-19 22:04           ` Trond Myklebust
2007-04-21 19:47             ` Eric W. Biederman
2007-04-19  7:59 ` [PATCH] nfsv4 delegation: " Eric W. Biederman
2007-04-19 16:22   ` Trond Myklebust
2007-04-19  7:59 ` [PATCH] nfsd/nfs4state: Remove unnecessary daemonize call Eric W. Biederman
2007-04-19  7:59 ` [PATCH] nfs4state reclaimer: Remove unnecessary allow_signal Eric W. Biederman
2007-04-19 16:26   ` Trond Myklebust
2007-04-19  7:59 ` [PATCH] smbfs: " Eric W. Biederman
2007-04-19 22:47   ` Andrew Morton
2007-04-19  7:59 ` [PATCH] dvb_en_50221: Convert to kthread API Eric W. Biederman
2007-04-19 22:34   ` Andrew Morton
2007-04-20  6:37     ` Christoph Hellwig
2007-04-20  6:48       ` Andrew Morton
2007-04-20  9:37         ` Cedric Le Goater
2007-04-19  7:59 ` [PATCH] md: Remove broken SIGKILL support Eric W. Biederman
2007-05-01  0:47   ` Neil Brown
2007-05-01  6:13     ` Eric W. Biederman
2007-04-19  7:59 ` [PATCH] synchro_test: Convert to the kthread API Eric W. Biederman
2007-04-19  7:59 ` Eric W. Biederman
2007-04-22 12:15 ` Remaining straight forward kthread API conversions 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=11769658182698-git-send-email-ebiederm@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=akpm@osdl.org \
    --cc=containers@lists.osdl.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@tv-sign.ru \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.