]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Staging: rt2870: Revert d44ca7 Removal of kernel_thread() API
authorGreg Kroah-Hartman <gregkh@suse.de>
Fri, 31 Jul 2009 05:14:04 +0000 (07:14 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Sun, 16 Aug 2009 21:19:01 +0000 (14:19 -0700)
commit 2c63abf9e8a51dec886da482dfd8ae752581a61c upstream.

[Mike Galbraith did the upstream revert, which was more complex]

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.

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

index 9d59e3167fe452f4ac0bf2687bc5fb98fc77f2d8..04c764d95d77dede233a8f17ef9f8d943260a670 100644 (file)
@@ -265,7 +265,7 @@ INT MlmeThread(
         */
        DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__func__));
 
-       pObj->MLMEThr_task = NULL;
+       pObj->MLMEThr_pid = THREAD_PID_INIT_VALUE;
 
        complete_and_exit (&pAd->mlmeComplete, 0);
        return 0;
@@ -373,7 +373,7 @@ INT RTUSBCmdThread(
         */
        DBGPRINT(RT_DEBUG_TRACE,( "<---RTUSBCmdThread\n"));
 
-       pObj->RTUSBCmdThr_task = NULL;
+       pObj->RTUSBCmdThr_pid = THREAD_PID_INIT_VALUE;
 
        complete_and_exit (&pAd->CmdQComplete, 0);
        return 0;
@@ -467,7 +467,7 @@ INT TimerQThread(
         */
        DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__func__));
 
-       pObj->TimerQThr_task = NULL;
+       pObj->TimerQThr_pid = THREAD_PID_INIT_VALUE;
 
        complete_and_exit(&pAd->TimerQComplete, 0);
        return 0;
@@ -944,46 +944,69 @@ VOID RT28xxThreadTerminate(
        RTUSBCancelPendingIRPs(pAd);
 
        // Terminate Threads
-       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;
+       }
        }
 
 
@@ -1044,7 +1067,7 @@ BOOLEAN RT28XXChipsetCheck(
                if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor &&
                        dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct)
                {
-                       printk(KERN_DEBUG "rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
+                       printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
                                        dev_p->descriptor.idVendor, dev_p->descriptor.idProduct);
                        break;
                }
index cb16d2fcf60a8fd3ad10e42c5d7ca5b8263fb3d9..9f5143b3922e393f40eed49874f6e35fdf75fe42 100644 (file)
@@ -727,8 +727,8 @@ NDIS_STATUS AdapterBlockAllocateMemory(
 
        usb_dev = pObj->pUsb_Dev;
 
-       pObj->MLMEThr_task              = NULL;
-       pObj->RTUSBCmdThr_task  = NULL;
+       pObj->MLMEThr_pid               = THREAD_PID_INIT_VALUE;
+       pObj->RTUSBCmdThr_pid   = THREAD_PID_INIT_VALUE;
 
        *ppAd = (PVOID)vmalloc(sizeof(RTMP_ADAPTER));
 
@@ -765,7 +765,7 @@ NDIS_STATUS  CreateThreads(
 {
        PRTMP_ADAPTER pAd = net_dev->ml_priv;
        POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
-       struct task_struct *tsk;
+       pid_t pid_number = -1;
 
        //init_MUTEX(&(pAd->usbdev_semaphore));
 
@@ -779,39 +779,36 @@ NDIS_STATUS        CreateThreads(
        init_completion (&pAd->TimerQComplete);
 
        // Creat MLME Thread
-       pObj->MLMEThr_task = NULL;
-       tsk = kthread_run(MlmeThread, pAd, 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)
+       {
                printk (KERN_WARNING "%s: unable to start Mlme thread\n",pAd->net_dev->name);
                return NDIS_STATUS_FAILURE;
        }
-
-       pObj->MLMEThr_task = tsk;
+       pObj->MLMEThr_pid = GET_PID(pid_number);
        // Wait for the thread to start
        wait_for_completion(&(pAd->mlmeComplete));
 
        // Creat Command Thread
-       pObj->RTUSBCmdThr_task = NULL;
-       tsk = kthread_run(RTUSBCmdThread, pAd, 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)
        {
                printk (KERN_WARNING "%s: unable to start RTUSBCmd thread\n",pAd->net_dev->name);
                return NDIS_STATUS_FAILURE;
        }
-
-       pObj->RTUSBCmdThr_task = tsk;
+       pObj->RTUSBCmdThr_pid = GET_PID(pid_number);
        wait_for_completion(&(pAd->CmdQComplete));
 
-       pObj->TimerQThr_task = NULL;
-       tsk = kthread_run(TimerQThread, pAd, 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)
        {
                printk (KERN_WARNING "%s: unable to start TimerQThread\n",pAd->net_dev->name);
                return NDIS_STATUS_FAILURE;
        }
-       pObj->TimerQThr_task = tsk;
+       pObj->TimerQThr_pid = GET_PID(pid_number);
        // Wait for the thread to start
        wait_for_completion(&(pAd->TimerQComplete));
 
index f8e0ebd7bca94f33b8fec26ec62fe45a73395af9..fd809abf6df057e041305f8e950037d680942342 100644 (file)
@@ -709,6 +709,9 @@ BOOLEAN RTMP_FillTxBlkInfo(
        }
 
        return TRUE;
+
+FillTxBlkErr:
+       return FALSE;
 }
 
 
index 099b6a806f86d85635e601a177dbf8212284c5b7..870a00da3dacf6657083e40c82c21c753aac085c 100644 (file)
@@ -3655,7 +3655,7 @@ VOID      UserCfgInit(
 #ifdef RALINK_28xx_QA
        //pAd->ate.Repeat = 0;
        pAd->ate.TxStatus = 0;
-       pAd->ate.AtePid = NULL;
+       pAd->ate.AtePid = THREAD_PID_INIT_VALUE;
 #endif // RALINK_28xx_QA //
 #endif // RALINK_ATE //
 
index afde136a9a0c5834bcb8cc164e5b960af1fbd517..6db443e9268cff909315bea88292de834ea28676 100644 (file)
@@ -958,8 +958,7 @@ NDIS_STATUS RTUSBEnqueueCmdFromNdis(
        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)
                return (NDIS_STATUS_RESOURCES);
 
        status = RTMPAllocateMemory((PVOID *)&cmdqelmt, sizeof(CmdQElmt));
index fef14a4e2164b75b460a0e8722d9a686a0b5689a..39fa918dce1dc6ec9446f119c24e5f0cc26b673d 100644 (file)
@@ -580,16 +580,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)); \
 }
 
index 5a6ee6ad0e52f9f7ad9c4f21192d62b936c61e01..49ad37f0063707896e62c680da021222ebe078c5 100644 (file)
@@ -44,7 +44,6 @@
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/kernel.h>
-#include <linux/kthread.h>
 
 #include <linux/spinlock.h>
 #include <linux/init.h>
@@ -166,12 +165,14 @@ typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
 typedef        struct pid *    THREAD_PID;
+#define        THREAD_PID_INIT_VALUE   NULL
 #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)
 #define KILL_THREAD_PID(_A, _B, _C)    kill_pid(_A, _B, _C)
 #else
 typedef        pid_t   THREAD_PID;
+#define        THREAD_PID_INIT_VALUE   -1
 #define        GET_PID(_v)     _v
 #define        GET_PID_NUMBER(_v)      _v
 #define CHECK_PID_LEGALITY(_pid)       if (_pid >= 0)
@@ -187,11 +188,11 @@ struct os_lock  {
 struct os_cookie {
 
 #ifdef RT2870
-       struct usb_device       *pUsb_Dev;
+       struct usb_device               *pUsb_Dev;
 
-       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 // RT2870 //
 
        struct tasklet_struct   rx_done_task;