staging: rtl8188eu: rtw_cmd: Clean up tests if NULL returned on failure
[cascardo/linux.git] / drivers / staging / rtl8188eu / core / rtw_cmd.c
index 433b926..7748523 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- *
  ******************************************************************************/
 #define _RTW_CMD_C_
 
@@ -69,23 +64,17 @@ exit:
        return _SUCCESS;
 }
 
-struct cmd_obj *rtw_dequeue_cmd(struct __queue *queue)
+struct cmd_obj *rtw_dequeue_cmd(struct __queue *queue)
 {
        unsigned long irqL;
        struct cmd_obj *obj;
 
-
        spin_lock_irqsave(&queue->lock, irqL);
-       if (list_empty(&(queue->queue))) {
-               obj = NULL;
-       } else {
-               obj = container_of((&queue->queue)->next, struct cmd_obj, list);
+       obj = list_first_entry_or_null(&queue->queue, struct cmd_obj, list);
+       if (obj)
                list_del_init(&obj->list);
-       }
-
        spin_unlock_irqrestore(&queue->lock, irqL);
 
-
        return obj;
 }
 
@@ -269,11 +258,11 @@ u8 rtw_sitesurvey_cmd(struct adapter  *padapter, struct ndis_802_11_ssid *ssid,
                rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1);
 
        ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
-       if (ph2c == NULL)
+       if (!ph2c)
                return _FAIL;
 
        psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
-       if (psurveyPara == NULL) {
+       if (!psurveyPara) {
                kfree(ph2c);
                return _FAIL;
        }
@@ -356,7 +345,7 @@ u8 rtw_createbss_cmd(struct adapter  *padapter)
                RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, (" createbss for SSid:%s\n", pmlmepriv->assoc_ssid.Ssid));
 
        pcmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
-       if (pcmd == NULL) {
+       if (!pcmd) {
                res = _FAIL;
                goto exit;
        }
@@ -400,9 +389,8 @@ u8 rtw_joinbss_cmd(struct adapter  *padapter, struct wlan_network *pnetwork)
                RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+Join cmd: SSid =[%s]\n", pmlmepriv->assoc_ssid.Ssid));
 
        pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
-       if (pcmd == NULL) {
+       if (!pcmd) {
                res = _FAIL;
-               RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("rtw_joinbss_cmd: memory allocate for cmd_obj fail!!!\n"));
                goto exit;
        }
        /* for IEs is fix buf size */
@@ -528,7 +516,7 @@ u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueu
 
        /* prepare cmd parameter */
        param = kzalloc(sizeof(*param), GFP_KERNEL);
-       if (param == NULL) {
+       if (!param) {
                res = _FAIL;
                goto exit;
        }
@@ -537,7 +525,7 @@ u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueu
        if (enqueue) {
                /* need enqueue, prepare cmd_obj and enqueue */
                cmdobj = kzalloc(sizeof(*cmdobj), GFP_KERNEL);
-               if (cmdobj == NULL) {
+               if (!cmdobj) {
                        res = _FAIL;
                        kfree(param);
                        goto exit;
@@ -636,20 +624,20 @@ u8 rtw_clearstakey_cmd(struct adapter *padapter, u8 *psta, u8 entry, u8 enqueue)
                clear_cam_entry(padapter, entry);
        } else {
                ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
-               if (ph2c == NULL) {
+               if (!ph2c) {
                        res = _FAIL;
                        goto exit;
                }
 
                psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_ATOMIC);
-               if (psetstakey_para == NULL) {
+               if (!psetstakey_para) {
                        kfree(ph2c);
                        res = _FAIL;
                        goto exit;
                }
 
                psetstakey_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_ATOMIC);
-               if (psetstakey_rsp == NULL) {
+               if (!psetstakey_rsp) {
                        kfree(ph2c);
                        kfree(psetstakey_para);
                        res = _FAIL;
@@ -683,13 +671,13 @@ u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr)
 
 
        ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
-       if (ph2c == NULL) {
+       if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
 
        paddbareq_parm = kzalloc(sizeof(struct addBaReq_parm), GFP_KERNEL);
-       if (paddbareq_parm == NULL) {
+       if (!paddbareq_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
@@ -720,13 +708,13 @@ u8 rtw_dynamic_chk_wk_cmd(struct adapter *padapter)
 
 
        ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
-       if (ph2c == NULL) {
+       if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
 
        pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
-       if (pdrvextra_cmd_parm == NULL) {
+       if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
@@ -764,7 +752,7 @@ u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue)
 
        /* prepare cmd parameter */
        setChannelPlan_param = kzalloc(sizeof(struct SetChannelPlan_param), GFP_KERNEL);
-       if (setChannelPlan_param == NULL) {
+       if (!setChannelPlan_param) {
                res = _FAIL;
                goto exit;
        }
@@ -773,7 +761,7 @@ u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue)
        if (enqueue) {
                /* need enqueue, prepare cmd_obj and enqueue */
                pcmdobj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
-               if (pcmdobj == NULL) {
+               if (!pcmdobj) {
                        kfree(setChannelPlan_param);
                        res = _FAIL;
                        goto exit;
@@ -932,13 +920,13 @@ u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue)
 
        if (enqueue) {
                ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
-               if (ph2c == NULL) {
+               if (!ph2c) {
                        res = _FAIL;
                        goto exit;
                }
 
                pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
-               if (pdrvextra_cmd_parm == NULL) {
+               if (!pdrvextra_cmd_parm) {
                        kfree(ph2c);
                        res = _FAIL;
                        goto exit;
@@ -975,13 +963,13 @@ u8 rtw_rpt_timer_cfg_cmd(struct adapter *padapter, u16 min_time)
        u8      res = _SUCCESS;
 
        ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
-       if (ph2c == NULL) {
+       if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
 
        pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
-       if (pdrvextra_cmd_parm == NULL) {
+       if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;
@@ -1017,13 +1005,13 @@ u8 rtw_antenna_select_cmd(struct adapter *padapter, u8 antenna, u8 enqueue)
 
        if (enqueue) {
                ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
-               if (ph2c == NULL) {
+               if (!ph2c) {
                        res = _FAIL;
                        goto exit;
                }
 
                pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL);
-               if (pdrvextra_cmd_parm == NULL) {
+               if (!pdrvextra_cmd_parm) {
                        kfree(ph2c);
                        res = _FAIL;
                        goto exit;
@@ -1115,13 +1103,13 @@ u8 rtw_chk_hi_queue_cmd(struct adapter *padapter)
        u8      res = _SUCCESS;
 
        ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
-       if (ph2c == NULL) {
+       if (!ph2c) {
                res = _FAIL;
                goto exit;
        }
 
        pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL);
-       if (pdrvextra_cmd_parm == NULL) {
+       if (!pdrvextra_cmd_parm) {
                kfree(ph2c);
                res = _FAIL;
                goto exit;