aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/w1.c
diff options
context:
space:
mode:
authorEvgeniy Polyakov <johnpol@2ka.mipt.ru>2006-02-20 03:15:37 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-03-23 20:28:13 -0500
commit674a396c6d2ba0341ebdd7c1c9950f32f018e2dd (patch)
treeb1263e0a926d9cbdc7aa58260099392ad49a72fe /drivers/w1/w1.c
parentf73b5e7949945486a649e40821cd351e2f60bf02 (diff)
[PATCH] w1: use kthread api.
This patch removes old-style kernel thread initialization and changes w1 to use kthread api. It is based on Christoph Hellwig <hch@lst.de> work. Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/w1/w1.c')
-rw-r--r--drivers/w1/w1.c56
1 files changed, 16 insertions, 40 deletions
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index d640c1e1f8cd..a698b517e863 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -30,6 +30,7 @@
30#include <linux/device.h> 30#include <linux/device.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/sched.h> 32#include <linux/sched.h>
33#include <linux/kthread.h>
33 34
34#include <asm/atomic.h> 35#include <asm/atomic.h>
35 36
@@ -57,9 +58,7 @@ module_param_named(slave_ttl, w1_max_slave_ttl, int, 0);
57DEFINE_SPINLOCK(w1_mlock); 58DEFINE_SPINLOCK(w1_mlock);
58LIST_HEAD(w1_masters); 59LIST_HEAD(w1_masters);
59 60
60static pid_t control_thread; 61static struct task_struct *w1_control_thread;
61static int control_needs_exit;
62static DECLARE_COMPLETION(w1_control_complete);
63 62
64static int w1_master_match(struct device *dev, struct device_driver *drv) 63static int w1_master_match(struct device *dev, struct device_driver *drv)
65{ 64{
@@ -717,22 +716,16 @@ static int w1_control(void *data)
717{ 716{
718 struct w1_slave *sl, *sln; 717 struct w1_slave *sl, *sln;
719 struct w1_master *dev, *n; 718 struct w1_master *dev, *n;
720 int err, have_to_wait = 0; 719 int have_to_wait = 0;
721 720
722 daemonize("w1_control"); 721 while (!kthread_should_stop() || have_to_wait) {
723 allow_signal(SIGTERM);
724
725 while (!control_needs_exit || have_to_wait) {
726 have_to_wait = 0; 722 have_to_wait = 0;
727 723
728 try_to_freeze(); 724 try_to_freeze();
729 msleep_interruptible(w1_control_timeout * 1000); 725 msleep_interruptible(w1_control_timeout * 1000);
730 726
731 if (signal_pending(current))
732 flush_signals(current);
733
734 list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry) { 727 list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry) {
735 if (!control_needs_exit && !dev->flags) 728 if (!kthread_should_stop() && !dev->flags)
736 continue; 729 continue;
737 /* 730 /*
738 * Little race: we can create thread but not set the flag. 731 * Little race: we can create thread but not set the flag.
@@ -743,21 +736,12 @@ static int w1_control(void *data)
743 continue; 736 continue;
744 } 737 }
745 738
746 if (control_needs_exit) { 739 if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
747 set_bit(W1_MASTER_NEED_EXIT, &dev->flags); 740 set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
748 741
749 err = kill_proc(dev->kpid, SIGTERM, 1); 742 spin_lock(&w1_mlock);
750 if (err)
751 dev_err(&dev->dev,
752 "Failed to send signal to w1 kernel thread %d.\n",
753 dev->kpid);
754 }
755
756 if (test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
757 wait_for_completion(&dev->dev_exited);
758 spin_lock_bh(&w1_mlock);
759 list_del(&dev->w1_master_entry); 743 list_del(&dev->w1_master_entry);
760 spin_unlock_bh(&w1_mlock); 744 spin_unlock(&w1_mlock);
761 745
762 down(&dev->mutex); 746 down(&dev->mutex);
763 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { 747 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
@@ -789,7 +773,7 @@ static int w1_control(void *data)
789 } 773 }
790 } 774 }
791 775
792 complete_and_exit(&w1_control_complete, 0); 776 return 0;
793} 777}
794 778
795int w1_process(void *data) 779int w1_process(void *data)
@@ -797,17 +781,11 @@ int w1_process(void *data)
797 struct w1_master *dev = (struct w1_master *) data; 781 struct w1_master *dev = (struct w1_master *) data;
798 struct w1_slave *sl, *sln; 782 struct w1_slave *sl, *sln;
799 783
800 daemonize("%s", dev->name); 784 while (!kthread_should_stop() && !test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
801 allow_signal(SIGTERM);
802
803 while (!test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
804 try_to_freeze(); 785 try_to_freeze();
805 msleep_interruptible(w1_timeout * 1000); 786 msleep_interruptible(w1_timeout * 1000);
806 787
807 if (signal_pending(current)) 788 if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags))
808 flush_signals(current);
809
810 if (test_bit(W1_MASTER_NEED_EXIT, &dev->flags))
811 break; 789 break;
812 790
813 if (!dev->initialized) 791 if (!dev->initialized)
@@ -840,7 +818,6 @@ int w1_process(void *data)
840 } 818 }
841 819
842 atomic_dec(&dev->refcnt); 820 atomic_dec(&dev->refcnt);
843 complete_and_exit(&dev->dev_exited, 0);
844 821
845 return 0; 822 return 0;
846} 823}
@@ -873,11 +850,11 @@ static int w1_init(void)
873 goto err_out_master_unregister; 850 goto err_out_master_unregister;
874 } 851 }
875 852
876 control_thread = kernel_thread(&w1_control, NULL, 0); 853 w1_control_thread = kthread_run(w1_control, NULL, "w1_control");
877 if (control_thread < 0) { 854 if (IS_ERR(w1_control_thread)) {
855 retval = PTR_ERR(w1_control_thread);
878 printk(KERN_ERR "Failed to create control thread. err=%d\n", 856 printk(KERN_ERR "Failed to create control thread. err=%d\n",
879 control_thread); 857 retval);
880 retval = control_thread;
881 goto err_out_slave_unregister; 858 goto err_out_slave_unregister;
882 } 859 }
883 860
@@ -903,8 +880,7 @@ static void w1_fini(void)
903 list_for_each_entry(dev, &w1_masters, w1_master_entry) 880 list_for_each_entry(dev, &w1_masters, w1_master_entry)
904 __w1_remove_master_device(dev); 881 __w1_remove_master_device(dev);
905 882
906 control_needs_exit = 1; 883 kthread_stop(w1_control_thread);
907 wait_for_completion(&w1_control_complete);
908 884
909 driver_unregister(&w1_slave_driver); 885 driver_unregister(&w1_slave_driver);
910 driver_unregister(&w1_master_driver); 886 driver_unregister(&w1_master_driver);