From: Eric W. Biederman 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 Cc: Mauro Carvalho Chehab Signed-off-by: Eric W. Biederman Signed-off-by: Andrew Morton --- drivers/media/video/saa7134/saa7134-tvaudio.c | 27 +++++++--------- drivers/media/video/saa7134/saa7134.h | 2 - 2 files changed, 14 insertions(+), 15 deletions(-) diff -puN drivers/media/video/saa7134/saa7134-tvaudio.c~mm-only-saa7134-tvaudio-convert-to-kthread-api drivers/media/video/saa7134/saa7134-tvaudio.c --- a/drivers/media/video/saa7134/saa7134-tvaudio.c~mm-only-saa7134-tvaudio-convert-to-kthread-api +++ a/drivers/media/video/saa7134/saa7134-tvaudio.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -506,11 +507,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: @@ -619,7 +618,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]); @@ -783,9 +782,6 @@ static int tvaudio_thread_ddep(void *dat 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; @@ -797,7 +793,7 @@ static int tvaudio_thread_ddep(void *dat for (;;) { tvaudio_sleep(dev,-1); - if (dev->thread.shutdown || signal_pending(current)) + if (dev->thread.shutdown) goto done; restart: @@ -987,14 +983,17 @@ int saa7134_tvaudio_init2(struct saa7134 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); } @@ -1006,7 +1005,7 @@ int saa7134_tvaudio_init2(struct saa7134 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); @@ -1021,7 +1020,7 @@ int saa7134_tvaudio_do_scan(struct saa71 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 -puN drivers/media/video/saa7134/saa7134.h~mm-only-saa7134-tvaudio-convert-to-kthread-api drivers/media/video/saa7134/saa7134.h --- a/drivers/media/video/saa7134/saa7134.h~mm-only-saa7134-tvaudio-convert-to-kthread-api +++ a/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; _