Staging: rt2870: Revert d44ca7 Removal of kernel_thread() API
authorMike Galbraith <efault@gmx.de>
Fri, 31 Jul 2009 05:14:04 +0000 (07:14 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 7 Aug 2009 23:12:02 +0000 (16:12 -0700)
Staging: rt2870: Revert d44ca7 Removal of kernel_thread() API

The sanity check this patch introduced triggers on shutdown, apparently due to
threads having already exited by the time BUG_ON() is reached.

Signed-off-by: Mike Galbraith <efault@gmx.de>
Cc: Peter Teoh <htmldeveloper@gmail.com>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/rt2860/rt_linux.h
drivers/staging/rt2870/2870_main_dev.c
drivers/staging/rt2870/common/2870_rtmp_init.c
drivers/staging/rt2870/common/rtusb_io.c
drivers/staging/rt2870/rt2870.h

index 85175c1824328f58d3aa652de7240bdd6ab5bf2b..25b53ac3f8204f9484e002beaedf77db6d5acb3e 100644 (file)
@@ -43,9 +43,6 @@
 #include "rtmp_type.h"
 #include <linux/module.h>
 #include <linux/kernel.h>
-#if !defined(RT2860) && !defined(RT30xx)
-#include <linux/kthread.h>
-#endif
 
 #include <linux/spinlock.h>
 #include <linux/init.h>
@@ -166,9 +163,7 @@ typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_
 
 #ifndef RT30xx
 typedef        struct pid *    THREAD_PID;
-#ifdef RT2860
 #define        THREAD_PID_INIT_VALUE   NULL
-#endif
 #define        GET_PID(_v)     find_get_pid(_v)
 #define        GET_PID_NUMBER(_v)      pid_nr(_v)
 #define CHECK_PID_LEGALITY(_pid)       if (pid_nr(_pid) >= 0)
@@ -188,12 +183,12 @@ struct os_cookie {
        dma_addr_t                              pAd_pa;
 #endif
 #ifdef RT2870
-       struct usb_device       *pUsb_Dev;
+       struct usb_device               *pUsb_Dev;
 
 #ifndef RT30xx
-       struct task_struct      *MLMEThr_task;
-       struct task_struct      *RTUSBCmdThr_task;
-       struct task_struct      *TimerQThr_task;
+       THREAD_PID                              MLMEThr_pid;
+       THREAD_PID                              RTUSBCmdThr_pid;
+       THREAD_PID                              TimerQThr_pid;
 #endif
 #ifdef RT30xx
        struct pid      *MLMEThr_pid;
index dd01c64fbf61fd09432cc6d0452213239d4801eb..a4e8696ca39c4dba233fb9851af7146a2cc88ab7 100644 (file)
@@ -235,7 +235,7 @@ INT MlmeThread(
        DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__func__));
 
 #ifndef RT30xx
-       pObj->MLMEThr_task = NULL;
+       pObj->MLMEThr_pid = THREAD_PID_INIT_VALUE;
 #endif
 #ifdef RT30xx
        pObj->MLMEThr_pid = NULL;
@@ -348,7 +348,7 @@ INT RTUSBCmdThread(
        DBGPRINT(RT_DEBUG_TRACE,( "<---RTUSBCmdThread\n"));
 
 #ifndef RT30xx
-       pObj->RTUSBCmdThr_task = NULL;
+       pObj->RTUSBCmdThr_pid = THREAD_PID_INIT_VALUE;
 #endif
 #ifdef RT30xx
        pObj->RTUSBCmdThr_pid = NULL;
@@ -447,7 +447,7 @@ INT TimerQThread(
        DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__func__));
 
 #ifndef RT30xx
-       pObj->TimerQThr_task = NULL;
+       pObj->TimerQThr_pid = THREAD_PID_INIT_VALUE;
 #endif
 #ifdef RT30xx
        pObj->TimerQThr_pid = NULL;
@@ -883,46 +883,69 @@ VOID RT28xxThreadTerminate(
 
        // Terminate Threads
 #ifndef RT30xx
-       BUG_ON(pObj->TimerQThr_task == NULL);
-       CHECK_PID_LEGALITY(task_pid(pObj->TimerQThr_task))
+       CHECK_PID_LEGALITY(pObj->TimerQThr_pid)
        {
                POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;
 
-               printk(KERN_DEBUG "Terminate the TimerQThr pid=%d!\n",
-                       pid_nr(task_pid(pObj->TimerQThr_task)));
+               printk("Terminate the TimerQThr_pid=%d!\n", GET_PID_NUMBER(pObj->TimerQThr_pid));
                mb();
                pAd->TimerFunc_kill = 1;
                mb();
-               kthread_stop(pObj->TimerQThr_task);
-               pObj->TimerQThr_task = NULL;
+               ret = KILL_THREAD_PID(pObj->TimerQThr_pid, SIGTERM, 1);
+               if (ret)
+               {
+                       printk(KERN_WARNING "%s: unable to stop TimerQThread, pid=%d, ret=%d!\n",
+                                       pAd->net_dev->name, GET_PID_NUMBER(pObj->TimerQThr_pid), ret);
+               }
+               else
+               {
+                       wait_for_completion(&pAd->TimerQComplete);
+                       pObj->TimerQThr_pid = THREAD_PID_INIT_VALUE;
+               }
        }
 
-       BUG_ON(pObj->MLMEThr_task == NULL);
-       CHECK_PID_LEGALITY(task_pid(pObj->MLMEThr_task))
+       CHECK_PID_LEGALITY(pObj->MLMEThr_pid)
        {
-               printk(KERN_DEBUG "Terminate the MLMEThr pid=%d!\n",
-                       pid_nr(task_pid(pObj->MLMEThr_task)));
+               printk("Terminate the MLMEThr_pid=%d!\n", GET_PID_NUMBER(pObj->MLMEThr_pid));
                mb();
                pAd->mlme_kill = 1;
                //RT28XX_MLME_HANDLER(pAd);
                mb();
-               kthread_stop(pObj->MLMEThr_task);
-               pObj->MLMEThr_task = NULL;
+               ret = KILL_THREAD_PID(pObj->MLMEThr_pid, SIGTERM, 1);
+               if (ret)
+               {
+                       printk (KERN_WARNING "%s: unable to Mlme thread, pid=%d, ret=%d!\n",
+                                       pAd->net_dev->name, GET_PID_NUMBER(pObj->MLMEThr_pid), ret);
+               }
+               else
+               {
+                       //wait_for_completion (&pAd->notify);
+                       wait_for_completion (&pAd->mlmeComplete);
+                       pObj->MLMEThr_pid = THREAD_PID_INIT_VALUE;
+               }
        }
 
-       BUG_ON(pObj->RTUSBCmdThr_task == NULL);
-       CHECK_PID_LEGALITY(task_pid(pObj->RTUSBCmdThr_task))
+       CHECK_PID_LEGALITY(pObj->RTUSBCmdThr_pid)
        {
-               printk(KERN_DEBUG "Terminate the RTUSBCmdThr pid=%d!\n",
-                       pid_nr(task_pid(pObj->RTUSBCmdThr_task)));
+               printk("Terminate the RTUSBCmdThr_pid=%d!\n", GET_PID_NUMBER(pObj->RTUSBCmdThr_pid));
                mb();
                NdisAcquireSpinLock(&pAd->CmdQLock);
                pAd->CmdQ.CmdQState = RT2870_THREAD_STOPED;
                NdisReleaseSpinLock(&pAd->CmdQLock);
                mb();
                //RTUSBCMDUp(pAd);
-               kthread_stop(pObj->RTUSBCmdThr_task);
-               pObj->RTUSBCmdThr_task = NULL;
+               ret = KILL_THREAD_PID(pObj->RTUSBCmdThr_pid, SIGTERM, 1);
+               if (ret)
+               {
+                       printk(KERN_WARNING "%s: unable to RTUSBCmd thread, pid=%d, ret=%d!\n",
+                                       pAd->net_dev->name, GET_PID_NUMBER(pObj->RTUSBCmdThr_pid), ret);
+               }
+               else
+               {
+                       //wait_for_completion (&pAd->notify);
+                       wait_for_completion (&pAd->CmdQComplete);
+                       pObj->RTUSBCmdThr_pid = THREAD_PID_INIT_VALUE;
+               }
        }
 #endif
 #ifdef RT30xx
@@ -1045,7 +1068,7 @@ BOOLEAN RT28XXChipsetCheck(
                        dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct)
                {
 #ifndef RT30xx
-                       printk(KERN_DEBUG "rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
+                       printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
 #endif
 #ifdef RT30xx
                        printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
index 0f4c8af97e47f5c5b06f4f4b80ebbddcc7ed81b9..80909e9ab5aea5469dd2b60a29f35e8edef7b93f 100644 (file)
@@ -700,8 +700,8 @@ NDIS_STATUS AdapterBlockAllocateMemory(
        usb_dev = pObj->pUsb_Dev;
 
 #ifndef RT30xx
-       pObj->MLMEThr_task              = NULL;
-       pObj->RTUSBCmdThr_task  = NULL;
+       pObj->MLMEThr_pid               = THREAD_PID_INIT_VALUE;
+       pObj->RTUSBCmdThr_pid   = THREAD_PID_INIT_VALUE;
 #endif
 #ifdef RT30xx
        pObj->MLMEThr_pid       = NULL;
@@ -743,7 +743,7 @@ NDIS_STATUS  CreateThreads(
        PRTMP_ADAPTER pAd = net_dev->ml_priv;
        POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
 #ifndef RT30xx
-       struct task_struct *tsk;
+       pid_t pid_number = -1;
 #endif
 #ifdef RT30xx
        pid_t pid_number;
@@ -762,10 +762,10 @@ NDIS_STATUS        CreateThreads(
 
        // Creat MLME Thread
 #ifndef RT30xx
-       pObj->MLMEThr_task = NULL;
-       tsk = kthread_run(MlmeThread, pAd, "%s", pAd->net_dev->name);
-
-       if (IS_ERR(tsk)) {
+       pObj->MLMEThr_pid= THREAD_PID_INIT_VALUE;
+       pid_number = kernel_thread(MlmeThread, pAd, CLONE_VM);
+       if (pid_number < 0)
+       {
 #endif
 #ifdef RT30xx
        pObj->MLMEThr_pid = NULL;
@@ -778,7 +778,7 @@ NDIS_STATUS  CreateThreads(
        }
 
 #ifndef RT30xx
-       pObj->MLMEThr_task = tsk;
+       pObj->MLMEThr_pid = GET_PID(pid_number);
 #endif
 #ifdef RT30xx
        pObj->MLMEThr_pid = find_get_pid(pid_number);
@@ -788,10 +788,9 @@ NDIS_STATUS         CreateThreads(
 
        // Creat Command Thread
 #ifndef RT30xx
-       pObj->RTUSBCmdThr_task = NULL;
-       tsk = kthread_run(RTUSBCmdThread, pAd, "%s", pAd->net_dev->name);
-
-       if (IS_ERR(tsk) < 0)
+       pObj->RTUSBCmdThr_pid= THREAD_PID_INIT_VALUE;
+       pid_number = kernel_thread(RTUSBCmdThread, pAd, CLONE_VM);
+       if (pid_number < 0)
 #endif
 #ifdef RT30xx
        pObj->RTUSBCmdThr_pid = NULL;
@@ -804,7 +803,7 @@ NDIS_STATUS  CreateThreads(
        }
 
 #ifndef RT30xx
-       pObj->RTUSBCmdThr_task = tsk;
+       pObj->RTUSBCmdThr_pid = GET_PID(pid_number);
 #endif
 #ifdef RT30xx
        pObj->RTUSBCmdThr_pid = find_get_pid(pid_number);
@@ -812,9 +811,9 @@ NDIS_STATUS  CreateThreads(
        wait_for_completion(&(pAd->CmdQComplete));
 
 #ifndef RT30xx
-       pObj->TimerQThr_task = NULL;
-       tsk = kthread_run(TimerQThread, pAd, "%s", pAd->net_dev->name);
-       if (IS_ERR(tsk) < 0)
+       pObj->TimerQThr_pid= THREAD_PID_INIT_VALUE;
+       pid_number = kernel_thread(TimerQThread, pAd, CLONE_VM);
+       if (pid_number < 0)
 #endif
 #ifdef RT30xx
        pObj->TimerQThr_pid = NULL;
@@ -826,7 +825,7 @@ NDIS_STATUS  CreateThreads(
                return NDIS_STATUS_FAILURE;
        }
 #ifndef RT30xx
-       pObj->TimerQThr_task = tsk;
+       pObj->TimerQThr_pid = GET_PID(pid_number);
 #endif
 #ifdef RT30xx
        pObj->TimerQThr_pid = find_get_pid(pid_number);
index fd1b0c18f2a007633a733807e76cb8e2620c9a13..704b5c2d5091a1327492f509c16e2b4d4a798075 100644 (file)
@@ -984,8 +984,7 @@ NDIS_STATUS RTUSBEnqueueCmdFromNdis(
        POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
 
 #ifndef RT30xx
-       BUG_ON(pObj->RTUSBCmdThr_task == NULL);
-       CHECK_PID_LEGALITY(task_pid(pObj->RTUSBCmdThr_task))
+       CHECK_PID_LEGALITY(pObj->RTUSBCmdThr_pid)
 #endif
 #ifdef RT30xx
        if (pObj->RTUSBCmdThr_pid < 0)
index 10e1640d61e5072fd071ba430d959c055a942726..2b8872b2fd9dcf116522cd90efe206e9f9ae51ff 100644 (file)
@@ -590,16 +590,14 @@ VOID RTUSBBulkRxComplete(purbb_t pUrb, struct pt_regs *pt_regs);
 #define RTUSBMlmeUp(pAd)               \
 {                                                                  \
        POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;  \
-       BUG_ON(pObj->MLMEThr_task == NULL);                 \
-       CHECK_PID_LEGALITY(task_pid(pObj->MLMEThr_task))                    \
+       CHECK_PID_LEGALITY(pObj->MLMEThr_pid)               \
         up(&(pAd->mlme_semaphore)); \
 }
 
 #define RTUSBCMDUp(pAd)                        \
 {                                                                          \
        POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;  \
-       BUG_ON(pObj->RTUSBCmdThr_task == NULL);     \
-       CHECK_PID_LEGALITY(task_pid(pObj->RTUSBCmdThr_task))        \
+       CHECK_PID_LEGALITY(pObj->RTUSBCmdThr_pid)           \
            up(&(pAd->RTUSBCmd_semaphore)); \
 }
 #endif