Skip to content

Commit

Permalink
USB: usbatm: convert heavy init dances to kthread API
Browse files Browse the repository at this point in the history
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: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: Duncan Sands <baldrick@free.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Pavel Emelyanov authored and Greg Kroah-Hartman committed Apr 25, 2008
1 parent 1409e8e commit c4504a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions drivers/usb/atm/usbatm.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#include <linux/stat.h>
#include <linux/timer.h>
#include <linux/wait.h>
#include <linux/kthread.h>

#ifdef VERBOSE_DEBUG
static int usbatm_print_packet(const unsigned char *data, int len);
Expand Down Expand Up @@ -1014,10 +1015,7 @@ static int usbatm_do_heavy_init(void *arg)
struct usbatm_data *instance = arg;
int ret;

daemonize(instance->driver->driver_name);
allow_signal(SIGTERM);
instance->thread_pid = current->pid;

complete(&instance->thread_started);

ret = instance->driver->heavy_init(instance, instance->usb_intf);
Expand All @@ -1026,21 +1024,26 @@ static int usbatm_do_heavy_init(void *arg)
ret = usbatm_atm_init(instance);

mutex_lock(&instance->serialize);
instance->thread_pid = -1;
instance->thread = NULL;
mutex_unlock(&instance->serialize);

complete_and_exit(&instance->thread_exited, ret);
}

static int usbatm_heavy_init(struct usbatm_data *instance)
{
int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_FS | CLONE_FILES);

if (ret < 0) {
usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
return ret;
struct task_struct *t;

t = kthread_create(usbatm_do_heavy_init, instance,
instance->driver->driver_name);
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);

return 0;
Expand Down Expand Up @@ -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 */
mutex_init(&instance->serialize);

instance->thread_pid = -1;
instance->thread = NULL;
init_completion(&instance->thread_started);
init_completion(&instance->thread_exited);

Expand Down Expand Up @@ -1287,8 +1290,8 @@ void usbatm_usb_disconnect(struct usb_interface *intf)

mutex_lock(&instance->serialize);
instance->disconnected = 1;
if (instance->thread_pid >= 0)
kill_proc(instance->thread_pid, SIGTERM, 1);
if (instance->thread != NULL)
send_sig(SIGTERM, instance->thread, 1);
mutex_unlock(&instance->serialize);

wait_for_completion(&instance->thread_exited);
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/atm/usbatm.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct usbatm_data {
int disconnected;

/* heavy init */
int thread_pid;
struct task_struct *thread;
struct completion thread_started;
struct completion thread_exited;

Expand Down

0 comments on commit c4504a7

Please sign in to comment.