aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/w1_int.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/w1/w1_int.c')
-rw-r--r--drivers/w1/w1_int.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index a2f9065e1928..68565aacec7b 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -22,6 +22,7 @@
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/kthread.h>
25 26
26#include "w1.h" 27#include "w1.h"
27#include "w1_log.h" 28#include "w1_log.h"
@@ -56,7 +57,6 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
56 dev->max_slave_count = slave_count; 57 dev->max_slave_count = slave_count;
57 dev->slave_count = 0; 58 dev->slave_count = 0;
58 dev->attempts = 0; 59 dev->attempts = 0;
59 dev->kpid = -1;
60 dev->initialized = 0; 60 dev->initialized = 0;
61 dev->id = id; 61 dev->id = id;
62 dev->slave_ttl = slave_ttl; 62 dev->slave_ttl = slave_ttl;
@@ -67,8 +67,6 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
67 INIT_LIST_HEAD(&dev->slist); 67 INIT_LIST_HEAD(&dev->slist);
68 init_MUTEX(&dev->mutex); 68 init_MUTEX(&dev->mutex);
69 69
70 init_completion(&dev->dev_exited);
71
72 memcpy(&dev->dev, device, sizeof(struct device)); 70 memcpy(&dev->dev, device, sizeof(struct device));
73 snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id), 71 snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id),
74 "w1_bus_master%u", dev->id); 72 "w1_bus_master%u", dev->id);
@@ -116,12 +114,12 @@ int w1_add_master_device(struct w1_bus_master *master)
116 if (!dev) 114 if (!dev)
117 return -ENOMEM; 115 return -ENOMEM;
118 116
119 dev->kpid = kernel_thread(&w1_process, dev, 0); 117 dev->thread = kthread_run(&w1_process, dev, "%s", dev->name);
120 if (dev->kpid < 0) { 118 if (IS_ERR(dev->thread)) {
119 retval = PTR_ERR(dev->thread);
121 dev_err(&dev->dev, 120 dev_err(&dev->dev,
122 "Failed to create new kernel thread. err=%d\n", 121 "Failed to create new kernel thread. err=%d\n",
123 dev->kpid); 122 retval);
124 retval = dev->kpid;
125 goto err_out_free_dev; 123 goto err_out_free_dev;
126 } 124 }
127 125
@@ -138,20 +136,14 @@ int w1_add_master_device(struct w1_bus_master *master)
138 spin_unlock(&w1_mlock); 136 spin_unlock(&w1_mlock);
139 137
140 msg.id.mst.id = dev->id; 138 msg.id.mst.id = dev->id;
141 msg.id.mst.pid = dev->kpid; 139 msg.id.mst.pid = dev->thread->pid;
142 msg.type = W1_MASTER_ADD; 140 msg.type = W1_MASTER_ADD;
143 w1_netlink_send(dev, &msg); 141 w1_netlink_send(dev, &msg);
144 142
145 return 0; 143 return 0;
146 144
147err_out_kill_thread: 145err_out_kill_thread:
148 set_bit(W1_MASTER_NEED_EXIT, &dev->flags); 146 kthread_stop(dev->thread);
149 if (kill_proc(dev->kpid, SIGTERM, 1))
150 dev_err(&dev->dev,
151 "Failed to send signal to w1 kernel thread %d.\n",
152 dev->kpid);
153 wait_for_completion(&dev->dev_exited);
154
155err_out_free_dev: 147err_out_free_dev:
156 w1_free_dev(dev); 148 w1_free_dev(dev);
157 149
@@ -160,18 +152,14 @@ err_out_free_dev:
160 152
161void __w1_remove_master_device(struct w1_master *dev) 153void __w1_remove_master_device(struct w1_master *dev)
162{ 154{
163 int err;
164 struct w1_netlink_msg msg; 155 struct w1_netlink_msg msg;
156 pid_t pid = dev->thread->pid;
165 157
166 set_bit(W1_MASTER_NEED_EXIT, &dev->flags); 158 set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
167 err = kill_proc(dev->kpid, SIGTERM, 1); 159 kthread_stop(dev->thread);
168 if (err)
169 dev_err(&dev->dev,
170 "%s: Failed to send signal to w1 kernel thread %d.\n",
171 __func__, dev->kpid);
172 160
173 while (atomic_read(&dev->refcnt)) { 161 while (atomic_read(&dev->refcnt)) {
174 dev_dbg(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n", 162 dev_info(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n",
175 dev->name, atomic_read(&dev->refcnt)); 163 dev->name, atomic_read(&dev->refcnt));
176 164
177 if (msleep_interruptible(1000)) 165 if (msleep_interruptible(1000))
@@ -179,7 +167,7 @@ void __w1_remove_master_device(struct w1_master *dev)
179 } 167 }
180 168
181 msg.id.mst.id = dev->id; 169 msg.id.mst.id = dev->id;
182 msg.id.mst.pid = dev->kpid; 170 msg.id.mst.pid = pid;
183 msg.type = W1_MASTER_REMOVE; 171 msg.type = W1_MASTER_REMOVE;
184 w1_netlink_send(dev, &msg); 172 w1_netlink_send(dev, &msg);
185 173