Commit c4504a7e authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Greg Kroah-Hartman

USB: usbatm: convert heavy init dances to kthread API

This is an attempt to kill two birds with one stone.

First, we kill one more user of kernel_thread, which is scheduled
for removal. Second - we kill one of the last users of kill_proc -
the function which is also to be removed, because it uses a pid_t
which is not safe now.
Signed-off-by: default avatarPavel Emelyanov <xemul@openvz.org>
Signed-off-by: default avatarDuncan Sands <baldrick@free.fr>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 1409e8e0
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/kthread.h>
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
static int usbatm_print_packet(const unsigned char *data, int len); static int usbatm_print_packet(const unsigned char *data, int len);
...@@ -1014,10 +1015,7 @@ static int usbatm_do_heavy_init(void *arg) ...@@ -1014,10 +1015,7 @@ static int usbatm_do_heavy_init(void *arg)
struct usbatm_data *instance = arg; struct usbatm_data *instance = arg;
int ret; int ret;
daemonize(instance->driver->driver_name);
allow_signal(SIGTERM); allow_signal(SIGTERM);
instance->thread_pid = current->pid;
complete(&instance->thread_started); complete(&instance->thread_started);
ret = instance->driver->heavy_init(instance, instance->usb_intf); ret = instance->driver->heavy_init(instance, instance->usb_intf);
...@@ -1026,7 +1024,7 @@ static int usbatm_do_heavy_init(void *arg) ...@@ -1026,7 +1024,7 @@ static int usbatm_do_heavy_init(void *arg)
ret = usbatm_atm_init(instance); ret = usbatm_atm_init(instance);
mutex_lock(&instance->serialize); mutex_lock(&instance->serialize);
instance->thread_pid = -1; instance->thread = NULL;
mutex_unlock(&instance->serialize); mutex_unlock(&instance->serialize);
complete_and_exit(&instance->thread_exited, ret); complete_and_exit(&instance->thread_exited, ret);
...@@ -1034,13 +1032,18 @@ static int usbatm_do_heavy_init(void *arg) ...@@ -1034,13 +1032,18 @@ static int usbatm_do_heavy_init(void *arg)
static int usbatm_heavy_init(struct usbatm_data *instance) static int usbatm_heavy_init(struct usbatm_data *instance)
{ {
int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_FS | CLONE_FILES); struct task_struct *t;
if (ret < 0) { t = kthread_create(usbatm_do_heavy_init, instance,
usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret); instance->driver->driver_name);
return ret; if (IS_ERR(t)) {
usb_err(instance, "%s: failed to create kernel_thread (%ld)!\n",
__func__, PTR_ERR(t));
return PTR_ERR(t);
} }
instance->thread = t;
wake_up_process(t);
wait_for_completion(&instance->thread_started); wait_for_completion(&instance->thread_started);
return 0; return 0;
...@@ -1124,7 +1127,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id, ...@@ -1124,7 +1127,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */ kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */
mutex_init(&instance->serialize); mutex_init(&instance->serialize);
instance->thread_pid = -1; instance->thread = NULL;
init_completion(&instance->thread_started); init_completion(&instance->thread_started);
init_completion(&instance->thread_exited); init_completion(&instance->thread_exited);
...@@ -1287,8 +1290,8 @@ void usbatm_usb_disconnect(struct usb_interface *intf) ...@@ -1287,8 +1290,8 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
mutex_lock(&instance->serialize); mutex_lock(&instance->serialize);
instance->disconnected = 1; instance->disconnected = 1;
if (instance->thread_pid >= 0) if (instance->thread != NULL)
kill_proc(instance->thread_pid, SIGTERM, 1); send_sig(SIGTERM, instance->thread, 1);
mutex_unlock(&instance->serialize); mutex_unlock(&instance->serialize);
wait_for_completion(&instance->thread_exited); wait_for_completion(&instance->thread_exited);
......
...@@ -175,7 +175,7 @@ struct usbatm_data { ...@@ -175,7 +175,7 @@ struct usbatm_data {
int disconnected; int disconnected;
/* heavy init */ /* heavy init */
int thread_pid; struct task_struct *thread;
struct completion thread_started; struct completion thread_started;
struct completion thread_exited; struct completion thread_exited;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment