summaryrefslogtreecommitdiffstats
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.c49
1 files changed, 13 insertions, 36 deletions
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index c3f67eafc7ec..68565aacec7b 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -22,23 +22,15 @@
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/delay.h>
+#include <linux/kthread.h>
#include "w1.h"
#include "w1_log.h"
#include "w1_netlink.h"
+#include "w1_int.h"
static u32 w1_ids = 1;
-extern struct device_driver w1_master_driver;
-extern struct bus_type w1_bus_type;
-extern struct device w1_master_device;
-extern int w1_max_slave_count;
-extern int w1_max_slave_ttl;
-extern struct list_head w1_masters;
-extern spinlock_t w1_mlock;
-
-extern int w1_process(void *);
-
static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
struct device_driver *driver,
struct device *device)
@@ -65,7 +57,6 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
dev->max_slave_count = slave_count;
dev->slave_count = 0;
dev->attempts = 0;
- dev->kpid = -1;
dev->initialized = 0;
dev->id = id;
dev->slave_ttl = slave_ttl;
@@ -76,8 +67,6 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
INIT_LIST_HEAD(&dev->slist);
init_MUTEX(&dev->mutex);
- init_completion(&dev->dev_exited);
-
memcpy(&dev->dev, device, sizeof(struct device));
snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id),
"w1_bus_master%u", dev->id);
@@ -103,7 +92,7 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
return dev;
}
-void w1_free_dev(struct w1_master *dev)
+static void w1_free_dev(struct w1_master *dev)
{
device_unregister(&dev->dev);
}
@@ -125,12 +114,12 @@ int w1_add_master_device(struct w1_bus_master *master)
if (!dev)
return -ENOMEM;
- dev->kpid = kernel_thread(&w1_process, dev, 0);
- if (dev->kpid < 0) {
+ dev->thread = kthread_run(&w1_process, dev, "%s", dev->name);
+ if (IS_ERR(dev->thread)) {
+ retval = PTR_ERR(dev->thread);
dev_err(&dev->dev,
"Failed to create new kernel thread. err=%d\n",
- dev->kpid);
- retval = dev->kpid;
+ retval);
goto err_out_free_dev;
}
@@ -147,20 +136,14 @@ int w1_add_master_device(struct w1_bus_master *master)
spin_unlock(&w1_mlock);
msg.id.mst.id = dev->id;
- msg.id.mst.pid = dev->kpid;
+ msg.id.mst.pid = dev->thread->pid;
msg.type = W1_MASTER_ADD;
w1_netlink_send(dev, &msg);
return 0;
err_out_kill_thread:
- set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
- if (kill_proc(dev->kpid, SIGTERM, 1))
- dev_err(&dev->dev,
- "Failed to send signal to w1 kernel thread %d.\n",
- dev->kpid);
- wait_for_completion(&dev->dev_exited);
-
+ kthread_stop(dev->thread);
err_out_free_dev:
w1_free_dev(dev);
@@ -169,18 +152,14 @@ err_out_free_dev:
void __w1_remove_master_device(struct w1_master *dev)
{
- int err;
struct w1_netlink_msg msg;
+ pid_t pid = dev->thread->pid;
set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
- err = kill_proc(dev->kpid, SIGTERM, 1);
- if (err)
- dev_err(&dev->dev,
- "%s: Failed to send signal to w1 kernel thread %d.\n",
- __func__, dev->kpid);
+ kthread_stop(dev->thread);
while (atomic_read(&dev->refcnt)) {
- dev_dbg(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n",
+ dev_info(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n",
dev->name, atomic_read(&dev->refcnt));
if (msleep_interruptible(1000))
@@ -188,7 +167,7 @@ void __w1_remove_master_device(struct w1_master *dev)
}
msg.id.mst.id = dev->id;
- msg.id.mst.pid = dev->kpid;
+ msg.id.mst.pid = pid;
msg.type = W1_MASTER_REMOVE;
w1_netlink_send(dev, &msg);
@@ -217,5 +196,3 @@ void w1_remove_master_device(struct w1_bus_master *bm)
EXPORT_SYMBOL(w1_add_master_device);
EXPORT_SYMBOL(w1_remove_master_device);
-
-MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_W1);