speedtch usbatm.h,1.3,1.4 usbatm2.c,1.12,1.13
Duncan Sands
duncan at infradead.org
Fri Jan 28 06:03:46 EST 2005
Update of /home/cvs/speedtch
In directory phoenix.infradead.org:/tmp/cvs-serv16618
Modified Files:
usbatm.h usbatm2.c
Log Message:
Manage our own kernel thread, much the same as Roman's patch except that we
shoot the thread down with SIGTERM. This is racy though:
(1) the thread may have finished and someone may be using the pid -> we shoot
down the wrong process.
(2) between the call to daemonize and the call to allow_signal, there is a small
window where we don't accept any signals - an attempt to shoot it down at that
precise instant will fail.
Also, we allow SIGTERM, but maybe we should allow SIGKILL also?
Index: usbatm.h
===================================================================
RCS file: /home/cvs/speedtch/usbatm.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- usbatm.h 25 Jan 2005 08:18:09 -0000 1.3
+++ usbatm.h 28 Jan 2005 11:03:43 -0000 1.4
@@ -156,8 +156,9 @@
struct usbatm_driver *driver;
void *driver_data;
- /* heavy thread part */
- struct task_struct *kthread;
+ /* heavy init part */
+ int thread_pid;
+ struct completion thread_exited;
/* USB device part */
struct usb_device *usb_dev;
Index: usbatm2.c
===================================================================
RCS file: /home/cvs/speedtch/usbatm2.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- usbatm2.c 28 Jan 2005 10:13:00 -0000 1.12
+++ usbatm2.c 28 Jan 2005 11:03:43 -0000 1.13
@@ -62,29 +62,27 @@
*
*/
-#define CONFIG_USB_SPEEDTOUCH // QQ remove!
-#define CONFIG_USB_CXACRU // QQ remove!
-
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/kthread.h>
-#include <linux/sched.h>
-#include <linux/timer.h>
-#include <linux/errno.h>
-#include <linux/proc_fs.h>
-#include <linux/slab.h>
-#include <linux/wait.h>
-#include <linux/list.h>
#include <asm/uaccess.h>
-#include <linux/smp_lock.h>
-#include <linux/interrupt.h>
#include <linux/atm.h>
#include <linux/atmdev.h>
+#include <linux/completion.h>
+#include <linux/config.h>
#include <linux/crc32.h>
-#include <linux/init.h>
+#include <linux/errno.h>
#include <linux/firmware.h>
-#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/proc_fs.h>
+#include <linux/sched.h>
+#include <linux/signal.h>
+#include <linux/slab.h>
+#include <linux/smp_lock.h>
+#include <linux/timer.h>
+#include <linux/wait.h>
#include "usbatm.h"
@@ -1020,28 +1018,27 @@
struct usbatm_data *instance = arg;
int ret;
+ daemonize("%s/%s", usbatm_driver_name, instance->driver->driver_name);
+ allow_signal(SIGTERM);
+
ret = instance->driver->heavy_init(instance, instance->usb_intf);
if (!ret)
ret = usbatm_atm_init(instance);
- return ret;
+ complete_and_exit(&instance->thread_exited, ret);
}
-static long usbatm_heavy_init(struct usbatm_data *instance)
+static int usbatm_heavy_init(struct usbatm_data *instance)
{
- struct task_struct *kthread;
+ int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_FS | CLONE_FILES);
- kthread = kthread_create(usbatm_do_heavy_init, instance, "%s/%s", usbatm_driver_name, instance->driver->driver_name);
-
- if (IS_ERR(kthread)) {
- dbg("usbatm_heavy_init: kernel_thread failed (%ld)!", PTR_ERR(kthread));
- return PTR_ERR(kthread);
+ if (ret < 0) {
+ dbg("usbatm_heavy_init: failed to create kernel_thread (%d)!", ret);
+ return ret;
}
- instance->kthread = kthread;
- mb();
- wake_up_process(kthread);
+ instance->thread_pid = ret;
return 0;
}
@@ -1078,6 +1075,9 @@
instance->driver = driver;
+ instance->thread_pid = -1;
+ init_completion(&instance->thread_exited);
+
instance->usb_dev = dev;
instance->usb_intf = intf;
instance->tx_endpoint = usb_sndbulkpipe(dev, driver->out);
@@ -1241,8 +1241,10 @@
if (instance->atm_dev && instance->driver->atm_stop)
instance->driver->atm_stop(instance, instance->atm_dev);
- if (instance->kthread)
- kthread_stop(instance->kthread);
+ if (instance->thread_pid >= 0) {
+ kill_proc(instance->thread_pid, SIGTERM, 1);
+ wait_for_completion(&instance->thread_exited);
+ }
if (instance->driver->unbind)
instance->driver->unbind(instance, intf);
More information about the Usbatm-commits
mailing list