Merge branches 'irq-core-for-linus' and 'core-locking-for-linus' of git://git.kernel...
[pandora-kernel.git] / drivers / staging / brcm80211 / brcmfmac / dhd_linux.c
index cb7af02..bbbe7c5 100644 (file)
 #ifdef CONFIG_WIFI_CONTROL_FUNC
 #include <linux/platform_device.h>
 #endif
-#include <typedefs.h>
-#include <linuxver.h>
-#include <osl.h>
-
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/kthread.h>
 #include <linux/ethtool.h>
 #include <linux/fcntl.h>
 #include <linux/fs.h>
-
 #include <linux/uaccess.h>
+#include <bcmdefs.h>
+#include <linuxver.h>
+#include <osl.h>
 #include <bcmutils.h>
 #include <bcmendian.h>
 
@@ -171,7 +169,7 @@ void wifi_del_dev(void)
 
 #if defined(CONFIG_PM_SLEEP)
 #include <linux/suspend.h>
-volatile bool dhd_mmc_suspend = FALSE;
+volatile bool dhd_mmc_suspend = false;
 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
 #endif /*  defined(CONFIG_PM_SLEEP) */
 
@@ -246,9 +244,8 @@ typedef struct dhd_info {
        struct semaphore dpc_sem;
 
        /* Thread to issue ioctl for multicast */
-       long sysioc_pid;
+       struct task_struct *sysioc_tsk;
        struct semaphore sysioc_sem;
-       struct completion sysioc_exited;
        bool set_multicast;
        bool set_macaddress;
        struct ether_addr macvalue;
@@ -274,7 +271,7 @@ module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
 module_param(dhd_msg_level, int, 0);
 
 /* Spawn a thread for system ioctls (set mac, set mcast) */
-uint dhd_sysioc = TRUE;
+uint dhd_sysioc = true;
 module_param(dhd_sysioc, uint, 0);
 
 /* Watchdog interval */
@@ -293,11 +290,11 @@ uint dhd_arp_mode = 0xb;
 module_param(dhd_arp_mode, uint, 0);
 
 /* ARP offload enable */
-uint dhd_arp_enable = TRUE;
+uint dhd_arp_enable = true;
 module_param(dhd_arp_enable, uint, 0);
 
 /* Global Pkt filter enable control */
-uint dhd_pkt_filter_enable = TRUE;
+uint dhd_pkt_filter_enable = true;
 module_param(dhd_pkt_filter_enable, uint, 0);
 
 /*  Pkt filter init setup */
@@ -305,7 +302,7 @@ uint dhd_pkt_filter_init;
 module_param(dhd_pkt_filter_init, uint, 0);
 
 /* Pkt filter mode control */
-uint dhd_master_mode = TRUE;
+uint dhd_master_mode = true;
 module_param(dhd_master_mode, uint, 1);
 
 /* Watchdog thread priority, -1 to use kernel timer */
@@ -334,15 +331,6 @@ uint dhd_radio_up = 1;
 char iface_name[IFNAMSIZ];
 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
 
-#define DAEMONIZE(a) \
-       do { \
-               daemonize(a); \
-               allow_signal(SIGKILL); \
-               allow_signal(SIGTERM); \
-       } while (0)
-
-#define BLOCKABLE()    (!in_atomic())
-
 /* The following are specific to the SDIO dongle */
 
 /* IOCTL response timeout */
@@ -353,15 +341,15 @@ int dhd_idletime = DHD_IDLETIME_TICKS;
 module_param(dhd_idletime, int, 0);
 
 /* Use polling */
-uint dhd_poll = FALSE;
+uint dhd_poll = false;
 module_param(dhd_poll, uint, 0);
 
 /* Use cfg80211 */
-uint dhd_cfg80211 = TRUE;
+uint dhd_cfg80211 = true;
 module_param(dhd_cfg80211, uint, 0);
 
 /* Use interrupts */
-uint dhd_intr = TRUE;
+uint dhd_intr = true;
 module_param(dhd_intr, uint, 0);
 
 /* SDIO Drive Strength (in milliamps) */
@@ -432,11 +420,11 @@ static int dhd_sleep_pm_callback(struct notifier_block *nfb,
        switch (action) {
        case PM_HIBERNATION_PREPARE:
        case PM_SUSPEND_PREPARE:
-               dhd_mmc_suspend = TRUE;
+               dhd_mmc_suspend = true;
                return NOTIFY_OK;
        case PM_POST_HIBERNATION:
        case PM_POST_SUSPEND:
-               dhd_mmc_suspend = FALSE;
+               dhd_mmc_suspend = false;
                return NOTIFY_OK;
        }
        return 0;
@@ -624,7 +612,7 @@ int dhd_timeout_expired(dhd_timeout_t *tmo)
        tmo->elapsed += tmo->increment;
 
        if (tmo->increment < tmo->tick) {
-               OSL_DELAY(tmo->increment);
+               udelay(tmo->increment);
                tmo->increment *= 2;
                if (tmo->increment > tmo->tick)
                        tmo->increment = tmo->tick;
@@ -717,12 +705,12 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
        cnt = netdev_mc_count(dev);
 
        /* Determine initial value of allmulti flag */
-       allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
+       allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
 
        /* Send down the multicast list first. */
 
        buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
-       bufp = buf = MALLOC(dhd->pub.osh, buflen);
+       bufp = buf = kmalloc(buflen, GFP_ATOMIC);
        if (!bufp) {
                DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
                           dhd_ifname(&dhd->pub, ifidx), cnt));
@@ -748,16 +736,16 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
        ioc.cmd = WLC_SET_VAR;
        ioc.buf = buf;
        ioc.len = buflen;
-       ioc.set = TRUE;
+       ioc.set = true;
 
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
                DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
                           dhd_ifname(&dhd->pub, ifidx), cnt));
-               allmulti = cnt ? TRUE : allmulti;
+               allmulti = cnt ? true : allmulti;
        }
 
-       MFREE(dhd->pub.osh, buf, buflen);
+       kfree(buf);
 
        /* Now send the allmulti setting.  This is based on the setting in the
         * net_device flags, but might be modified above to be turned on if we
@@ -765,7 +753,7 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
         */
 
        buflen = sizeof("allmulti") + sizeof(allmulti);
-       buf = MALLOC(dhd->pub.osh, buflen);
+       buf = kmalloc(buflen, GFP_ATOMIC);
        if (!buf) {
                DHD_ERROR(("%s: out of memory for allmulti\n",
                           dhd_ifname(&dhd->pub, ifidx)));
@@ -778,7 +766,7 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
                DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
                        "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
                        (int)sizeof(allmulti), buflen));
-               MFREE(dhd->pub.osh, buf, buflen);
+               kfree(buf);
                return;
        }
 
@@ -786,7 +774,7 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
        ioc.cmd = WLC_SET_VAR;
        ioc.buf = buf;
        ioc.len = buflen;
-       ioc.set = TRUE;
+       ioc.set = true;
 
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
@@ -794,19 +782,19 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
                           dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
        }
 
-       MFREE(dhd->pub.osh, buf, buflen);
+       kfree(buf);
 
        /* Finally, pick up the PROMISC flag as well, like the NIC
                 driver does */
 
-       allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
+       allmulti = (dev->flags & IFF_PROMISC) ? true : false;
        allmulti = htol32(allmulti);
 
        memset(&ioc, 0, sizeof(ioc));
        ioc.cmd = WLC_SET_PROMISC;
        ioc.buf = &allmulti;
        ioc.len = sizeof(allmulti);
-       ioc.set = TRUE;
+       ioc.set = true;
 
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
@@ -833,7 +821,7 @@ _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
        ioc.cmd = WLC_SET_VAR;
        ioc.buf = buf;
        ioc.len = 32;
-       ioc.set = TRUE;
+       ioc.set = true;
 
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
        if (ret < 0) {
@@ -931,7 +919,7 @@ static void dhd_op_if(dhd_if_t *ifp)
                        free_netdev(ifp->net);
 
                dhd->iflist[ifp->idx] = NULL;
-               MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
+               kfree(ifp);
 #ifdef SOFTAP
                if (ifp->net == ap_net_dev)
                        ap_net_dev = NULL;      /*  NULL  SOFTAP global
@@ -945,12 +933,14 @@ static int _dhd_sysioc_thread(void *data)
        dhd_info_t *dhd = (dhd_info_t *) data;
        int i;
 #ifdef SOFTAP
-       bool in_ap = FALSE;
+       bool in_ap = false;
 #endif
 
-       DAEMONIZE("dhd_sysioc");
+       allow_signal(SIGTERM);
 
        while (down_interruptible(&dhd->sysioc_sem) == 0) {
+               if (kthread_should_stop())
+                       break;
                for (i = 0; i < DHD_MAX_IFS; i++) {
                        if (dhd->iflist[i]) {
 #ifdef SOFTAP
@@ -969,30 +959,30 @@ static int _dhd_sysioc_thread(void *data)
                                        DHD_TRACE(("attempt to set MAC for %s "
                                                "in AP Mode," "blocked. \n",
                                                dhd->iflist[i]->net->name));
-                                       dhd->set_macaddress = FALSE;
+                                       dhd->set_macaddress = false;
                                        continue;
                                }
 
                                if (in_ap && dhd->set_multicast) {
                                        DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
                                                dhd->iflist[i]->net->name));
-                                       dhd->set_multicast = FALSE;
+                                       dhd->set_multicast = false;
                                        continue;
                                }
 #endif                         /* SOFTAP */
                                if (dhd->set_multicast) {
-                                       dhd->set_multicast = FALSE;
+                                       dhd->set_multicast = false;
                                        _dhd_set_multicast_list(dhd, i);
                                }
                                if (dhd->set_macaddress) {
-                                       dhd->set_macaddress = FALSE;
+                                       dhd->set_macaddress = false;
                                        _dhd_set_mac_address(dhd, i,
                                                             &dhd->macvalue);
                                }
                        }
                }
        }
-       complete_and_exit(&dhd->sysioc_exited, 0);
+       return 0;
 }
 
 static int dhd_set_mac_address(struct net_device *dev, void *addr)
@@ -1007,9 +997,9 @@ static int dhd_set_mac_address(struct net_device *dev, void *addr)
        if (ifidx == DHD_BAD_IF)
                return -1;
 
-       ASSERT(dhd->sysioc_pid >= 0);
+       ASSERT(dhd->sysioc_tsk);
        memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
-       dhd->set_macaddress = TRUE;
+       dhd->set_macaddress = true;
        up(&dhd->sysioc_sem);
 
        return ret;
@@ -1024,8 +1014,8 @@ static void dhd_set_multicast_list(struct net_device *dev)
        if (ifidx == DHD_BAD_IF)
                return;
 
-       ASSERT(dhd->sysioc_pid >= 0);
-       dhd->set_multicast = TRUE;
+       ASSERT(dhd->sysioc_tsk);
+       dhd->set_multicast = true;
        up(&dhd->sysioc_sem);
 }
 
@@ -1049,10 +1039,6 @@ int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
                        atomic_inc(&dhd->pend_8021x_cnt);
        }
 
-       /* Look into the packet and update the packet priority */
-       if ((PKTPRIO(pktbuf) == 0))
-               pktsetprio(pktbuf, FALSE);
-
        /* If the protocol uses a data header, apply it */
        dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
 
@@ -1305,12 +1291,13 @@ static int dhd_watchdog_thread(void *data)
        }
 #endif                         /* DHD_SCHED */
 
+       allow_signal(SIGTERM);
        /* Run until signal received */
        while (1) {
                if (kthread_should_stop())
                        break;
                if (down_interruptible(&dhd->watchdog_sem) == 0) {
-                       if (dhd->pub.dongle_reset == FALSE) {
+                       if (dhd->pub.dongle_reset == false) {
                                WAKE_LOCK(&dhd->pub, WAKE_LOCK_WATCHDOG);
                                /* Call the bus module watchdog */
                                dhd_bus_watchdog(&dhd->pub);
@@ -1370,9 +1357,10 @@ static int dhd_dpc_thread(void *data)
        }
 #endif                         /* DHD_SCHED */
 
+       allow_signal(SIGTERM);
        /* Run until signal received */
        while (1) {
-               if(kthread_should_stop())
+               if (kthread_should_stop())
                        break;
                if (down_interruptible(&dhd->dpc_sem) == 0) {
                        /* Call bus dpc unless it indicated down
@@ -1386,7 +1374,7 @@ static int dhd_dpc_thread(void *data)
                                }
                                WAKE_UNLOCK(&dhd->pub, WAKE_LOCK_DPC);
                        } else {
-                               dhd_bus_stop(dhd->pub.bus, TRUE);
+                               dhd_bus_stop(dhd->pub.bus, true);
                        }
                } else
                        break;
@@ -1407,7 +1395,7 @@ static void dhd_dpc(unsigned long data)
                if (dhd_bus_dpc(dhd->pub.bus))
                        tasklet_schedule(&dhd->tasklet);
        } else {
-               dhd_bus_stop(dhd->pub.bus, TRUE);
+               dhd_bus_stop(dhd->pub.bus, true);
        }
 }
 
@@ -1437,7 +1425,7 @@ static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
        ioc.cmd = WLC_GET_VAR;
        ioc.buf = buf;
        ioc.len = (uint) sizeof(buf);
-       ioc.set = FALSE;
+       ioc.set = false;
 
        strcpy(buf, "toe_ol");
        ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
@@ -1471,7 +1459,7 @@ static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
        ioc.cmd = WLC_SET_VAR;
        ioc.buf = buf;
        ioc.len = (uint) sizeof(buf);
-       ioc.set = TRUE;
+       ioc.set = true;
 
        /* Set toe_ol as requested */
 
@@ -1674,7 +1662,7 @@ static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
 
        /* Copy out any buffer passed */
        if (ioc.buf) {
-               buflen = min(ioc.len, DHD_IOCTL_MAXLEN);
+               buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
                /* optimization for direct ioctl calls from kernel */
                /*
                   if (segment_eq(get_fs(), KERNEL_DS)) {
@@ -1682,7 +1670,7 @@ static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
                   } else {
                 */
                {
-                       buf = (char *)MALLOC(dhd->pub.osh, buflen);
+                       buf = kmalloc(buflen, GFP_ATOMIC);
                        if (!buf) {
                                bcmerror = -BCME_NOMEM;
                                goto done;
@@ -1752,7 +1740,7 @@ done:
        }
 
        if (buf)
-               MFREE(dhd->pub.osh, buf, buflen);
+               kfree(buf);
 
        return OSL_ERROR(bcmerror);
 }
@@ -1828,15 +1816,11 @@ static int dhd_open(struct net_device *net)
 
 osl_t *dhd_osl_attach(void *pdev, uint bustype)
 {
-       return osl_attach(pdev, bustype, TRUE);
+       return osl_attach(pdev, bustype, true);
 }
 
 void dhd_osl_detach(osl_t *osh)
 {
-       if (MALLOCED(osh)) {
-               DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __func__,
-                          MALLOCED(osh)));
-       }
        osl_detach(osh);
 }
 
@@ -1851,7 +1835,7 @@ dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
        ASSERT(dhd && (ifidx < DHD_MAX_IFS));
 
        ifp = dhd->iflist[ifidx];
-       if (!ifp && !(ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t)))) {
+       if (!ifp && !(ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC))) {
                DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
                return -ENOMEM;
        }
@@ -1866,7 +1850,7 @@ dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
        if (handle == NULL) {
                ifp->state = WLC_E_IF_ADD;
                ifp->idx = ifidx;
-               ASSERT(dhd->sysioc_pid >= 0);
+               ASSERT(dhd->sysioc_tsk);
                up(&dhd->sysioc_sem);
        } else
                ifp->net = (struct net_device *)handle;
@@ -1889,7 +1873,7 @@ void dhd_del_if(dhd_info_t *dhd, int ifidx)
 
        ifp->state = WLC_E_IF_DEL;
        ifp->idx = ifidx;
-       ASSERT(dhd->sysioc_pid >= 0);
+       ASSERT(dhd->sysioc_tsk);
        up(&dhd->sysioc_sem);
 }
 
@@ -1914,7 +1898,7 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
        }
 
        /* Allocate primary dhd_info */
-       dhd = MALLOC(osh, sizeof(dhd_info_t));
+       dhd = kmalloc(sizeof(dhd_info_t), GFP_ATOMIC);
        if (!dhd) {
                DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
                goto fail;
@@ -1945,7 +1929,7 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
                goto fail;
 
        net->netdev_ops = NULL;
-       init_MUTEX(&dhd->proto_sem);
+       sema_init(&dhd->proto_sem, 1);
        /* Initialize other structure content */
        init_waitqueue_head(&dhd->ioctl_resp_wait);
        init_waitqueue_head(&dhd->ctrl_wait);
@@ -1993,11 +1977,11 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
        dhd->timer.function = dhd_watchdog;
 
        /* Initialize thread based operation and lock */
-       init_MUTEX(&dhd->sdsem);
+       sema_init(&dhd->sdsem, 1);
        if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
-               dhd->threads_only = TRUE;
+               dhd->threads_only = true;
        else
-               dhd->threads_only = FALSE;
+               dhd->threads_only = false;
 
        if (dhd_dpc_prio >= 0) {
                /* Initialize watchdog thread */
@@ -2030,11 +2014,15 @@ dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
 
        if (dhd_sysioc) {
                sema_init(&dhd->sysioc_sem, 0);
-               init_completion(&dhd->sysioc_exited);
-               dhd->sysioc_pid = kernel_thread(_dhd_sysioc_thread, dhd, 0);
-       } else {
-               dhd->sysioc_pid = -1;
-       }
+               dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
+                                               "_dhd_sysioc");
+               if (IS_ERR(dhd->sysioc_tsk)) {
+                       printk(KERN_WARNING
+                               "_dhd_sysioc thread failed to start\n");
+                       dhd->sysioc_tsk = NULL;
+               }
+       } else
+               dhd->sysioc_tsk = NULL;
 
        /*
         * Save the dhd_info into the priv
@@ -2108,7 +2096,7 @@ int dhd_bus_start(dhd_pub_t *dhdp)
        dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
 
        /* Bring up the bus */
-       ret = dhd_bus_init(&dhd->pub, TRUE);
+       ret = dhd_bus_init(&dhd->pub, true);
        if (ret != 0) {
                DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
                return ret;
@@ -2117,19 +2105,19 @@ int dhd_bus_start(dhd_pub_t *dhdp)
        /* Host registration for OOB interrupt */
        if (bcmsdh_register_oob_intr(dhdp)) {
                del_timer_sync(&dhd->timer);
-               dhd->wd_timer_valid = FALSE;
+               dhd->wd_timer_valid = false;
                DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
                return -ENODEV;
        }
 
        /* Enable oob at firmware */
-       dhd_enable_oob_intr(dhd->pub.bus, TRUE);
+       dhd_enable_oob_intr(dhd->pub.bus, true);
 #endif                         /* defined(OOB_INTR_ONLY) */
 
        /* If bus is not ready, can't come up */
        if (dhd->pub.busstate != DHD_BUS_DATA) {
                del_timer_sync(&dhd->timer);
-               dhd->wd_timer_valid = FALSE;
+               dhd->wd_timer_valid = false;
                DHD_ERROR(("%s failed bus is not ready\n", __func__));
                return -ENODEV;
        }
@@ -2301,14 +2289,14 @@ void dhd_bus_detach(dhd_pub_t *dhdp)
                        dhd_prot_stop(&dhd->pub);
 
                        /* Stop the bus module */
-                       dhd_bus_stop(dhd->pub.bus, TRUE);
+                       dhd_bus_stop(dhd->pub.bus, true);
 #if defined(OOB_INTR_ONLY)
                        bcmsdh_unregister_oob_intr();
 #endif                         /* defined(OOB_INTR_ONLY) */
 
                        /* Clear the watchdog timer */
                        del_timer_sync(&dhd->timer);
-                       dhd->wd_timer_valid = FALSE;
+                       dhd->wd_timer_valid = false;
                }
        }
 }
@@ -2342,20 +2330,22 @@ void dhd_detach(dhd_pub_t *dhdp)
                        }
 
                        if (dhd->watchdog_tsk) {
+                               send_sig(SIGTERM, dhd->watchdog_tsk, 1);
                                kthread_stop(dhd->watchdog_tsk);
                                dhd->watchdog_tsk = NULL;
                        }
 
                        if (dhd->dpc_tsk) {
+                               send_sig(SIGTERM, dhd->dpc_tsk, 1);
                                kthread_stop(dhd->dpc_tsk);
                                dhd->dpc_tsk = NULL;
-                       }
-                       else
+                       } else
                                tasklet_kill(&dhd->tasklet);
 
-                       if (dhd->sysioc_pid >= 0) {
-                               KILL_PROC(dhd->sysioc_pid, SIGTERM);
-                               wait_for_completion(&dhd->sysioc_exited);
+                       if (dhd->sysioc_tsk) {
+                               send_sig(SIGTERM, dhd->sysioc_tsk, 1);
+                               kthread_stop(dhd->sysioc_tsk);
+                               dhd->sysioc_tsk = NULL;
                        }
 
                        dhd_bus_detach(dhdp);
@@ -2378,8 +2368,8 @@ void dhd_detach(dhd_pub_t *dhdp)
                        WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_LINK_DOWN_TMOUT);
                        WAKE_LOCK_DESTROY(dhdp, WAKE_LOCK_PNO_FIND_TMOUT);
                        free_netdev(ifp->net);
-                       MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
-                       MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
+                       kfree(ifp);
+                       kfree(dhd);
                }
        }
 }
@@ -2511,7 +2501,7 @@ int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
                timeout = schedule_timeout(timeout);
 
        if (signal_pending(current))
-               *pending = TRUE;
+               *pending = true;
 
        set_current_state(TASK_RUNNING);
        remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
@@ -2540,9 +2530,9 @@ void dhd_os_wd_timer(void *bus, uint wdtick)
                return;
 
        /* Totally stop the timer */
-       if (!wdtick && dhd->wd_timer_valid == TRUE) {
+       if (!wdtick && dhd->wd_timer_valid == true) {
                del_timer_sync(&dhd->timer);
-               dhd->wd_timer_valid = FALSE;
+               dhd->wd_timer_valid = false;
                save_dhd_watchdog_ms = wdtick;
                return;
        }
@@ -2552,7 +2542,7 @@ void dhd_os_wd_timer(void *bus, uint wdtick)
 
                if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
 
-                       if (dhd->wd_timer_valid == TRUE)
+                       if (dhd->wd_timer_valid == true)
                                /* Stop timer and restart at new value */
                                del_timer_sync(&dhd->timer);
 
@@ -2569,7 +2559,7 @@ void dhd_os_wd_timer(void *bus, uint wdtick)
                                  jiffies + dhd_watchdog_ms * HZ / 1000);
                }
 
-               dhd->wd_timer_valid = TRUE;
+               dhd->wd_timer_valid = true;
                save_dhd_watchdog_ms = wdtick;
        }
 }
@@ -2678,27 +2668,6 @@ void dhd_os_sdtxunlock(dhd_pub_t *pub)
        dhd_os_sdunlock(pub);
 }
 
-#ifdef DHD_USE_STATIC_BUF
-void *dhd_os_prealloc(int section, unsigned long size)
-{
-#if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
-       void *alloc_ptr = NULL;
-       if (wifi_control_data && wifi_control_data->mem_prealloc) {
-               alloc_ptr = wifi_control_data->mem_prealloc(section, size);
-               if (alloc_ptr) {
-                       DHD_INFO(("success alloc section %d\n", section));
-                       bzero(alloc_ptr, size);
-                       return alloc_ptr;
-               }
-       }
-
-       DHD_ERROR(("can't alloc section %d\n", section));
-       return 0;
-#else
-       return MALLOC(0, size);
-#endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
-}
-#endif /* DHD_USE_STATIC_BUF */
 #if defined(CONFIG_WIRELESS_EXT)
 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev)
 {
@@ -2764,7 +2733,7 @@ void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
        struct dhd_info *dhdinfo = dhd->info;
        dhd_os_sdunlock(dhd);
        wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
-                                        (*lockvar == FALSE), HZ * 2);
+                                        (*lockvar == false), HZ * 2);
        dhd_os_sdlock(dhd);
        return;
 }
@@ -2948,7 +2917,7 @@ int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
 
 exit:
        /* free buf before return */
-       MFREE(dhd->osh, buf, size);
+       kfree(buf);
        /* close file before return */
        if (fp)
                filp_close(fp, current->files);