]> Git Repo - J-linux.git/commitdiff
Merge branch 'exit-cleanups-for-v5.16' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <[email protected]>
Thu, 11 Nov 2021 00:15:54 +0000 (16:15 -0800)
committerLinus Torvalds <[email protected]>
Thu, 11 Nov 2021 00:15:54 +0000 (16:15 -0800)
Pull exit cleanups from Eric Biederman:
 "While looking at some issues related to the exit path in the kernel I
  found several instances where the code is not using the existing
  abstractions properly.

  This set of changes introduces force_fatal_sig a way of sending a
  signal and not allowing it to be caught, and corrects the misuse of
  the existing abstractions that I found.

  A lot of the misuse of the existing abstractions are silly things such
  as doing something after calling a no return function, rolling BUG by
  hand, doing more work than necessary to terminate a kernel thread, or
  calling do_exit(SIGKILL) instead of calling force_sig(SIGKILL).

  In the review a deficiency in force_fatal_sig and force_sig_seccomp
  where ptrace or sigaction could prevent the delivery of the signal was
  found. I have added a change that adds SA_IMMUTABLE to change that
  makes it impossible to interrupt the delivery of those signals, and
  allows backporting to fix force_sig_seccomp

  And Arnd found an issue where a function passed to kthread_run had the
  wrong prototype, and after my cleanup was failing to build."

* 'exit-cleanups-for-v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (23 commits)
  soc: ti: fix wkup_m3_rproc_boot_thread return type
  signal: Add SA_IMMUTABLE to ensure forced siganls do not get changed
  signal: Replace force_sigsegv(SIGSEGV) with force_fatal_sig(SIGSEGV)
  exit/r8188eu: Replace the macro thread_exit with a simple return 0
  exit/rtl8712: Replace the macro thread_exit with a simple return 0
  exit/rtl8723bs: Replace the macro thread_exit with a simple return 0
  signal/x86: In emulate_vsyscall force a signal instead of calling do_exit
  signal/sparc32: In setup_rt_frame and setup_fram use force_fatal_sig
  signal/sparc32: Exit with a fatal signal when try_to_clear_window_buffer fails
  exit/syscall_user_dispatch: Send ordinary signals on failure
  signal: Implement force_fatal_sig
  exit/kthread: Have kernel threads return instead of calling do_exit
  signal/s390: Use force_sigsegv in default_trap_handler
  signal/vm86_32: Properly send SIGSEGV when the vm86 state cannot be saved.
  signal/vm86_32: Replace open coded BUG_ON with an actual BUG_ON
  signal/sparc: In setup_tsb_params convert open coded BUG into BUG
  signal/powerpc: On swapcontext failure force SIGSEGV
  signal/sh: Use force_sig(SIGKILL) instead of do_group_exit(SIGKILL)
  signal/mips: Update (_save|_restore)_fp_context to fail with -EFAULT
  signal/sparc32: Remove unreachable do_exit in do_sparc_fault
  ...

17 files changed:
1  2 
arch/m68k/kernel/traps.c
arch/powerpc/kernel/signal_32.c
arch/powerpc/kernel/signal_64.c
arch/s390/kernel/dumpstack.c
arch/s390/kernel/traps.c
arch/xtensa/kernel/traps.c
drivers/staging/r8188eu/core/rtw_cmd.c
drivers/staging/r8188eu/include/osdep_service.h
drivers/staging/rtl8723bs/core/rtw_cmd.c
drivers/staging/rtl8723bs/core/rtw_xmit.c
drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
fs/exec.c
fs/ocfs2/journal.c
include/linux/sched/signal.h
kernel/kthread.c
kernel/signal.c
net/batman-adv/tp_meter.c

diff --combined arch/m68k/kernel/traps.c
index 9718ce94cc845ab36c393b6dda9a349247bc6da3,74045d164ddb5e6b68fdcb150f86da7dd3f7d3b6..99058a6da956da2f4c10ace2fc45cc6e7ff19cef
@@@ -181,8 -181,9 +181,8 @@@ static inline void access_error060 (str
  static inline unsigned long probe040(int iswrite, unsigned long addr, int wbs)
  {
        unsigned long mmusr;
 -      mm_segment_t old_fs = get_fs();
  
 -      set_fs(MAKE_MM_SEG(wbs));
 +      set_fc(wbs);
  
        if (iswrite)
                asm volatile (".chip 68040; ptestw (%0); .chip 68k" : : "a" (addr));
  
        asm volatile (".chip 68040; movec %%mmusr,%0; .chip 68k" : "=r" (mmusr));
  
 -      set_fs(old_fs);
 +      set_fc(USER_DATA);
  
        return mmusr;
  }
@@@ -200,8 -201,10 +200,8 @@@ static inline int do_040writeback1(unsi
                                   unsigned long wbd)
  {
        int res = 0;
 -      mm_segment_t old_fs = get_fs();
  
 -      /* set_fs can not be moved, otherwise put_user() may oops */
 -      set_fs(MAKE_MM_SEG(wbs));
 +      set_fc(wbs);
  
        switch (wbs & WBSIZ_040) {
        case BA_SIZE_BYTE:
                break;
        }
  
 -      /* set_fs can not be moved, otherwise put_user() may oops */
 -      set_fs(old_fs);
 -
 +      set_fc(USER_DATA);
  
        pr_debug("do_040writeback1, res=%d\n", res);
  
@@@ -1145,7 -1150,7 +1145,7 @@@ asmlinkage void set_esp0(unsigned long 
   */
  asmlinkage void fpsp040_die(void)
  {
-       force_sigsegv(SIGSEGV);
+       force_fatal_sig(SIGSEGV);
  }
  
  #ifdef CONFIG_M68KFPU_EMU
index 38c3eae40c145090cb8fa692da97d8356b494437,933ab95805a6c43729b1699d5bc9646d94382051..00a9c9cd6d421c4fc1536fdb9e527cd9e78a45a6
@@@ -1048,7 -1048,7 +1048,7 @@@ SYSCALL_DEFINE3(swapcontext, struct uco
        if (new_ctx == NULL)
                return 0;
        if (!access_ok(new_ctx, ctx_size) ||
 -          fault_in_pages_readable((u8 __user *)new_ctx, ctx_size))
 +          fault_in_readable((char __user *)new_ctx, ctx_size))
                return -EFAULT;
  
        /*
         * or if another thread unmaps the region containing the context.
         * We kill the task with a SIGSEGV in this situation.
         */
-       if (do_setcontext(new_ctx, regs, 0))
-               do_exit(SIGSEGV);
+       if (do_setcontext(new_ctx, regs, 0)) {
+               force_fatal_sig(SIGSEGV);
+               return -EFAULT;
+       }
  
        set_thread_flag(TIF_RESTOREALL);
        return 0;
@@@ -1237,7 -1239,7 +1239,7 @@@ SYSCALL_DEFINE3(debug_setcontext, struc
  #endif
  
        if (!access_ok(ctx, sizeof(*ctx)) ||
 -          fault_in_pages_readable((u8 __user *)ctx, sizeof(*ctx)))
 +          fault_in_readable((char __user *)ctx, sizeof(*ctx)))
                return -EFAULT;
  
        /*
index 9f471b4a11e3951bb5e41114a613eb926919909c,8ead9b3f47c61f040c6e56aa580d8b265c18d9e2..ef518535d436878cdc869725789bdaf048f5d3c5
@@@ -688,7 -688,7 +688,7 @@@ SYSCALL_DEFINE3(swapcontext, struct uco
        if (new_ctx == NULL)
                return 0;
        if (!access_ok(new_ctx, ctx_size) ||
 -          fault_in_pages_readable((u8 __user *)new_ctx, ctx_size))
 +          fault_in_readable((char __user *)new_ctx, ctx_size))
                return -EFAULT;
  
        /*
         * We kill the task with a SIGSEGV in this situation.
         */
  
-       if (__get_user_sigset(&set, &new_ctx->uc_sigmask))
-               do_exit(SIGSEGV);
+       if (__get_user_sigset(&set, &new_ctx->uc_sigmask)) {
+               force_fatal_sig(SIGSEGV);
+               return -EFAULT;
+       }
        set_current_blocked(&set);
  
        if (!user_read_access_begin(new_ctx, ctx_size))
                return -EFAULT;
        if (__unsafe_restore_sigcontext(current, NULL, 0, &new_ctx->uc_mcontext)) {
                user_read_access_end();
-               do_exit(SIGSEGV);
+               force_fatal_sig(SIGSEGV);
+               return -EFAULT;
        }
        user_read_access_end();
  
index 85f326e258df875829123905180c8acb025a4524,f45e66b8bed68a7c90f37fe25c0ef06064cde79e..0681c55e831d7aaddd2a80d0abacaa317d60768f
@@@ -152,7 -152,7 +152,7 @@@ void show_stack(struct task_struct *tas
  static void show_last_breaking_event(struct pt_regs *regs)
  {
        printk("Last Breaking-Event-Address:\n");
 -      printk(" [<%016lx>] %pSR\n", regs->args[0], (void *)regs->args[0]);
 +      printk(" [<%016lx>] %pSR\n", regs->last_break, (void *)regs->last_break);
  }
  
  void show_registers(struct pt_regs *regs)
@@@ -192,7 -192,7 +192,7 @@@ void show_regs(struct pt_regs *regs
  
  static DEFINE_SPINLOCK(die_lock);
  
- void die(struct pt_regs *regs, const char *str)
+ void __noreturn die(struct pt_regs *regs, const char *str)
  {
        static int die_counter;
  
diff --combined arch/s390/kernel/traps.c
index 6c6f7dcce1a510b67b772ed5798e9481767e3db0,01a7c68dcfb6ee22142c599c15de05513763cf8f..035705c9f23ea0b03a545e94a857075302164105
@@@ -84,7 -84,7 +84,7 @@@ static void default_trap_handler(struc
  {
        if (user_mode(regs)) {
                report_user_fault(regs, SIGSEGV, 0);
-               do_exit(SIGSEGV);
+               force_fatal_sig(SIGSEGV);
        } else
                die(regs, "Unknown program exception");
  }
@@@ -300,6 -300,7 +300,6 @@@ static void (*pgm_check_table[128])(str
  
  void noinstr __do_pgm_check(struct pt_regs *regs)
  {
 -      unsigned long last_break = S390_lowcore.breaking_event_addr;
        unsigned int trapnr;
        irqentry_state_t state;
  
  
        if (user_mode(regs)) {
                update_timer_sys();
 -              if (last_break < 4096)
 -                      last_break = 1;
 -              current->thread.last_break = last_break;
 -              regs->args[0] = last_break;
 +              if (!static_branch_likely(&cpu_has_bear)) {
 +                      if (regs->last_break < 4096)
 +                              regs->last_break = 1;
 +              }
 +              current->thread.last_break = regs->last_break;
        }
  
        if (S390_lowcore.pgm_code & 0x0200) {
index 35a7d47f28cfcaec5a8ac940aaf6bbceff51e1cb,fb056a1913397ec50a135f1baad7b612c78fbe8b..4b4dbeb2d6125608c01d334335c200c6d4026d04
@@@ -97,9 -97,7 +97,9 @@@ static dispatch_init_table_t __initdat
  /* EXCCAUSE_INSTRUCTION_FETCH unhandled */
  /* EXCCAUSE_LOAD_STORE_ERROR unhandled*/
  { EXCCAUSE_LEVEL1_INTERRUPT,  0,         do_interrupt },
 +#ifdef SUPPORT_WINDOWED
  { EXCCAUSE_ALLOCA,            USER|KRNL, fast_alloca },
 +#endif
  /* EXCCAUSE_INTEGER_DIVIDE_BY_ZERO unhandled */
  /* EXCCAUSE_PRIVILEGED unhandled */
  #if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION
@@@ -464,10 -462,12 +464,10 @@@ void secondary_trap_init(void
  
  void show_regs(struct pt_regs * regs)
  {
 -      int i, wmask;
 +      int i;
  
        show_regs_print_info(KERN_DEFAULT);
  
 -      wmask = regs->wmask & ~1;
 -
        for (i = 0; i < 16; i++) {
                if ((i % 8) == 0)
                        pr_info("a%02d:", i);
@@@ -527,7 -527,7 +527,7 @@@ void show_stack(struct task_struct *tas
  
  DEFINE_SPINLOCK(die_lock);
  
- void die(const char * str, struct pt_regs * regs, long err)
+ void __noreturn die(const char * str, struct pt_regs * regs, long err)
  {
        static int die_counter;
        const char *pr = "";
index 5d5f25364b2f03db4af6e319b8d18269c12d3879,d37c9463eecca05c2a756f0f00f9167d92a9e529..48869a7056fdd913f5b8673f1ba7d411dccc70a9
@@@ -9,8 -9,6 +9,8 @@@
  #include "../include/mlme_osdep.h"
  #include "../include/rtw_br_ext.h"
  #include "../include/rtw_mlme_ext.h"
 +#include "../include/rtl8188e_dm.h"
 +#include "../include/rtl8188e_sreset.h"
  
  /*
  Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
@@@ -21,12 -19,11 +21,12 @@@ static int _rtw_init_cmd_priv(struct cm
  {
        int res = _SUCCESS;
  
 -      sema_init(&pcmdpriv->cmd_queue_sema, 0);
 +      init_completion(&pcmdpriv->enqueue_cmd);
        /* sema_init(&(pcmdpriv->cmd_done_sema), 0); */
 -      sema_init(&pcmdpriv->terminate_cmdthread_sema, 0);
 +      init_completion(&pcmdpriv->start_cmd_thread);
 +      init_completion(&pcmdpriv->stop_cmd_thread);
  
 -      _rtw_init_queue(&pcmdpriv->cmd_queue);
 +      rtw_init_queue(&pcmdpriv->cmd_queue);
  
        /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
  
@@@ -170,6 -167,16 +170,6 @@@ static int rtw_cmd_filter(struct cmd_pr
  {
        u8 bAllow = false; /* set to true to allow enqueuing cmd when hw_init_completed is false */
  
 -      /* To decide allow or not */
 -      if ((pcmdpriv->padapter->pwrctrlpriv.bHWPwrPindetect) &&
 -          (!pcmdpriv->padapter->registrypriv.usbss_enable)) {
 -              if (cmd_obj->cmdcode == GEN_CMD_CODE(_Set_Drv_Extra)) {
 -                      struct drvextra_cmd_parm        *pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)cmd_obj->parmbuf;
 -                      if (pdrvextra_cmd_parm->ec_id == POWER_SAVING_CTRL_WK_CID)
 -                              bAllow = true;
 -              }
 -      }
 -
        if (cmd_obj->cmdcode == GEN_CMD_CODE(_SetChannelPlan))
                bAllow = true;
  
@@@ -198,7 -205,7 +198,7 @@@ u32 rtw_enqueue_cmd(struct cmd_priv *pc
        res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
  
        if (res == _SUCCESS)
 -              up(&pcmdpriv->cmd_queue_sema);
 +              complete(&pcmdpriv->enqueue_cmd);
  
  exit:
  
@@@ -214,6 -221,14 +214,6 @@@ struct    cmd_obj *rtw_dequeue_cmd(struct 
        return cmd_obj;
  }
  
 -void rtw_cmd_clr_isr(struct   cmd_priv *pcmdpriv)
 -{
 -
 -      pcmdpriv->cmd_done_cnt++;
 -      /* up(&(pcmdpriv->cmd_done_sema)); */
 -
 -}
 -
  void rtw_free_cmd_obj(struct cmd_obj *pcmd)
  {
  
@@@ -244,14 -259,23 +244,14 @@@ int rtw_cmd_thread(void *context
        struct adapter *padapter = (struct adapter *)context;
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  
 -      thread_enter("RTW_CMD_THREAD");
 -
        pcmdbuf = pcmdpriv->cmd_buf;
  
        pcmdpriv->cmdthd_running = true;
 -      up(&pcmdpriv->terminate_cmdthread_sema);
 +      complete(&pcmdpriv->start_cmd_thread);
  
        while (1) {
 -              if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL)
 -                      break;
 +              wait_for_completion(&pcmdpriv->enqueue_cmd);
  
 -              if (padapter->bDriverStopped ||
 -                  padapter->bSurpriseRemoved) {
 -                      DBG_88E("%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n",
 -                              __func__, padapter->bDriverStopped, padapter->bSurpriseRemoved, __LINE__);
 -                      break;
 -              }
  _next:
                if (padapter->bDriverStopped ||
                    padapter->bSurpriseRemoved) {
@@@ -321,11 -345,43 +321,11 @@@ post_process
                rtw_free_cmd_obj(pcmd);
        } while (1);
  
 -      up(&pcmdpriv->terminate_cmdthread_sema);
 +      complete(&pcmdpriv->stop_cmd_thread);
  
-       thread_exit();
+       return 0;
  }
  
 -u8 rtw_setstandby_cmd(struct adapter *padapter, uint action)
 -{
 -      struct cmd_obj *ph2c;
 -      struct usb_suspend_parm *psetusbsuspend;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -
 -      u8 ret = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!ph2c) {
 -              ret = _FAIL;
 -              goto exit;
 -      }
 -
 -      psetusbsuspend = kzalloc(sizeof(struct usb_suspend_parm), GFP_ATOMIC);
 -      if (!psetusbsuspend) {
 -              kfree(ph2c);
 -              ret = _FAIL;
 -              goto exit;
 -      }
 -
 -      psetusbsuspend->action = action;
 -
 -      init_h2fwcmd_w_parm_no_rsp(ph2c, psetusbsuspend, GEN_CMD_CODE(_SetUsbSuspend));
 -
 -      ret = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -
 -exit:
 -
 -      return ret;
 -}
 -
  /*
  rtw_sitesurvey_cmd(~)
        ### NOTE:#### (!!!!)
@@@ -435,12 -491,228 +435,12 @@@ exit
        return res;
  }
  
 -u8 rtw_setbasicrate_cmd(struct adapter *padapter, u8 *rateset)
 -{
 -      struct cmd_obj *ph2c;
 -      struct setbasicrate_parm *pssetbasicratepara;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      u8      res = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!ph2c) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -      pssetbasicratepara = kzalloc(sizeof(struct setbasicrate_parm), GFP_ATOMIC);
 -
 -      if (!pssetbasicratepara) {
 -              kfree(ph2c);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara, _SetBasicRate_CMD_);
 -
 -      memcpy(pssetbasicratepara->basicrates, rateset, NumRates);
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -exit:
 -
 -      return res;
 -}
 -
 -/*
 -unsigned char rtw_setphy_cmd(unsigned char  *adapter)
 -
 -1.  be called only after rtw_update_registrypriv_dev_network(~) or mp testing program
 -2.  for AdHoc/Ap mode or mp mode?
 -
 -*/
 -u8 rtw_setphy_cmd(struct adapter *padapter, u8 modem, u8 ch)
 -{
 -      struct cmd_obj *ph2c;
 -      struct setphy_parm *psetphypara;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      u8      res = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!ph2c) {
 -              res = _FAIL;
 -              goto exit;
 -              }
 -      psetphypara = kzalloc(sizeof(struct setphy_parm), GFP_ATOMIC);
 -
 -      if (!psetphypara) {
 -              kfree(ph2c);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      init_h2fwcmd_w_parm_no_rsp(ph2c, psetphypara, _SetPhy_CMD_);
 -
 -      psetphypara->modem = modem;
 -      psetphypara->rfchannel = ch;
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -exit:
 -
 -      return res;
 -}
 -
 -u8 rtw_setbbreg_cmd(struct adapter *padapter, u8 offset, u8 val)
 -{
 -      struct cmd_obj *ph2c;
 -      struct writeBB_parm *pwritebbparm;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      u8      res = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!ph2c) {
 -              res = _FAIL;
 -              goto exit;
 -              }
 -      pwritebbparm = kzalloc(sizeof(struct writeBB_parm), GFP_ATOMIC);
 -
 -      if (!pwritebbparm) {
 -              kfree(ph2c);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      init_h2fwcmd_w_parm_no_rsp(ph2c, pwritebbparm, GEN_CMD_CODE(_SetBBReg));
 -
 -      pwritebbparm->offset = offset;
 -      pwritebbparm->value = val;
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -exit:
 -
 -      return res;
 -}
 -
 -u8 rtw_getbbreg_cmd(struct adapter  *padapter, u8 offset, u8 *pval)
 -{
 -      struct cmd_obj *ph2c;
 -      struct readBB_parm *prdbbparm;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      u8      res = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!ph2c) {
 -              res = _FAIL;
 -              goto exit;
 -              }
 -      prdbbparm = kzalloc(sizeof(struct readBB_parm), GFP_ATOMIC);
 -
 -      if (!prdbbparm) {
 -              kfree(ph2c);
 -              return _FAIL;
 -      }
 -
 -      INIT_LIST_HEAD(&ph2c->list);
 -      ph2c->cmdcode = GEN_CMD_CODE(_GetBBReg);
 -      ph2c->parmbuf = (unsigned char *)prdbbparm;
 -      ph2c->cmdsz =  sizeof(struct readBB_parm);
 -      ph2c->rsp = pval;
 -      ph2c->rspsz = sizeof(struct readBB_rsp);
 -
 -      prdbbparm->offset = offset;
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -exit:
 -
 -      return res;
 -}
 -
 -u8 rtw_setrfreg_cmd(struct adapter  *padapter, u8 offset, u32 val)
 -{
 -      struct cmd_obj *ph2c;
 -      struct writeRF_parm *pwriterfparm;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      u8      res = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!ph2c) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -      pwriterfparm = kzalloc(sizeof(struct writeRF_parm), GFP_ATOMIC);
 -
 -      if (!pwriterfparm) {
 -              kfree(ph2c);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      init_h2fwcmd_w_parm_no_rsp(ph2c, pwriterfparm, GEN_CMD_CODE(_SetRFReg));
 -
 -      pwriterfparm->offset = offset;
 -      pwriterfparm->value = val;
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -exit:
 -
 -      return res;
 -}
 -
 -u8 rtw_getrfreg_cmd(struct adapter  *padapter, u8 offset, u8 *pval)
 -{
 -      struct cmd_obj *ph2c;
 -      struct readRF_parm *prdrfparm;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      u8      res = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!ph2c) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      prdrfparm = kzalloc(sizeof(struct readRF_parm), GFP_ATOMIC);
 -      if (!prdrfparm) {
 -              kfree(ph2c);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      INIT_LIST_HEAD(&ph2c->list);
 -      ph2c->cmdcode = GEN_CMD_CODE(_GetRFReg);
 -      ph2c->parmbuf = (unsigned char *)prdrfparm;
 -      ph2c->cmdsz =  sizeof(struct readRF_parm);
 -      ph2c->rsp = pval;
 -      ph2c->rspsz = sizeof(struct readRF_rsp);
 -
 -      prdrfparm->offset = offset;
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -
 -exit:
 -
 -      return res;
 -}
 -
  void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter,  struct cmd_obj *pcmd)
  {
  
  
        kfree(pcmd->parmbuf);
        kfree(pcmd);
 -
 -      if (padapter->registrypriv.mp_mode == 1)
 -              padapter->mppriv.workparam.bcompleted = true;
 -
 -}
 -
 -void rtw_readtssi_cmdrsp_callback(struct adapter *padapter,  struct cmd_obj *pcmd)
 -{
 -
 -
 -      kfree(pcmd->parmbuf);
 -      kfree(pcmd);
 -
 -      if (padapter->registrypriv.mp_mode == 1)
 -              padapter->mppriv.workparam.bcompleted = true;
 -
  }
  
  u8 rtw_createbss_cmd(struct adapter  *padapter)
@@@ -471,6 -743,32 +471,6 @@@ exit
        return res;
  }
  
 -u8 rtw_createbss_cmd_ex(struct adapter  *padapter, unsigned char *pbss, unsigned int sz)
 -{
 -      struct cmd_obj *pcmd;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      u8      res = _SUCCESS;
 -
 -      pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!pcmd) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      INIT_LIST_HEAD(&pcmd->list);
 -      pcmd->cmdcode = GEN_CMD_CODE(_CreateBss);
 -      pcmd->parmbuf = pbss;
 -      pcmd->cmdsz =  sz;
 -      pcmd->rsp = NULL;
 -      pcmd->rspsz = 0;
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, pcmd);
 -
 -exit:
 -
 -      return res;
 -}
 -
  u8 rtw_joinbss_cmd(struct adapter  *padapter, struct wlan_network *pnetwork)
  {
        u8      res = _SUCCESS;
@@@ -775,6 -1073,115 +775,6 @@@ exit
        return res;
  }
  
 -u8 rtw_setrttbl_cmd(struct adapter  *padapter, struct setratable_parm *prate_table)
 -{
 -      struct cmd_obj *ph2c;
 -      struct setratable_parm *psetrttblparm;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      u8      res = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
 -      if (!ph2c) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -      psetrttblparm = kzalloc(sizeof(struct setratable_parm), GFP_KERNEL);
 -
 -      if (!psetrttblparm) {
 -              kfree(ph2c);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm, GEN_CMD_CODE(_SetRaTable));
 -
 -      memcpy(psetrttblparm, prate_table, sizeof(struct setratable_parm));
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -exit:
 -
 -      return res;
 -}
 -
 -u8 rtw_getrttbl_cmd(struct adapter  *padapter, struct getratable_rsp *pval)
 -{
 -      struct cmd_obj *ph2c;
 -      struct getratable_parm *pgetrttblparm;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      u8      res = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
 -      if (!ph2c) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -      pgetrttblparm = kzalloc(sizeof(struct getratable_parm), GFP_KERNEL);
 -
 -      if (!pgetrttblparm) {
 -              kfree(ph2c);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -/*    init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm, GEN_CMD_CODE(_SetRaTable)); */
 -
 -      INIT_LIST_HEAD(&ph2c->list);
 -      ph2c->cmdcode = GEN_CMD_CODE(_GetRaTable);
 -      ph2c->parmbuf = (unsigned char *)pgetrttblparm;
 -      ph2c->cmdsz =  sizeof(struct getratable_parm);
 -      ph2c->rsp = (u8 *)pval;
 -      ph2c->rspsz = sizeof(struct getratable_rsp);
 -
 -      pgetrttblparm->rsvd = 0x0;
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -exit:
 -
 -      return res;
 -}
 -
 -u8 rtw_setassocsta_cmd(struct adapter  *padapter, u8 *mac_addr)
 -{
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -      struct cmd_obj *ph2c;
 -      struct set_assocsta_parm *psetassocsta_para;
 -      struct set_stakey_rsp *psetassocsta_rsp = NULL;
 -
 -      u8      res = _SUCCESS;
 -
 -      ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!ph2c) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      psetassocsta_para = kzalloc(sizeof(struct set_assocsta_parm), GFP_ATOMIC);
 -      if (!psetassocsta_para) {
 -              kfree(ph2c);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      psetassocsta_rsp = kzalloc(sizeof(struct set_assocsta_rsp), GFP_ATOMIC);
 -      if (!psetassocsta_rsp) {
 -              kfree(ph2c);
 -              kfree(psetassocsta_para);
 -              return _FAIL;
 -      }
 -
 -      init_h2fwcmd_w_parm_no_rsp(ph2c, psetassocsta_para, _SetAssocSta_CMD_);
 -      ph2c->rsp = (u8 *)psetassocsta_rsp;
 -      ph2c->rspsz = sizeof(struct set_assocsta_rsp);
 -
 -      memcpy(psetassocsta_para->addr, mac_addr, ETH_ALEN);
 -
 -      res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -
 -exit:
 -
 -      return res;
 - }
 -
  u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr)
  {
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
@@@ -843,6 -1250,57 +843,6 @@@ exit
        return res;
  }
  
 -u8 rtw_set_ch_cmd(struct adapter *padapter, u8 ch, u8 bw, u8 ch_offset, u8 enqueue)
 -{
 -      struct cmd_obj *pcmdobj;
 -      struct set_ch_parm *set_ch_parm;
 -      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 -
 -      u8 res = _SUCCESS;
 -
 -      DBG_88E(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
 -              FUNC_NDEV_ARG(padapter->pnetdev), ch, bw, ch_offset);
 -
 -      /* check input parameter */
 -
 -      /* prepare cmd parameter */
 -      set_ch_parm = kzalloc(sizeof(*set_ch_parm), GFP_ATOMIC);
 -      if (!set_ch_parm) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -      set_ch_parm->ch = ch;
 -      set_ch_parm->bw = bw;
 -      set_ch_parm->ch_offset = ch_offset;
 -
 -      if (enqueue) {
 -              /* need enqueue, prepare cmd_obj and enqueue */
 -              pcmdobj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -              if (!pcmdobj) {
 -                      kfree(set_ch_parm);
 -                      res = _FAIL;
 -                      goto exit;
 -              }
 -
 -              init_h2fwcmd_w_parm_no_rsp(pcmdobj, set_ch_parm, GEN_CMD_CODE(_SetChannel));
 -              res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
 -      } else {
 -              /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
 -              if (H2C_SUCCESS != set_ch_hdl(padapter, (u8 *)set_ch_parm))
 -                      res = _FAIL;
 -
 -              kfree(set_ch_parm);
 -      }
 -
 -      /* do something based on res... */
 -
 -exit:
 -
 -      DBG_88E(FUNC_NDEV_FMT" res:%u\n", FUNC_NDEV_ARG(padapter->pnetdev), res);
 -
 -      return res;
 -}
 -
  u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue)
  {
        struct  cmd_obj *pcmdobj;
@@@ -894,6 -1352,74 +894,6 @@@ exit
        return res;
  }
  
 -u8 rtw_led_blink_cmd(struct adapter *padapter, struct LED_871x *pLed)
 -{
 -      struct  cmd_obj *pcmdobj;
 -      struct  LedBlink_param *ledBlink_param;
 -      struct  cmd_priv   *pcmdpriv = &padapter->cmdpriv;
 -
 -      u8      res = _SUCCESS;
 -
 -      pcmdobj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!pcmdobj) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      ledBlink_param = kzalloc(sizeof(struct LedBlink_param), GFP_ATOMIC);
 -      if (!ledBlink_param) {
 -              kfree(pcmdobj);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      ledBlink_param->pLed = pLed;
 -
 -      init_h2fwcmd_w_parm_no_rsp(pcmdobj, ledBlink_param, GEN_CMD_CODE(_LedBlink));
 -      res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
 -
 -exit:
 -
 -      return res;
 -}
 -
 -u8 rtw_set_csa_cmd(struct adapter *padapter, u8 new_ch_no)
 -{
 -      struct  cmd_obj *pcmdobj;
 -      struct  SetChannelSwitch_param *setChannelSwitch_param;
 -      struct  cmd_priv   *pcmdpriv = &padapter->cmdpriv;
 -
 -      u8      res = _SUCCESS;
 -
 -      pcmdobj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
 -      if (!pcmdobj) {
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      setChannelSwitch_param = kzalloc(sizeof(struct  SetChannelSwitch_param),
 -                                       GFP_ATOMIC);
 -      if (!setChannelSwitch_param) {
 -              kfree(pcmdobj);
 -              res = _FAIL;
 -              goto exit;
 -      }
 -
 -      setChannelSwitch_param->new_ch_no = new_ch_no;
 -
 -      init_h2fwcmd_w_parm_no_rsp(pcmdobj, setChannelSwitch_param, GEN_CMD_CODE(_SetChannelSwitch));
 -      res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
 -
 -exit:
 -
 -      return res;
 -}
 -
 -u8 rtw_tdls_cmd(struct adapter *padapter, u8 *addr, u8 option)
 -{
 -      return _SUCCESS;
 -}
 -
  static void traffic_status_watchdog(struct adapter *padapter)
  {
        u8      bEnterPS;
@@@ -960,15 -1486,17 +960,15 @@@ static void dynamic_chk_wk_hdl(struct a
        padapter = (struct adapter *)pbuf;
        pmlmepriv = &padapter->mlmepriv;
  
 -#ifdef CONFIG_88EU_AP_MODE
        if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
                expire_timeout_chk(padapter);
 -#endif
  
 -      rtw_hal_sreset_xmit_status_check(padapter);
 +      rtl8188e_sreset_xmit_status_check(padapter);
  
        linked_status_chk(padapter);
        traffic_status_watchdog(padapter);
  
 -      rtw_hal_dm_watchdog(padapter);
 +      rtl8188e_HalDmWatchDog(padapter);
  }
  
  static void lps_ctrl_wk_hdl(struct adapter *padapter, u8 lps_ctrl_type)
                mstatus = 1;/* connect */
                /*  Reset LPS Setting */
                padapter->pwrctrlpriv.LpsIdleCount = 0;
 -              rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
 +              SetHwReg8188EU(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
                break;
        case LPS_CTRL_DISCONNECT:
                mstatus = 0;/* disconnect */
                LPS_Leave(padapter);
 -              rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
 +              SetHwReg8188EU(padapter, HW_VAR_H2C_FW_JOINBSSRPT, (u8 *)(&mstatus));
                break;
        case LPS_CTRL_SPECIAL_PACKET:
                /* DBG_88E("LPS_CTRL_SPECIAL_PACKET\n"); */
@@@ -1060,7 -1588,7 +1060,7 @@@ exit
  
  static void rpt_timer_setting_wk_hdl(struct adapter *padapter, u16 min_time)
  {
 -      rtw_hal_set_hwreg(padapter, HW_VAR_RPT_TIMER_SETTING, (u8 *)(&min_time));
 +      SetHwReg8188EU(padapter, HW_VAR_RPT_TIMER_SETTING, (u8 *)(&min_time));
  }
  
  u8 rtw_rpt_timer_cfg_cmd(struct adapter *padapter, u16 min_time)
@@@ -1097,7 -1625,7 +1097,7 @@@ exit
  
  static void antenna_select_wk_hdl(struct adapter *padapter, u8 antenna)
  {
 -      rtw_hal_set_hwreg(padapter, HW_VAR_ANTENNA_DIVERSITY_SELECT, (u8 *)(&antenna));
 +      SetHwReg8188EU(padapter, HW_VAR_ANTENNA_DIVERSITY_SELECT, (u8 *)(&antenna));
  }
  
  u8 rtw_antenna_select_cmd(struct adapter *padapter, u8 antenna, u8 enqueue)
        u8      support_ant_div;
        u8      res = _SUCCESS;
  
 -      rtw_hal_get_def_var(padapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &support_ant_div);
 +      GetHalDefVar8188EUsb(padapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &support_ant_div);
        if (!support_ant_div)
                return res;
  
@@@ -1141,6 -1669,12 +1141,6 @@@ exit
        return res;
  }
  
 -static void power_saving_wk_hdl(struct adapter *padapter, u8 *pbuf, int sz)
 -{
 -       rtw_ps_processor(padapter);
 -}
 -
 -#ifdef CONFIG_88EU_P2P
  u8 p2p_protocol_wk_cmd(struct adapter *padapter, int intCmdType)
  {
        struct cmd_obj  *ph2c;
@@@ -1177,6 -1711,7 +1177,6 @@@ exit
  
        return res;
  }
 -#endif /* CONFIG_88EU_P2P */
  
  u8 rtw_ps_cmd(struct adapter *padapter)
  {
@@@ -1210,6 -1745,8 +1210,6 @@@ exit
        return res;
  }
  
 -#ifdef CONFIG_88EU_AP_MODE
 -
  static void rtw_chk_hi_queue_hdl(struct adapter *padapter)
  {
        int cnt = 0;
                /* while ((rtw_read32(padapter, 0x414)&0x00ffff00)!= 0) */
                /* while ((rtw_read32(padapter, 0x414)&0x0000ff00)!= 0) */
  
 -              rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &val);
 +              GetHwReg8188EU(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &val);
  
                while (!val) {
                        msleep(100);
                        if (cnt > 10)
                                break;
  
 -                      rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &val);
 +                      GetHwReg8188EU(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &val);
                }
  
                if (cnt <= 10) {
@@@ -1280,6 -1817,7 +1280,6 @@@ u8 rtw_chk_hi_queue_cmd(struct adapter 
  exit:
        return res;
  }
 -#endif
  
  u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt)
  {
@@@ -1314,12 -1852,29 +1314,12 @@@ exit
        return res;
  }
  
 -static s32 c2h_evt_hdl(struct adapter *adapter, struct c2h_evt_hdr *c2h_evt, c2h_id_filter filter)
 +static void c2h_evt_hdl(struct adapter *adapter, struct c2h_evt_hdr *c2h_evt, c2h_id_filter filter)
  {
 -      s32 ret = _FAIL;
        u8 buf[16];
  
 -      if (!c2h_evt) {
 -              /* No c2h event in cmd_obj, read c2h event before handling*/
 -              if (c2h_evt_read(adapter, buf) == _SUCCESS) {
 -                      c2h_evt = (struct c2h_evt_hdr *)buf;
 -
 -                      if (filter && !filter(c2h_evt->id))
 -                              goto exit;
 -
 -                      ret = rtw_hal_c2h_handler(adapter, c2h_evt);
 -              }
 -      } else {
 -              if (filter && !filter(c2h_evt->id))
 -                      goto exit;
 -
 -              ret = rtw_hal_c2h_handler(adapter, c2h_evt);
 -      }
 -exit:
 -      return ret;
 +      if (!c2h_evt)
 +              c2h_evt_read(adapter, buf);
  }
  
  static void c2h_wk_callback(struct work_struct *work)
        struct evt_priv *evtpriv = container_of(work, struct evt_priv, c2h_wk);
        struct adapter *adapter = container_of(evtpriv, struct adapter, evtpriv);
        struct c2h_evt_hdr *c2h_evt;
 -      c2h_id_filter ccx_id_filter = rtw_hal_c2h_id_filter_ccx(adapter);
  
        evtpriv->c2h_wk_alive = true;
  
                        continue;
                }
  
 -              if (ccx_id_filter(c2h_evt->id)) {
 -                      /* Handle CCX report here */
 -                      rtw_hal_c2h_handler(adapter, c2h_evt);
 -                      kfree(c2h_evt);
 -              } else {
 -#ifdef CONFIG_88EU_P2P
 -                      /* Enqueue into cmd_thread for others */
 -                      rtw_c2h_wk_cmd(adapter, (u8 *)c2h_evt);
 -#endif
 -              }
 +              /* Enqueue into cmd_thread for others */
 +              rtw_c2h_wk_cmd(adapter, (u8 *)c2h_evt);
        }
  
        evtpriv->c2h_wk_alive = false;
@@@ -1377,7 -1941,7 +1377,7 @@@ u8 rtw_drvextra_cmd_hdl(struct adapter 
                dynamic_chk_wk_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type_size);
                break;
        case POWER_SAVING_CTRL_WK_CID:
 -              power_saving_wk_hdl(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type_size);
 +              rtw_ps_processor(padapter);
                break;
        case LPS_CTRL_WK_CID:
                lps_ctrl_wk_hdl(padapter, (u8)pdrvextra_cmd->type_size);
        case ANT_SELECT_WK_CID:
                antenna_select_wk_hdl(padapter, pdrvextra_cmd->type_size);
                break;
 -#ifdef CONFIG_88EU_P2P
        case P2P_PS_WK_CID:
                p2p_ps_wk_hdl(padapter, pdrvextra_cmd->type_size);
                break;
                /*      I used the type_size as the type command */
                p2p_protocol_wk_hdl(padapter, pdrvextra_cmd->type_size);
                break;
 -#endif
 -#ifdef CONFIG_88EU_AP_MODE
        case CHECK_HIQ_WK_CID:
                rtw_chk_hi_queue_hdl(padapter);
                break;
 -#endif /* CONFIG_88EU_AP_MODE */
        case C2H_WK_CID:
                c2h_evt_hdl(padapter, (struct c2h_evt_hdr *)pdrvextra_cmd->pbuf, NULL);
                break;
index efab3a97eb46df9a2aafb4b6561430d10d468c67,afbffb551f9bb71812813d158702be93e19b1955..f6f5e45812125dafdb5a95f978c071388d9ca19c
@@@ -49,13 -49,24 +49,11 @@@ struct     __queue 
        spinlock_t lock;
  };
  
- #define thread_exit() complete_and_exit(NULL, 0)
  static inline struct list_head *get_list_head(struct __queue *queue)
  {
        return (&(queue->queue));
  }
  
 -static inline int _enter_critical_mutex(struct mutex *pmutex, unsigned long *pirqL)
 -{
 -      int ret;
 -
 -      ret = mutex_lock_interruptible(pmutex);
 -      return ret;
 -}
 -
 -static inline void _exit_critical_mutex(struct mutex *pmutex, unsigned long *pirqL)
 -{
 -              mutex_unlock(pmutex);
 -}
 -
  static inline void rtw_list_delete(struct list_head *plist)
  {
        list_del_init(plist);
@@@ -141,11 -152,11 +139,11 @@@ extern unsigned char RSN_TKIP_CIPHER[4]
  
  void *rtw_malloc2d(int h, int w, int size);
  
 -u32  _rtw_down_sema(struct semaphore *sema);
 -void _rtw_mutex_init(struct mutex *pmutex);
 -void _rtw_mutex_free(struct mutex *pmutex);
 -
 -void _rtw_init_queue(struct __queue *pqueue);
 +#define rtw_init_queue(q)                                     \
 +      do {                                                    \
 +              INIT_LIST_HEAD(&((q)->queue));                  \
 +              spin_lock_init(&((q)->lock));                   \
 +      } while (0)
  
  u32  rtw_systime_to_ms(u32 systime);
  u32  rtw_ms_to_systime(u32 ms);
@@@ -153,17 -164,32 +151,17 @@@ s32  rtw_get_passing_time_ms(u32 start)
  
  void rtw_usleep_os(int us);
  
 -u32  rtw_atoi(u8 *s);
 -
  static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
  {
        return del_timer_sync(ptimer);
  }
  
 -static __inline void thread_enter(char *name)
 -{
 -#ifdef daemonize
 -      daemonize("%s", name);
 -#endif
 -      allow_signal(SIGTERM);
 -}
 -
  static inline void flush_signals_thread(void)
  {
        if (signal_pending (current))
                flush_signals(current);
  }
  
 -static inline int res_to_status(int res)
 -{
 -      return res;
 -}
 -
  #define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
  #define RND4(x)       (((x >> 2) + (((x & 3) == 0) ?  0: 1)) << 2)
  
@@@ -274,10 -300,12 +272,10 @@@ struct rtw_cbuf 
        u32 write;
        u32 read;
        u32 size;
 -      void *bufs[0];
 +      void *bufs[];
  };
  
 -bool rtw_cbuf_full(struct rtw_cbuf *cbuf);
  bool rtw_cbuf_empty(struct rtw_cbuf *cbuf);
 -bool rtw_cbuf_push(struct rtw_cbuf *cbuf, void *buf);
  void *rtw_cbuf_pop(struct rtw_cbuf *cbuf);
  struct rtw_cbuf *rtw_cbuf_alloc(u32 size);
  int wifirate2_ratetbl_inx(unsigned char rate);
index 639459d52261491d3483188a0976c8e92d72fcb6,8e69f9c10f5c5e06f2aee3138c0f32a10b11cc4f..bd24d913b4646b4f8228a8f02e681bdc2d758103
@@@ -166,8 -166,7 +166,8 @@@ int rtw_init_cmd_priv(struct       cmd_priv *
        init_completion(&pcmdpriv->cmd_queue_comp);
        init_completion(&pcmdpriv->terminate_cmdthread_comp);
  
 -      _rtw_init_queue(&(pcmdpriv->cmd_queue));
 +      INIT_LIST_HEAD(&pcmdpriv->cmd_queue.queue);
 +      spin_lock_init(&pcmdpriv->cmd_queue.lock);
  
        /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
  
@@@ -256,7 -255,7 +256,7 @@@ int _rtw_enqueue_cmd(struct __queue *qu
  {
        unsigned long irqL;
  
 -      if (obj == NULL)
 +      if (!obj)
                goto exit;
  
        /* spin_lock_bh(&queue->lock); */
@@@ -278,10 -277,10 +278,10 @@@ struct  cmd_obj *_rtw_dequeue_cmd(struc
  
        /* spin_lock_bh(&(queue->lock)); */
        spin_lock_irqsave(&queue->lock, irqL);
 -      if (list_empty(&(queue->queue)))
 +      if (list_empty(&queue->queue))
                obj = NULL;
        else {
 -              obj = container_of(get_next(&(queue->queue)), struct cmd_obj, list);
 +              obj = container_of(get_next(&queue->queue), struct cmd_obj, list);
                list_del_init(&obj->list);
        }
  
@@@ -309,19 -308,22 +309,19 @@@ int rtw_cmd_filter(struct cmd_priv *pcm
        if (cmd_obj->cmdcode == GEN_CMD_CODE(_SetChannelPlan))
                bAllow = true;
  
 -      if ((pcmdpriv->padapter->hw_init_completed == false && bAllow == false)
 -              || atomic_read(&(pcmdpriv->cmdthd_running)) == false    /* com_thread not running */
 -      )
 +      if ((!pcmdpriv->padapter->hw_init_completed && !bAllow) ||
 +              !atomic_read(&pcmdpriv->cmdthd_running))        /* com_thread not running */
                return _FAIL;
  
        return _SUCCESS;
  }
  
 -
 -
  int rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
  {
        int res = _FAIL;
        struct adapter *padapter = pcmdpriv->padapter;
  
 -      if (cmd_obj == NULL)
 +      if (!cmd_obj)
                goto exit;
  
        cmd_obj->padapter = padapter;
@@@ -365,10 -367,11 +365,10 @@@ void rtw_free_cmd_obj(struct cmd_obj *p
        kfree(pcmd);
  }
  
 -
  void rtw_stop_cmd_thread(struct adapter *adapter)
  {
        if (adapter->cmdThread &&
 -              atomic_read(&(adapter->cmdpriv.cmdthd_running)) == true &&
 +              atomic_read(&adapter->cmdpriv.cmdthd_running) &&
                adapter->cmdpriv.stop_req == 0) {
                adapter->cmdpriv.stop_req = 1;
                complete(&adapter->cmdpriv.cmd_queue_comp);
@@@ -384,7 -387,7 +384,7 @@@ int rtw_cmd_thread(void *context
        u8 (*cmd_hdl)(struct adapter *padapter, u8 *pbuf);
        void (*pcmd_callback)(struct adapter *dev, struct cmd_obj *pcmd);
        struct adapter *padapter = context;
 -      struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
 +      struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
        struct drvextra_cmd_parm *extra_parm = NULL;
  
        thread_enter("RTW_CMD_THREAD");
        pcmdbuf = pcmdpriv->cmd_buf;
  
        pcmdpriv->stop_req = 0;
 -      atomic_set(&(pcmdpriv->cmdthd_running), true);
 +      atomic_set(&pcmdpriv->cmdthd_running, true);
        complete(&pcmdpriv->terminate_cmdthread_comp);
  
        while (1) {
                        break;
                }
  
 -              if ((padapter->bDriverStopped == true) || (padapter->bSurpriseRemoved == true)) {
 +              if (padapter->bDriverStopped || padapter->bSurpriseRemoved) {
                        netdev_dbg(padapter->pnetdev,
                                   "%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n",
                                   __func__, padapter->bDriverStopped,
                        continue;
  
  _next:
 -              if ((padapter->bDriverStopped == true) || (padapter->bSurpriseRemoved == true)) {
 +              if (padapter->bDriverStopped || padapter->bSurpriseRemoved) {
                        netdev_dbg(padapter->pnetdev,
                                   "%s: DriverStopped(%d) SurpriseRemoved(%d) break at line %d\n",
                                   __func__, padapter->bDriverStopped,
  
  post_process:
  
 -              if (mutex_lock_interruptible(&(pcmd->padapter->cmdpriv.sctx_mutex)) == 0) {
 +              if (mutex_lock_interruptible(&pcmd->padapter->cmdpriv.sctx_mutex) == 0) {
                        if (pcmd->sctx) {
                                netdev_dbg(padapter->pnetdev,
                                           FUNC_ADPT_FMT " pcmd->sctx\n",
                                else
                                        rtw_sctx_done_err(&pcmd->sctx, RTW_SCTX_DONE_CMD_ERROR);
                        }
 -                      mutex_unlock(&(pcmd->padapter->cmdpriv.sctx_mutex));
 +                      mutex_unlock(&pcmd->padapter->cmdpriv.sctx_mutex);
                }
  
                /* call callback function for post-processed */
                if (pcmd->cmdcode < ARRAY_SIZE(rtw_cmd_callback)) {
                        pcmd_callback = rtw_cmd_callback[pcmd->cmdcode].callback;
 -                      if (pcmd_callback == NULL) {
 +                      if (!pcmd_callback) {
                                rtw_free_cmd_obj(pcmd);
                        } else {
                                /* todo: !!! fill rsp_buf to pcmd->rsp if (pcmd->rsp!= NULL) */
                } else {
                        rtw_free_cmd_obj(pcmd);
                }
 -
                flush_signals_thread();
 -
                goto _next;
 -
        }
  
        /*  free all cmd_obj resources */
        do {
                pcmd = rtw_dequeue_cmd(pcmdpriv);
 -              if (pcmd == NULL) {
 +              if (!pcmd) {
                        rtw_unregister_cmd_alive(padapter);
                        break;
                }
        } while (1);
  
        complete(&pcmdpriv->terminate_cmdthread_comp);
 -      atomic_set(&(pcmdpriv->cmdthd_running), false);
 +      atomic_set(&pcmdpriv->cmdthd_running, false);
  
-       thread_exit();
+       return 0;
  }
  
  /*
@@@ -536,15 -542,15 +536,15 @@@ u8 rtw_sitesurvey_cmd(struct adapter  *
        struct cmd_priv         *pcmdpriv = &padapter->cmdpriv;
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  
 -      if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
 +      if (check_fwstate(pmlmepriv, _FW_LINKED))
                rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1);
  
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL)
 +      if (!ph2c)
                return _FAIL;
  
        psurveyPara = rtw_zmalloc(sizeof(struct sitesurvey_parm));
 -      if (psurveyPara == NULL) {
 +      if (!psurveyPara) {
                kfree(ph2c);
                return _FAIL;
        }
        res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  
        if (res == _SUCCESS) {
 -
                pmlmepriv->scan_start_time = jiffies;
                _set_timer(&pmlmepriv->scan_to_timer, SCANNING_TIMEOUT);
        } else {
@@@ -601,13 -608,13 +601,13 @@@ u8 rtw_setdatarate_cmd(struct adapter *
        u8 res = _SUCCESS;
  
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        pbsetdataratepara = rtw_zmalloc(sizeof(struct setdatarate_parm));
 -      if (pbsetdataratepara == NULL) {
 +      if (!pbsetdataratepara) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
@@@ -637,7 -644,7 +637,7 @@@ u8 rtw_createbss_cmd(struct adapter  *p
        u8 res = _SUCCESS;
  
        pcmd = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (pcmd == NULL) {
 +      if (!pcmd) {
                res = _FAIL;
                goto exit;
        }
@@@ -670,7 -677,7 +670,7 @@@ int rtw_startbss_cmd(struct adapter  *p
        } else {
                /* need enqueue, prepare cmd_obj and enqueue */
                pcmd = rtw_zmalloc(sizeof(struct cmd_obj));
 -              if (pcmd == NULL) {
 +              if (!pcmd) {
                        res = _FAIL;
                        goto exit;
                }
@@@ -717,12 -724,12 +717,12 @@@ u8 rtw_joinbss_cmd(struct adapter  *pad
        struct ht_priv          *phtpriv = &pmlmepriv->htpriv;
        enum ndis_802_11_network_infrastructure ndis_network_mode = pnetwork->network.infrastructure_mode;
        struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
 -      struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
 +      struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
        u32 tmp_len;
        u8 *ptmp = NULL;
  
        pcmd = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (pcmd == NULL) {
 +      if (!pcmd) {
                res = _FAIL;
                goto exit;
        }
                case Ndis802_11AutoUnknown:
                case Ndis802_11InfrastructureMax:
                        break;
 -
                }
        }
  
        /*  If not,  we have to copy the connecting AP's MAC address to it so that */
        /*  the driver just has the bssid information for PMKIDList searching. */
  
 -      if (pmlmepriv->assoc_by_bssid == false)
 +      if (!pmlmepriv->assoc_by_bssid)
                memcpy(&pmlmepriv->assoc_bssid[0], &pnetwork->network.mac_address[0], ETH_ALEN);
  
        psecnetwork->ie_length = rtw_restruct_sec_ie(padapter, &pnetwork->network.ies[0], &psecnetwork->ies[0], pnetwork->network.ie_length);
@@@ -833,7 -841,7 +833,7 @@@ u8 rtw_disassoc_cmd(struct adapter *pad
  
        /* prepare cmd parameter */
        param = rtw_zmalloc(sizeof(*param));
 -      if (param == NULL) {
 +      if (!param) {
                res = _FAIL;
                goto exit;
        }
        if (enqueue) {
                /* need enqueue, prepare cmd_obj and enqueue */
                cmdobj = rtw_zmalloc(sizeof(*cmdobj));
 -              if (cmdobj == NULL) {
 +              if (!cmdobj) {
                        res = _FAIL;
                        kfree(param);
                        goto exit;
@@@ -870,7 -878,7 +870,7 @@@ u8 rtw_setopmode_cmd(struct adapter  *p
  
        psetop = rtw_zmalloc(sizeof(struct setopmode_parm));
  
 -      if (psetop == NULL) {
 +      if (!psetop) {
                res = _FAIL;
                goto exit;
        }
  
        if (enqueue) {
                ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -              if (ph2c == NULL) {
 +              if (!ph2c) {
                        kfree(psetop);
                        res = _FAIL;
                        goto exit;
@@@ -906,7 -914,7 +906,7 @@@ u8 rtw_setstakey_cmd(struct adapter *pa
        u8 res = _SUCCESS;
  
        psetstakey_para = rtw_zmalloc(sizeof(struct set_stakey_parm));
 -      if (psetstakey_para == NULL) {
 +      if (!psetstakey_para) {
                res = _FAIL;
                goto exit;
        }
        memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
  
        if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
 -              psetstakey_para->algorithm = (unsigned char) psecuritypriv->dot11PrivacyAlgrthm;
 +              psetstakey_para->algorithm = (unsigned char)psecuritypriv->dot11PrivacyAlgrthm;
        else
                GET_ENCRY_ALGO(psecuritypriv, sta, psetstakey_para->algorithm, false);
  
 -      if (unicast_key == true)
 +      if (unicast_key)
                memcpy(&psetstakey_para->key, &sta->dot118021x_UncstKey, 16);
        else
                memcpy(&psetstakey_para->key, &psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey, 16);
  
        if (enqueue) {
                ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -              if (ph2c == NULL) {
 +              if (!ph2c) {
                        kfree(psetstakey_para);
                        res = _FAIL;
                        goto exit;
                }
  
                psetstakey_rsp = rtw_zmalloc(sizeof(struct set_stakey_rsp));
 -              if (psetstakey_rsp == NULL) {
 +              if (!psetstakey_rsp) {
                        kfree(ph2c);
                        kfree(psetstakey_para);
                        res = _FAIL;
                }
  
                init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
 -              ph2c->rsp = (u8 *) psetstakey_rsp;
 +              ph2c->rsp = (u8 *)psetstakey_rsp;
                ph2c->rspsz = sizeof(struct set_stakey_rsp);
                res = rtw_enqueue_cmd(pcmdpriv, ph2c);
        } else {
@@@ -973,20 -981,20 +973,20 @@@ u8 rtw_clearstakey_cmd(struct adapter *
                }
        } else {
                ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -              if (ph2c == NULL) {
 +              if (!ph2c) {
                        res = _FAIL;
                        goto exit;
                }
  
                psetstakey_para = rtw_zmalloc(sizeof(struct set_stakey_parm));
 -              if (psetstakey_para == NULL) {
 +              if (!psetstakey_para) {
                        kfree(ph2c);
                        res = _FAIL;
                        goto exit;
                }
  
                psetstakey_rsp = rtw_zmalloc(sizeof(struct set_stakey_rsp));
 -              if (psetstakey_rsp == NULL) {
 +              if (!psetstakey_rsp) {
                        kfree(ph2c);
                        kfree(psetstakey_para);
                        res = _FAIL;
                }
  
                init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
 -              ph2c->rsp = (u8 *) psetstakey_rsp;
 +              ph2c->rsp = (u8 *)psetstakey_rsp;
                ph2c->rspsz = sizeof(struct set_stakey_rsp);
  
                memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN);
                psetstakey_para->algorithm = _NO_PRIVACY_;
  
                res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -
        }
 -
  exit:
        return res;
  }
@@@ -1016,13 -1026,13 +1016,13 @@@ u8 rtw_addbareq_cmd(struct adapter *pad
        u8 res = _SUCCESS;
  
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        paddbareq_parm = rtw_zmalloc(sizeof(struct addBaReq_parm));
 -      if (paddbareq_parm == NULL) {
 +      if (!paddbareq_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
@@@ -1048,13 -1058,13 +1048,13 @@@ u8 rtw_reset_securitypriv_cmd(struct ad
        u8 res = _SUCCESS;
  
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -      if (pdrvextra_cmd_parm == NULL) {
 +      if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
  
        /* rtw_enqueue_cmd(pcmdpriv, ph2c); */
        res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -
  exit:
        return res;
  }
@@@ -1082,13 -1093,13 +1082,13 @@@ u8 rtw_free_assoc_resources_cmd(struct 
        u8 res = _SUCCESS;
  
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -      if (pdrvextra_cmd_parm == NULL) {
 +      if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
  
        init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvextra_cmd_parm, GEN_CMD_CODE(_Set_Drv_Extra));
  
 -
        /* rtw_enqueue_cmd(pcmdpriv, ph2c); */
        res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -
  exit:
        return res;
  }
@@@ -1116,13 -1129,13 +1116,13 @@@ u8 rtw_dynamic_chk_wk_cmd(struct adapte
  
        /* only  primary padapter does this cmd */
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -      if (pdrvextra_cmd_parm == NULL) {
 +      if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
  
        /* rtw_enqueue_cmd(pcmdpriv, ph2c); */
        res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 -
  exit:
        return res;
  }
@@@ -1150,7 -1164,7 +1150,7 @@@ u8 rtw_set_chplan_cmd(struct adapter *p
        u8 res = _SUCCESS;
  
        /*  check if allow software config */
 -      if (swconfig && rtw_hal_is_disable_sw_channel_plan(padapter) == true) {
 +      if (swconfig && rtw_hal_is_disable_sw_channel_plan(padapter)) {
                res = _FAIL;
                goto exit;
        }
  
        /* prepare cmd parameter */
        setChannelPlan_param = rtw_zmalloc(sizeof(struct SetChannelPlan_param));
 -      if (setChannelPlan_param == NULL) {
 +      if (!setChannelPlan_param) {
                res = _FAIL;
                goto exit;
        }
        if (enqueue) {
                /* need enqueue, prepare cmd_obj and enqueue */
                pcmdobj = rtw_zmalloc(sizeof(struct cmd_obj));
 -              if (pcmdobj == NULL) {
 +              if (!pcmdobj) {
                        kfree(setChannelPlan_param);
                        res = _FAIL;
                        goto exit;
@@@ -1229,14 -1243,14 +1229,14 @@@ u8 traffic_status_watchdog(struct adapt
        u8 bBusyTraffic = false, bTxBusyTraffic = false, bRxBusyTraffic = false;
        u8 bHigherBusyTraffic = false, bHigherBusyRxTraffic = false, bHigherBusyTxTraffic = false;
  
 -      struct mlme_priv        *pmlmepriv = &(padapter->mlmepriv);
 +      struct mlme_priv        *pmlmepriv = &padapter->mlmepriv;
  
        collect_traffic_statistics(padapter);
  
        /*  */
        /*  Determine if our traffic is busy now */
        /*  */
 -      if ((check_fwstate(pmlmepriv, _FW_LINKED) == true)
 +      if ((check_fwstate(pmlmepriv, _FW_LINKED))
                /*&& !MgntInitAdapterInProgress(pMgntInfo)*/) {
                /*  if we raise bBusyTraffic in last watchdog, using lower threshold. */
                if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
                        (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 2)) {
                        bEnterPS = false;
  
 -                      if (bBusyTraffic == true) {
 +                      if (bBusyTraffic) {
                                if (pmlmepriv->LinkDetectInfo.TrafficTransitionCount <= 4)
                                        pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 4;
  
                struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
                int n_assoc_iface = 0;
  
 -              if (check_fwstate(&(dvobj->padapters->mlmepriv), WIFI_ASOC_STATE))
 +              if (check_fwstate(&dvobj->padapters->mlmepriv, WIFI_ASOC_STATE))
                        n_assoc_iface++;
  
                if (!from_timer && n_assoc_iface == 0)
@@@ -1326,18 -1340,21 +1326,18 @@@ static void dynamic_chk_wk_hdl(struct a
  {
        struct mlme_priv *pmlmepriv;
  
 -      pmlmepriv = &(padapter->mlmepriv);
 +      pmlmepriv = &padapter->mlmepriv;
  
 -      if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
 +      if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
                expire_timeout_chk(padapter);
  
        /* for debug purpose */
        _linked_info_dump(padapter);
 -
 -
        /* if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING|_FW_UNDER_SURVEY) ==false) */
        {
                linked_status_chk(padapter);
                traffic_status_watchdog(padapter, 0);
        }
 -
        rtw_hal_dm_watchdog(padapter);
  
        /* check_hw_pbc(padapter, pdrvextra_cmd->pbuf, pdrvextra_cmd->type); */
@@@ -1357,11 -1374,11 +1357,11 @@@ void lps_ctrl_wk_hdl(struct adapter *pa
  void lps_ctrl_wk_hdl(struct adapter *padapter, u8 lps_ctrl_type)
  {
        struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
 -      struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
 +      struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        u8 mstatus;
  
 -      if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)
 -              || (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)) {
 +      if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
 +              check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
                return;
        }
  
        case LPS_CTRL_SCAN:
                hal_btcoex_ScanNotify(padapter, true);
  
 -              if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
 +              if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                        /*  connect */
                        LPS_Leave(padapter, "LPS_CTRL_SCAN");
                }
@@@ -1419,13 -1436,13 +1419,13 @@@ u8 rtw_lps_ctrl_wk_cmd(struct adapter *
  
        if (enqueue) {
                ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -              if (ph2c == NULL) {
 +              if (!ph2c) {
                        res = _FAIL;
                        goto exit;
                }
  
                pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -              if (pdrvextra_cmd_parm == NULL) {
 +              if (!pdrvextra_cmd_parm) {
                        kfree(ph2c);
                        res = _FAIL;
                        goto exit;
@@@ -1461,13 -1478,13 +1461,13 @@@ u8 rtw_dm_in_lps_wk_cmd(struct adapter 
  
  
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -      if (pdrvextra_cmd_parm == NULL) {
 +      if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
        res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  
  exit:
 -
        return res;
 -
  }
  
  static void rtw_lps_change_dtim_hdl(struct adapter *padapter, u8 dtim)
        if (dtim <= 0 || dtim > 16)
                return;
  
 -      if (hal_btcoex_IsBtControlLps(padapter) == true)
 +      if (hal_btcoex_IsBtControlLps(padapter))
                return;
  
        mutex_lock(&pwrpriv->lock);
@@@ -1523,14 -1542,15 +1523,14 @@@ u8 rtw_dm_ra_mask_wk_cmd(struct adapte
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
        u8 res = _SUCCESS;
  
 -
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -      if (pdrvextra_cmd_parm == NULL) {
 +      if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
@@@ -1557,14 -1577,15 +1557,14 @@@ u8 rtw_ps_cmd(struct adapter *padapter
        struct drvextra_cmd_parm        *pdrvextra_cmd_parm;
        struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
        u8 res = _SUCCESS;
 -
        ppscmd = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ppscmd == NULL) {
 +      if (!ppscmd) {
                res = _FAIL;
                goto exit;
        }
  
        pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -      if (pdrvextra_cmd_parm == NULL) {
 +      if (!pdrvextra_cmd_parm) {
                kfree(ppscmd);
                res = _FAIL;
                goto exit;
@@@ -1597,7 -1618,7 +1597,7 @@@ static void rtw_chk_hi_queue_hdl(struc
  
        rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
  
 -      while (false == empty && jiffies_to_msecs(jiffies - start) < g_wait_hiq_empty) {
 +      while (!empty && jiffies_to_msecs(jiffies - start) < g_wait_hiq_empty) {
                msleep(100);
                rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
        }
@@@ -1630,13 -1651,13 +1630,13 @@@ u8 rtw_chk_hi_queue_cmd(struct adapter 
        u8 res = _SUCCESS;
  
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -      if (pdrvextra_cmd_parm == NULL) {
 +      if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
        res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  
  exit:
 -
        return res;
 -
  }
  
  struct btinfo {
@@@ -1722,13 -1745,13 +1722,13 @@@ u8 rtw_c2h_packet_wk_cmd(struct adapte
        u8 res = _SUCCESS;
  
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -      if (pdrvextra_cmd_parm == NULL) {
 +      if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
@@@ -1757,13 -1780,13 +1757,13 @@@ u8 rtw_c2h_wk_cmd(struct adapter *padap
        u8 res = _SUCCESS;
  
        ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
 -      if (ph2c == NULL) {
 +      if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
  
        pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
 -      if (pdrvextra_cmd_parm == NULL) {
 +      if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
@@@ -1817,7 -1840,7 +1817,7 @@@ static void c2h_wk_callback(struct work
                        continue;
                }
  
 -              if (ccx_id_filter(c2h_evt) == true) {
 +              if (ccx_id_filter(c2h_evt)) {
                        /* Handle CCX report here */
                        rtw_hal_c2h_handler(adapter, c2h_evt);
                        kfree(c2h_evt);
@@@ -1936,9 -1959,9 +1936,9 @@@ void rtw_createbss_cmd_callback(struct 
        struct wlan_network *pwlan = NULL;
        struct  mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)pcmd->parmbuf;
 -      struct wlan_network *tgt_network = &(pmlmepriv->cur_network);
 +      struct wlan_network *tgt_network = &pmlmepriv->cur_network;
  
 -      if (pcmd->parmbuf == NULL)
 +      if (!pcmd->parmbuf)
                goto exit;
  
        if (pcmd->res != H2C_SUCCESS)
                rtw_indicate_connect(padapter);
        } else {
                pwlan = rtw_alloc_network(pmlmepriv);
 -              spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
 -              if (pwlan == NULL) {
 +              spin_lock_bh(&pmlmepriv->scanned_queue.lock);
 +              if (!pwlan) {
                        pwlan = rtw_get_oldest_wlan_network(&pmlmepriv->scanned_queue);
 -                      if (pwlan == NULL) {
 -                              spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
 +                      if (!pwlan) {
 +                              spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
                                goto createbss_cmd_fail;
                        }
                        pwlan->last_scanned = jiffies;
                } else {
 -                      list_add_tail(&(pwlan->list), &pmlmepriv->scanned_queue.queue);
 +                      list_add_tail(&pwlan->list, &pmlmepriv->scanned_queue.queue);
                }
  
                pnetwork->length = get_wlan_bssid_ex_sz(pnetwork);
 -              memcpy(&(pwlan->network), pnetwork, pnetwork->length);
 +              memcpy(&pwlan->network, pnetwork, pnetwork->length);
                /* pwlan->fixed = true; */
  
                /* list_add_tail(&(pwlan->list), &pmlmepriv->scanned_queue.queue); */
  
                _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  
 -              spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
 +              spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
                /*  we will set _FW_LINKED when there is one more sat to join us (rtw_stassoc_event_callback) */
  
        }
@@@ -1998,10 -2021,13 +1998,10 @@@ exit
        rtw_free_cmd_obj(pcmd);
  }
  
 -
 -
  void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter,  struct cmd_obj *pcmd)
  {
 -
        struct sta_priv *pstapriv = &padapter->stapriv;
 -      struct set_stakey_rsp *psetstakey_rsp = (struct set_stakey_rsp *) (pcmd->rsp);
 +      struct set_stakey_rsp *psetstakey_rsp = (struct set_stakey_rsp *)(pcmd->rsp);
        struct sta_info *psta = rtw_get_stainfo(pstapriv, psetstakey_rsp->addr);
  
        if (!psta)
@@@ -2016,7 -2042,7 +2016,7 @@@ void rtw_setassocsta_cmdrsp_callback(st
        struct sta_priv *pstapriv = &padapter->stapriv;
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct set_assocsta_parm *passocsta_parm = (struct set_assocsta_parm *)(pcmd->parmbuf);
 -      struct set_assocsta_rsp *passocsta_rsp = (struct set_assocsta_rsp *) (pcmd->rsp);
 +      struct set_assocsta_rsp *passocsta_rsp = (struct set_assocsta_rsp *)(pcmd->rsp);
        struct sta_info *psta = rtw_get_stainfo(pstapriv, passocsta_parm->addr);
  
        if (!psta)
  
        spin_lock_bh(&pmlmepriv->lock);
  
 -      if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) && (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true))
 +      if (check_fwstate(pmlmepriv, WIFI_MP_STATE) && check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
                _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
  
        set_fwstate(pmlmepriv, _FW_LINKED);
index 46054d6a1fb534d6f08888bcb728d2dc71137240,0c357bc2478c821f89472c8bbbcf5c36d974f618..13b8bd5ffabc4c27cb28fd7aa5fae94528f6a526
@@@ -13,8 -13,7 +13,8 @@@ static u8 RFC1042_OUI[P80211_OUI_LEN] 
  static void _init_txservq(struct tx_servq *ptxservq)
  {
        INIT_LIST_HEAD(&ptxservq->tx_pending);
 -      _rtw_init_queue(&ptxservq->sta_pending);
 +      INIT_LIST_HEAD(&ptxservq->sta_pending.queue);
 +      spin_lock_init(&ptxservq->sta_pending.lock);
        ptxservq->qcnt = 0;
  }
  
@@@ -50,19 -49,13 +50,19 @@@ s32 _rtw_init_xmit_priv(struct xmit_pri
  
        pxmitpriv->adapter = padapter;
  
 -      _rtw_init_queue(&pxmitpriv->be_pending);
 -      _rtw_init_queue(&pxmitpriv->bk_pending);
 -      _rtw_init_queue(&pxmitpriv->vi_pending);
 -      _rtw_init_queue(&pxmitpriv->vo_pending);
 -      _rtw_init_queue(&pxmitpriv->bm_pending);
 +      INIT_LIST_HEAD(&pxmitpriv->be_pending.queue);
 +      spin_lock_init(&pxmitpriv->be_pending.lock);
 +      INIT_LIST_HEAD(&pxmitpriv->bk_pending.queue);
 +      spin_lock_init(&pxmitpriv->bk_pending.lock);
 +      INIT_LIST_HEAD(&pxmitpriv->vi_pending.queue);
 +      spin_lock_init(&pxmitpriv->vi_pending.lock);
 +      INIT_LIST_HEAD(&pxmitpriv->vo_pending.queue);
 +      spin_lock_init(&pxmitpriv->vo_pending.lock);
 +      INIT_LIST_HEAD(&pxmitpriv->bm_pending.queue);
 +      spin_lock_init(&pxmitpriv->bm_pending.lock);
  
 -      _rtw_init_queue(&pxmitpriv->free_xmit_queue);
 +      INIT_LIST_HEAD(&pxmitpriv->free_xmit_queue.queue);
 +      spin_lock_init(&pxmitpriv->free_xmit_queue.lock);
  
        /*
         * Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME,
        pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
  
        /* init xmit_buf */
 -      _rtw_init_queue(&pxmitpriv->free_xmitbuf_queue);
 -      _rtw_init_queue(&pxmitpriv->pending_xmitbuf_queue);
 +      INIT_LIST_HEAD(&pxmitpriv->free_xmitbuf_queue.queue);
 +      spin_lock_init(&pxmitpriv->free_xmitbuf_queue.lock);
 +      INIT_LIST_HEAD(&pxmitpriv->pending_xmitbuf_queue.queue);
 +      spin_lock_init(&pxmitpriv->pending_xmitbuf_queue.lock);
  
        pxmitpriv->pallocated_xmitbuf = vzalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4);
  
        pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
  
        /* init xframe_ext queue,  the same count as extbuf  */
 -      _rtw_init_queue(&pxmitpriv->free_xframe_ext_queue);
 +      INIT_LIST_HEAD(&pxmitpriv->free_xframe_ext_queue.queue);
 +      spin_lock_init(&pxmitpriv->free_xframe_ext_queue.lock);
  
        pxmitpriv->xframe_ext_alloc_addr = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_frame) + 4);
  
        pxmitpriv->free_xframe_ext_cnt = NR_XMIT_EXTBUFF;
  
        /*  Init xmit extension buff */
 -      _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue);
 +      INIT_LIST_HEAD(&pxmitpriv->free_xmit_extbuf_queue.queue);
 +      spin_lock_init(&pxmitpriv->free_xmit_extbuf_queue.lock);
  
        pxmitpriv->pallocated_xmit_extbuf = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_buf) + 4);
  
@@@ -1734,12 -1723,15 +1734,12 @@@ void rtw_free_xmitframe_queue(struct xm
        struct list_head *plist, *phead, *tmp;
        struct  xmit_frame      *pxmitframe;
  
 -      spin_lock_bh(&pframequeue->lock);
 -
        phead = get_list_head(pframequeue);
        list_for_each_safe(plist, tmp, phead) {
                pxmitframe = list_entry(plist, struct xmit_frame, list);
  
                rtw_free_xmitframe(pxmitpriv, pxmitframe);
        }
 -      spin_unlock_bh(&pframequeue->lock);
  }
  
  s32 rtw_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe)
@@@ -1794,7 -1786,6 +1794,7 @@@ s32 rtw_xmit_classifier(struct adapter 
        struct sta_info *psta;
        struct tx_servq *ptxservq;
        struct pkt_attrib       *pattrib = &pxmitframe->attrib;
 +      struct xmit_priv *xmit_priv = &padapter->xmitpriv;
        struct hw_xmit  *phwxmits =  padapter->xmitpriv.hwxmits;
        signed int res = _SUCCESS;
  
  
        ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
  
 +      spin_lock_bh(&xmit_priv->lock);
        if (list_empty(&ptxservq->tx_pending))
                list_add_tail(&ptxservq->tx_pending, get_list_head(phwxmits[ac_index].sta_queue));
  
        list_add_tail(&pxmitframe->list, get_list_head(&ptxservq->sta_pending));
        ptxservq->qcnt++;
        phwxmits[ac_index].accnt++;
 +      spin_unlock_bh(&xmit_priv->lock);
  
  exit:
  
@@@ -2202,10 -2191,11 +2202,10 @@@ void wakeup_sta_to_xmit(struct adapter 
        struct list_head *xmitframe_plist, *xmitframe_phead, *tmp;
        struct xmit_frame *pxmitframe = NULL;
        struct sta_priv *pstapriv = &padapter->stapriv;
 -      struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  
        psta_bmc = rtw_get_bcmc_stainfo(padapter);
  
 -      spin_lock_bh(&pxmitpriv->lock);
 +      spin_lock_bh(&psta->sleep_q.lock);
  
        xmitframe_phead = get_list_head(&psta->sleep_q);
        list_for_each_safe(xmitframe_plist, tmp, xmitframe_phead) {
  
  _exit:
  
 -      spin_unlock_bh(&pxmitpriv->lock);
 +      spin_unlock_bh(&psta->sleep_q.lock);
  
        if (update_mask)
                update_beacon(padapter, WLAN_EID_TIM, NULL, true);
@@@ -2318,8 -2308,9 +2318,8 @@@ void xmit_delivery_enabled_frames(struc
        struct list_head *xmitframe_plist, *xmitframe_phead, *tmp;
        struct xmit_frame *pxmitframe = NULL;
        struct sta_priv *pstapriv = &padapter->stapriv;
 -      struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  
 -      spin_lock_bh(&pxmitpriv->lock);
 +      spin_lock_bh(&psta->sleep_q.lock);
  
        xmitframe_phead = get_list_head(&psta->sleep_q);
        list_for_each_safe(xmitframe_plist, tmp, xmitframe_phead) {
                }
        }
  
 -      spin_unlock_bh(&pxmitpriv->lock);
 +      spin_unlock_bh(&psta->sleep_q.lock);
  }
  
  void enqueue_pending_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
@@@ -2500,7 -2491,7 +2500,7 @@@ int rtw_xmit_thread(void *context
  
        complete(&padapter->xmitpriv.terminate_xmitthread_comp);
  
-       thread_exit();
+       return 0;
  }
  
  void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms)
index 5f5c4719b58684d2491617afd40495e391aaf706,2b9a41b12d1f3ca8c6554d2c64072de81fc41f34..7fe3df863fe1381790b34c9c9555b962fd49e08f
@@@ -435,7 -435,7 +435,7 @@@ int rtl8723bs_xmit_thread(void *context
  
        complete(&pxmitpriv->SdioXmitTerminate);
  
-       thread_exit();
+       return 0;
  }
  
  s32 rtl8723bs_mgnt_xmit(
@@@ -507,7 -507,9 +507,7 @@@ s32 rtl8723bs_hal_xmit
                        rtw_issue_addbareq_cmd(padapter, pxmitframe);
        }
  
 -      spin_lock_bh(&pxmitpriv->lock);
        err = rtw_xmitframe_enqueue(padapter, pxmitframe);
 -      spin_unlock_bh(&pxmitpriv->lock);
        if (err != _SUCCESS) {
                rtw_free_xmitframe(pxmitpriv, pxmitframe);
  
diff --combined fs/exec.c
index b6079f1a098e84b8d46dd60cfb2474f58855e3c1,ac7b51b51f38af38422cd24abad2ddff02bb0bed..537d92c41105bcec0c07d7da2eb5a9bef40787e7
+++ b/fs/exec.c
@@@ -987,14 -987,16 +987,14 @@@ static int exec_mmap(struct mm_struct *
  
        if (old_mm) {
                /*
 -               * Make sure that if there is a core dump in progress
 -               * for the old mm, we get out and die instead of going
 -               * through with the exec.  We must hold mmap_lock around
 -               * checking core_state and changing tsk->mm.
 +               * If there is a pending fatal signal perhaps a signal
 +               * whose default action is to create a coredump get
 +               * out and die instead of going through with the exec.
                 */
 -              mmap_read_lock(old_mm);
 -              if (unlikely(old_mm->core_state)) {
 -                      mmap_read_unlock(old_mm);
 +              ret = mmap_read_lock_killable(old_mm);
 +              if (ret) {
                        up_write(&tsk->signal->exec_update_lock);
 -                      return -EINTR;
 +                      return ret;
                }
        }
  
@@@ -1850,7 -1852,7 +1850,7 @@@ out
         * SIGSEGV.
         */
        if (bprm->point_of_no_return && !fatal_signal_pending(current))
-               force_sigsegv(SIGSEGV);
+               force_fatal_sig(SIGSEGV);
  
  out_unmark:
        current->fs->in_exec = 0;
diff --combined fs/ocfs2/journal.c
index b9c339335a53db461eff6a405a3e82ce4d7da159,329986f12db32cc21fadf5984ca86b880552b0e4..dbf9b9e97d7403d6310e2a710577c3bca8bee39c
@@@ -810,34 -810,19 +810,34 @@@ void ocfs2_set_journal_params(struct oc
        write_unlock(&journal->j_state_lock);
  }
  
 -int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty)
 +int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty)
  {
        int status = -1;
        struct inode *inode = NULL; /* the journal inode */
        journal_t *j_journal = NULL;
 +      struct ocfs2_journal *journal = NULL;
        struct ocfs2_dinode *di = NULL;
        struct buffer_head *bh = NULL;
 -      struct ocfs2_super *osb;
        int inode_lock = 0;
  
 -      BUG_ON(!journal);
 +      /* initialize our journal structure */
 +      journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
 +      if (!journal) {
 +              mlog(ML_ERROR, "unable to alloc journal\n");
 +              status = -ENOMEM;
 +              goto done;
 +      }
 +      osb->journal = journal;
 +      journal->j_osb = osb;
  
 -      osb = journal->j_osb;
 +      atomic_set(&journal->j_num_trans, 0);
 +      init_rwsem(&journal->j_trans_barrier);
 +      init_waitqueue_head(&journal->j_checkpointed);
 +      spin_lock_init(&journal->j_lock);
 +      journal->j_trans_id = 1UL;
 +      INIT_LIST_HEAD(&journal->j_la_cleanups);
 +      INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
 +      journal->j_state = OCFS2_JOURNAL_FREE;
  
        /* already have the inode for our journal */
        inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE,
@@@ -1043,10 -1028,9 +1043,10 @@@ void ocfs2_journal_shutdown(struct ocfs
  
        journal->j_state = OCFS2_JOURNAL_FREE;
  
 -//    up_write(&journal->j_trans_barrier);
  done:
        iput(inode);
 +      kfree(journal);
 +      osb->journal = NULL;
  }
  
  static void ocfs2_clear_journal_error(struct super_block *sb,
@@@ -1513,10 -1497,7 +1513,7 @@@ bail
        if (quota_enabled)
                kfree(rm_quota);
  
-       /* no one is callint kthread_stop() for us so the kthread() api
-        * requires that we call do_exit().  And it isn't exported, but
-        * complete_and_exit() seems to be a minimal wrapper around it. */
-       complete_and_exit(NULL, status);
+       return status;
  }
  
  void ocfs2_recovery_thread(struct ocfs2_super *osb, int node_num)
index a8fe2a593a3a6c4b112fcd571776ed6c36c63ff3,e2dc9f119adae95e5190419d702e1ccf46720255..23505394ef7091d36219cd28b2e4ad617226f920
@@@ -72,17 -72,6 +72,17 @@@ struct multiprocess_signals 
        struct hlist_node node;
  };
  
 +struct core_thread {
 +      struct task_struct *task;
 +      struct core_thread *next;
 +};
 +
 +struct core_state {
 +      atomic_t nr_threads;
 +      struct core_thread dumper;
 +      struct completion startup;
 +};
 +
  /*
   * NOTE! "signal_struct" does not have its own
   * locking, because a shared signal_struct always
@@@ -121,8 -110,6 +121,8 @@@ struct signal_struct 
        int                     group_stop_count;
        unsigned int            flags; /* see SIGNAL_* flags below */
  
 +      struct core_state *core_state; /* coredumping support */
 +
        /*
         * PR_SET_CHILD_SUBREAPER marks a process, like a service
         * manager, to re-parent orphan (double-forking) child processes
@@@ -351,6 -338,7 +351,7 @@@ extern int kill_pid(struct pid *pid, in
  extern __must_check bool do_notify_parent(struct task_struct *, int);
  extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent);
  extern void force_sig(int);
+ extern void force_fatal_sig(int);
  extern int send_sig(int, struct task_struct *, int);
  extern int zap_other_threads(struct task_struct *p);
  extern struct sigqueue *sigqueue_alloc(void);
diff --combined kernel/kthread.c
index 4a4d7092a2d828d036dccee30bee7af8f043800a,33e17beaa682969cf33f8a71d57c3ccd29fa480f..7113003fab63de346d107eab584b612188f9d835
@@@ -270,7 -270,6 +270,7 @@@ EXPORT_SYMBOL_GPL(kthread_parkme)
  
  static int kthread(void *_create)
  {
 +      static const struct sched_param param = { .sched_priority = 0 };
        /* Copy data: it's on kthread's stack */
        struct kthread_create_info *create = _create;
        int (*threadfn)(void *data) = create->threadfn;
        init_completion(&self->parked);
        current->vfork_done = &self->exited;
  
 +      /*
 +       * The new thread inherited kthreadd's priority and CPU mask. Reset
 +       * back to default in case they have been changed.
 +       */
 +      sched_setscheduler_nocheck(current, SCHED_NORMAL, &param);
 +      set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_KTHREAD));
 +
        /* OK, tell user we're spawned, wait for stop or wakeup */
        __set_current_state(TASK_UNINTERRUPTIBLE);
        create->result = current;
@@@ -405,6 -397,7 +405,6 @@@ struct task_struct *__kthread_create_on
        }
        task = create->result;
        if (!IS_ERR(task)) {
 -              static const struct sched_param param = { .sched_priority = 0 };
                char name[TASK_COMM_LEN];
  
                /*
                 */
                vsnprintf(name, sizeof(name), namefmt, args);
                set_task_comm(task, name);
 -              /*
 -               * root may have changed our (kthreadd's) priority or CPU mask.
 -               * The kernel thread should not inherit these properties.
 -               */
 -              sched_setscheduler_nocheck(task, SCHED_NORMAL, &param);
 -              set_cpus_allowed_ptr(task,
 -                                   housekeeping_cpumask(HK_FLAG_KTHREAD));
        }
        kfree(create);
        return task;
   * If thread is going to be bound on a particular cpu, give its node
   * in @node, to get NUMA affinity for kthread stack, or else give NUMA_NO_NODE.
   * When woken, the thread will run @threadfn() with @data as its
-  * argument. @threadfn() can either call do_exit() directly if it is a
+  * argument. @threadfn() can either return directly if it is a
   * standalone thread for which no one will call kthread_stop(), or
   * return when 'kthread_should_stop()' is true (which means
   * kthread_stop() has been called).  The return value should be zero
diff --combined kernel/signal.c
index 6f3476dc787325c136a8a79e58e9963b1b57bc67,056a107e3cbc085e8ae039990920b3846df25ccb..7c4b7ae714d47f942c87547518112fbb5be35bf3
@@@ -426,10 -426,22 +426,10 @@@ __sigqueue_alloc(int sig, struct task_s
         */
        rcu_read_lock();
        ucounts = task_ucounts(t);
 -      sigpending = inc_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING, 1);
 -      switch (sigpending) {
 -      case 1:
 -              if (likely(get_ucounts(ucounts)))
 -                      break;
 -              fallthrough;
 -      case LONG_MAX:
 -              /*
 -               * we need to decrease the ucount in the userns tree on any
 -               * failure to avoid counts leaking.
 -               */
 -              dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING, 1);
 -              rcu_read_unlock();
 -              return NULL;
 -      }
 +      sigpending = inc_rlimit_get_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING);
        rcu_read_unlock();
 +      if (!sigpending)
 +              return NULL;
  
        if (override_rlimit || likely(sigpending <= task_rlimit(t, RLIMIT_SIGPENDING))) {
                q = kmem_cache_alloc(sigqueue_cachep, gfp_flags);
        }
  
        if (unlikely(q == NULL)) {
 -              if (dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING, 1))
 -                      put_ucounts(ucounts);
 +              dec_rlimit_put_ucounts(ucounts, UCOUNT_RLIMIT_SIGPENDING);
        } else {
                INIT_LIST_HEAD(&q->list);
                q->flags = sigqueue_flags;
@@@ -451,8 -464,8 +451,8 @@@ static void __sigqueue_free(struct sigq
  {
        if (q->flags & SIGQUEUE_PREALLOC)
                return;
 -      if (q->ucounts && dec_rlimit_ucounts(q->ucounts, UCOUNT_RLIMIT_SIGPENDING, 1)) {
 -              put_ucounts(q->ucounts);
 +      if (q->ucounts) {
 +              dec_rlimit_put_ucounts(q->ucounts, UCOUNT_RLIMIT_SIGPENDING);
                q->ucounts = NULL;
        }
        kmem_cache_free(sigqueue_cachep, q);
@@@ -1323,6 -1336,7 +1323,7 @@@ force_sig_info_to_task(struct kernel_si
        blocked = sigismember(&t->blocked, sig);
        if (blocked || ignored || sigdfl) {
                action->sa.sa_handler = SIG_DFL;
+               action->sa.sa_flags |= SA_IMMUTABLE;
                if (blocked) {
                        sigdelset(&t->blocked, sig);
                        recalc_sigpending_and_wake(t);
@@@ -1649,6 -1663,19 +1650,19 @@@ void force_sig(int sig
  }
  EXPORT_SYMBOL(force_sig);
  
+ void force_fatal_sig(int sig)
+ {
+       struct kernel_siginfo info;
+       clear_siginfo(&info);
+       info.si_signo = sig;
+       info.si_errno = 0;
+       info.si_code = SI_KERNEL;
+       info.si_pid = 0;
+       info.si_uid = 0;
+       force_sig_info_to_task(&info, current, true);
+ }
  /*
   * When things go south during signal handling, we
   * will force a SIGSEGV. And if the signal that caused
   */
  void force_sigsegv(int sig)
  {
-       struct task_struct *p = current;
-       if (sig == SIGSEGV) {
-               unsigned long flags;
-               spin_lock_irqsave(&p->sighand->siglock, flags);
-               p->sighand->action[sig - 1].sa.sa_handler = SIG_DFL;
-               spin_unlock_irqrestore(&p->sighand->siglock, flags);
-       }
-       force_sig(SIGSEGV);
+       if (sig == SIGSEGV)
+               force_fatal_sig(SIGSEGV);
+       else
+               force_sig(SIGSEGV);
  }
  
  int force_sig_fault_to_task(int sig, int code, void __user *addr
@@@ -2145,6 -2167,40 +2154,6 @@@ static void do_notify_parent_cldstop(st
        spin_unlock_irqrestore(&sighand->siglock, flags);
  }
  
 -static inline bool may_ptrace_stop(void)
 -{
 -      if (!likely(current->ptrace))
 -              return false;
 -      /*
 -       * Are we in the middle of do_coredump?
 -       * If so and our tracer is also part of the coredump stopping
 -       * is a deadlock situation, and pointless because our tracer
 -       * is dead so don't allow us to stop.
 -       * If SIGKILL was already sent before the caller unlocked
 -       * ->siglock we must see ->core_state != NULL. Otherwise it
 -       * is safe to enter schedule().
 -       *
 -       * This is almost outdated, a task with the pending SIGKILL can't
 -       * block in TASK_TRACED. But PTRACE_EVENT_EXIT can be reported
 -       * after SIGKILL was already dequeued.
 -       */
 -      if (unlikely(current->mm->core_state) &&
 -          unlikely(current->mm == current->parent->mm))
 -              return false;
 -
 -      return true;
 -}
 -
 -/*
 - * Return non-zero if there is a SIGKILL that should be waking us up.
 - * Called with the siglock held.
 - */
 -static bool sigkill_pending(struct task_struct *tsk)
 -{
 -      return sigismember(&tsk->pending.signal, SIGKILL) ||
 -             sigismember(&tsk->signal->shared_pending.signal, SIGKILL);
 -}
 -
  /*
   * This must be called with current->sighand->siglock held.
   *
@@@ -2162,7 -2218,7 +2171,7 @@@ static void ptrace_stop(int exit_code, 
  {
        bool gstop_done = false;
  
 -      if (arch_ptrace_stop_needed(exit_code, info)) {
 +      if (arch_ptrace_stop_needed()) {
                /*
                 * The arch code has something special to do before a
                 * ptrace stop.  This is allowed to block, e.g. for faults
                 * calling arch_ptrace_stop, so we must release it now.
                 * To preserve proper semantics, we must do this before
                 * any signal bookkeeping like checking group_stop_count.
 -               * Meanwhile, a SIGKILL could come in before we retake the
 -               * siglock.  That must prevent us from sleeping in TASK_TRACED.
 -               * So after regaining the lock, we must check for SIGKILL.
                 */
                spin_unlock_irq(&current->sighand->siglock);
 -              arch_ptrace_stop(exit_code, info);
 +              arch_ptrace_stop();
                spin_lock_irq(&current->sighand->siglock);
 -              if (sigkill_pending(current))
 -                      return;
        }
  
 +      /*
 +       * schedule() will not sleep if there is a pending signal that
 +       * can awaken the task.
 +       */
        set_special_state(TASK_TRACED);
  
        /*
  
        spin_unlock_irq(&current->sighand->siglock);
        read_lock(&tasklist_lock);
 -      if (may_ptrace_stop()) {
 +      if (likely(current->ptrace)) {
                /*
                 * Notify parents of the stop.
                 *
@@@ -2704,7 -2761,8 +2713,8 @@@ relock
                if (!signr)
                        break; /* will return 0 */
  
-               if (unlikely(current->ptrace) && signr != SIGKILL) {
+               if (unlikely(current->ptrace) && (signr != SIGKILL) &&
+                   !(sighand->action[signr -1].sa.sa_flags & SA_IMMUTABLE)) {
                        signr = ptrace_signal(signr, &ksig->info);
                        if (!signr)
                                continue;
@@@ -4054,6 -4112,10 +4064,10 @@@ int do_sigaction(int sig, struct k_siga
        k = &p->sighand->action[sig-1];
  
        spin_lock_irq(&p->sighand->siglock);
+       if (k->sa.sa_flags & SA_IMMUTABLE) {
+               spin_unlock_irq(&p->sighand->siglock);
+               return -EINVAL;
+       }
        if (oact)
                *oact = *k;
  
        return 0;
  }
  
 +#ifdef CONFIG_DYNAMIC_SIGFRAME
 +static inline void sigaltstack_lock(void)
 +      __acquires(&current->sighand->siglock)
 +{
 +      spin_lock_irq(&current->sighand->siglock);
 +}
 +
 +static inline void sigaltstack_unlock(void)
 +      __releases(&current->sighand->siglock)
 +{
 +      spin_unlock_irq(&current->sighand->siglock);
 +}
 +#else
 +static inline void sigaltstack_lock(void) { }
 +static inline void sigaltstack_unlock(void) { }
 +#endif
 +
  static int
  do_sigaltstack (const stack_t *ss, stack_t *oss, unsigned long sp,
                size_t min_ss_size)
  {
        struct task_struct *t = current;
 +      int ret = 0;
  
        if (oss) {
                memset(oss, 0, sizeof(stack_t));
                                ss_mode != 0))
                        return -EINVAL;
  
 +              sigaltstack_lock();
                if (ss_mode == SS_DISABLE) {
                        ss_size = 0;
                        ss_sp = NULL;
                } else {
                        if (unlikely(ss_size < min_ss_size))
 -                              return -ENOMEM;
 +                              ret = -ENOMEM;
 +                      if (!sigaltstack_size_valid(ss_size))
 +                              ret = -ENOMEM;
                }
 -
 -              t->sas_ss_sp = (unsigned long) ss_sp;
 -              t->sas_ss_size = ss_size;
 -              t->sas_ss_flags = ss_flags;
 +              if (!ret) {
 +                      t->sas_ss_sp = (unsigned long) ss_sp;
 +                      t->sas_ss_size = ss_size;
 +                      t->sas_ss_flags = ss_flags;
 +              }
 +              sigaltstack_unlock();
        }
 -      return 0;
 +      return ret;
  }
  
  SYSCALL_DEFINE2(sigaltstack,const stack_t __user *,uss, stack_t __user *,uoss)
index fbcb15c7c29b6ed091f6b2f56413c506ed24c988,1252540cde17937029b0dedfc8fa507dc04afa49..93730d30af544ca810a5ea212397686023cc925e
@@@ -631,9 -631,9 +631,9 @@@ static void batadv_tp_recv_ack(struct b
        struct batadv_orig_node *orig_node = NULL;
        const struct batadv_icmp_tp_packet *icmp;
        struct batadv_tp_vars *tp_vars;
 +      const unsigned char *dev_addr;
        size_t packet_len, mss;
        u32 rtt, recv_ack, cwnd;
 -      unsigned char *dev_addr;
  
        packet_len = BATADV_TP_PLEN;
        mss = BATADV_TP_PLEN;
@@@ -890,7 -890,7 +890,7 @@@ out
  
        batadv_tp_vars_put(tp_vars);
  
-       do_exit(0);
+       return 0;
  }
  
  /**
This page took 0.255583 seconds and 4 git commands to generate.