[PATCH] saa7134-tvaudio: Convert to kthread API.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Eric W. Biederman <[email protected]>

It is my goal to replace all kernel code that handles signals
from user space, calls kernel_thread or calls daemonize.  All
of which the kthread_api makes unncessary.  Handling signals
from user space is a maintenance problem becuase using a
kernel thread is an implementation detail and if user space
cares it does not allow us to change the implementation.  Calling
daemonize is a problem because it has to undo a continually changing
set of state generated by user space, requiring the implemetation
to change continually.  kernel_thread is a problem because it
returns a pid_t value.  Numeric pids are inherently racy and
in the presence of a pid namespace they are no longer global
making them useless for general use in the kernel.

So this patch renames the pid member of struct saa7134_thread
started and changes it's type from pid_t to int.  All it
has ever been used for is to detect if the kernel thread
is has been started so this works.

allow_signal(SIGTERM) and the calls to signal_pending have
been removed they are needed for the driver to operation.

The startup of tvaudio_thread and tvaudio_thread_dep have
been modified to use kthread_run instead of a combination
of kernel_thread and daemonize.

The result is code that is slightly simpler and more
maintainable.

Cc: Hartmut Hackmann <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Signed-off-by: Eric W. Biederman <[email protected]>
---
 drivers/media/video/saa7134/saa7134-tvaudio.c |   27 ++++++++++++-------------
 drivers/media/video/saa7134/saa7134.h         |    2 +-
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index 7b56041..b636cb1 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -27,6 +27,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
+#include <linux/kthread.h>
 #include <asm/div64.h>
 
 #include "saa7134-reg.h"
@@ -505,11 +506,9 @@ static int tvaudio_thread(void *data)
 	unsigned int i, audio, nscan;
 	int max1,max2,carrier,rx,mode,lastmode,default_carrier;
 
-	daemonize("%s", dev->name);
-	allow_signal(SIGTERM);
 	for (;;) {
 		tvaudio_sleep(dev,-1);
-		if (dev->thread.shutdown || signal_pending(current))
+		if (dev->thread.shutdown)
 			goto done;
 
 	restart:
@@ -618,7 +617,7 @@ static int tvaudio_thread(void *data)
 		for (;;) {
 			if (tvaudio_sleep(dev,5000))
 				goto restart;
-			if (dev->thread.shutdown || signal_pending(current))
+			if (dev->thread.shutdown)
 				break;
 			if (UNSET == dev->thread.mode) {
 				rx = tvaudio_getstereo(dev,&tvaudio[i]);
@@ -782,9 +781,6 @@ static int tvaudio_thread_ddep(void *data)
 	struct saa7134_dev *dev = data;
 	u32 value, norms, clock;
 
-	daemonize("%s", dev->name);
-	allow_signal(SIGTERM);
-
 	clock = saa7134_boards[dev->board].audio_clock;
 	if (UNSET != audio_clock_override)
 		clock = audio_clock_override;
@@ -796,7 +792,7 @@ static int tvaudio_thread_ddep(void *data)
 
 	for (;;) {
 		tvaudio_sleep(dev,-1);
-		if (dev->thread.shutdown || signal_pending(current))
+		if (dev->thread.shutdown)
 			goto done;
 
 	restart:
@@ -986,14 +982,17 @@ int saa7134_tvaudio_init2(struct saa7134_dev *dev)
 		break;
 	}
 
-	dev->thread.pid = -1;
+	dev->thread.started = 0;
 	if (my_thread) {
+		struct task_struct *task;
 		/* start tvaudio thread */
 		init_waitqueue_head(&dev->thread.wq);
 		init_completion(&dev->thread.exit);
-		dev->thread.pid = kernel_thread(my_thread,dev,0);
-		if (dev->thread.pid < 0)
-			printk(KERN_WARNING "%s: kernel_thread() failed\n",
+		task = kthread_run(my_thread, dev, "%s", dev->name);
+		if (!IS_ERR(task))
+			dev->thread.started = 1;
+		else
+			printk(KERN_WARNING "%s: kthread_create() failed\n",
 			       dev->name);
 		saa7134_tvaudio_do_scan(dev);
 	}
@@ -1005,7 +1004,7 @@ int saa7134_tvaudio_init2(struct saa7134_dev *dev)
 int saa7134_tvaudio_fini(struct saa7134_dev *dev)
 {
 	/* shutdown tvaudio thread */
-	if (dev->thread.pid >= 0) {
+	if (dev->thread.started) {
 		dev->thread.shutdown = 1;
 		wake_up_interruptible(&dev->thread.wq);
 		wait_for_completion(&dev->thread.exit);
@@ -1020,7 +1019,7 @@ int saa7134_tvaudio_do_scan(struct saa7134_dev *dev)
 		dprintk("sound IF not in use, skipping scan\n");
 		dev->automute = 0;
 		saa7134_tvaudio_setmute(dev);
-	} else if (dev->thread.pid >= 0) {
+	} else if (dev->thread.started) {
 		dev->thread.mode = UNSET;
 		dev->thread.scan2++;
 		wake_up_interruptible(&dev->thread.wq);
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 62224cc..3a10ce7 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -324,7 +324,7 @@ struct saa7134_pgtable {
 
 /* tvaudio thread status */
 struct saa7134_thread {
-	pid_t                      pid;
+	int			   started;
 	struct completion          exit;
 	wait_queue_head_t          wq;
 	unsigned int               shutdown;
-- 
1.5.0.g53756

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux