staging: rtl8712: use list_first_entry_or_null()
authorGeliang Tang <geliangtang@163.com>
Mon, 1 Feb 2016 14:47:03 +0000 (22:47 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 8 Feb 2016 03:53:04 +0000 (19:53 -0800)
Use list_first_entry_or_null() instead of list_empty() + LIST_CONTAINOR()
to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8712/rtl871x_cmd.c
drivers/staging/rtl8712/rtl871x_mlme.c
drivers/staging/rtl8712/rtl871x_recv.c
drivers/staging/rtl8712/rtl871x_sta_mgt.c
drivers/staging/rtl8712/rtl871x_xmit.c

index 562a102031277aa25672d33a2637835a54c81ed5..587567757f4b39e1c33885aab9d6aaf1ab75e966 100644 (file)
@@ -136,15 +136,12 @@ static struct cmd_obj *_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 = LIST_CONTAINOR(queue->queue.next,
-                                    struct cmd_obj, list);
+       spin_lock_irqsave(&queue->lock, irqL);
+       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);
+       spin_unlock_irqrestore(&queue->lock, irqL);
        return obj;
 }
 
index 04f727fc95eae192d6ca5c3feea449302dc1262d..1b022dbda04651da2697cf729b4fb90bc257ea77 100644 (file)
@@ -87,16 +87,15 @@ struct wlan_network *_r8712_alloc_network(struct mlme_priv *pmlmepriv)
        unsigned long irqL;
        struct wlan_network *pnetwork;
        struct  __queue *free_queue = &pmlmepriv->free_bss_pool;
-       struct list_head *plist = NULL;
 
-       if (list_empty(&free_queue->queue))
-               return NULL;
        spin_lock_irqsave(&free_queue->lock, irqL);
-       plist = free_queue->queue.next;
-       pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
-       list_del_init(&pnetwork->list);
-       pnetwork->last_scanned = jiffies;
-       pmlmepriv->num_of_scanned++;
+       pnetwork = list_first_entry_or_null(&free_queue->queue,
+                                           struct wlan_network, list);
+       if (pnetwork) {
+               list_del_init(&pnetwork->list);
+               pnetwork->last_scanned = jiffies;
+               pmlmepriv->num_of_scanned++;
+       }
        spin_unlock_irqrestore(&free_queue->lock, irqL);
        return pnetwork;
 }
index 2a8c49272580a776316b9495e10ebe8d22b7cf2b..616ca396591983b94227d4874d1c4c71482da78a 100644 (file)
@@ -101,21 +101,17 @@ void _r8712_free_recv_priv(struct recv_priv *precvpriv)
        r8712_free_recv_priv(precvpriv);
 }
 
-union recv_frame *r8712_alloc_recvframe(struct  __queue *pfree_recv_queue)
+union recv_frame *r8712_alloc_recvframe(struct __queue *pfree_recv_queue)
 {
        unsigned long irqL;
        union recv_frame  *precvframe;
-       struct list_head *plist, *phead;
        struct _adapter *padapter;
        struct recv_priv *precvpriv;
 
        spin_lock_irqsave(&pfree_recv_queue->lock, irqL);
-       if (list_empty(&pfree_recv_queue->queue)) {
-               precvframe = NULL;
-       } else {
-               phead = &pfree_recv_queue->queue;
-               plist = phead->next;
-               precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
+       precvframe = list_first_entry_or_null(&pfree_recv_queue->queue,
+                                             union recv_frame, u.hdr.list);
+       if (precvframe) {
                list_del_init(&precvframe->u.hdr.list);
                padapter = precvframe->u.hdr.adapter;
                if (padapter != NULL) {
index d5e18aa57e076be607cf00a620951cf9fd0282be..3fe45b6d4853170b8cf5f2a18a264713bcefcd36 100644 (file)
@@ -111,13 +111,11 @@ struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
        unsigned long flags;
 
        pfree_sta_queue = &pstapriv->free_sta_queue;
-       spin_lock_irqsave(&(pfree_sta_queue->lock), flags);
-       if (list_empty(&pfree_sta_queue->queue)) {
-               psta = NULL;
-       } else {
-               psta = LIST_CONTAINOR(pfree_sta_queue->queue.next,
-                                     struct sta_info, list);
-               list_del_init(&(psta->list));
+       spin_lock_irqsave(&pfree_sta_queue->lock, flags);
+       psta = list_first_entry_or_null(&pfree_sta_queue->queue,
+                                       struct sta_info, list);
+       if (psta) {
+               list_del_init(&psta->list);
                _init_stainfo(psta);
                memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
                index = wifi_mac_hash(hwaddr);
@@ -125,7 +123,7 @@ struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
                        psta = NULL;
                        goto exit;
                }
-               phash_list = &(pstapriv->sta_hash[index]);
+               phash_list = &pstapriv->sta_hash[index];
                list_add_tail(&psta->hash_list, phash_list);
                pstapriv->asoc_sta_count++;
 
@@ -149,7 +147,7 @@ struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
                }
        }
 exit:
-       spin_unlock_irqrestore(&(pfree_sta_queue->lock), flags);
+       spin_unlock_irqrestore(&pfree_sta_queue->lock, flags);
        return psta;
 }
 
index 68d65d230fe3e0a25645f32c2d3875323b0105a4..7089ebd51d8878bc1fb17521417ed8b22ea95f1c 100644 (file)
@@ -741,21 +741,16 @@ void r8712_update_protection(struct _adapter *padapter, u8 *ie, uint ie_len)
 struct xmit_buf *r8712_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
 {
        unsigned long irqL;
-       struct xmit_buf *pxmitbuf =  NULL;
-       struct list_head *plist, *phead;
+       struct xmit_buf *pxmitbuf;
        struct  __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
 
        spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
-       if (list_empty(&pfree_xmitbuf_queue->queue)) {
-               pxmitbuf = NULL;
-       } else {
-               phead = &pfree_xmitbuf_queue->queue;
-               plist = phead->next;
-               pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
-               list_del_init(&(pxmitbuf->list));
-       }
-       if (pxmitbuf !=  NULL)
+       pxmitbuf = list_first_entry_or_null(&pfree_xmitbuf_queue->queue,
+                                           struct xmit_buf, list);
+       if (pxmitbuf) {
+               list_del_init(&pxmitbuf->list);
                pxmitpriv->free_xmitbuf_cnt--;
+       }
        spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irqL);
        return pxmitbuf;
 }
@@ -795,20 +790,14 @@ struct xmit_frame *r8712_alloc_xmitframe(struct xmit_priv *pxmitpriv)
                pfree_xmit_queue
        */
        unsigned long irqL;
-       struct xmit_frame *pxframe = NULL;
-       struct list_head *plist, *phead;
+       struct xmit_frame *pxframe;
        struct  __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
 
        spin_lock_irqsave(&pfree_xmit_queue->lock, irqL);
-       if (list_empty(&pfree_xmit_queue->queue)) {
-               pxframe =  NULL;
-       } else {
-               phead = &pfree_xmit_queue->queue;
-               plist = phead->next;
-               pxframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
-               list_del_init(&(pxframe->list));
-       }
-       if (pxframe !=  NULL) {
+       pxframe = list_first_entry_or_null(&pfree_xmit_queue->queue,
+                                          struct xmit_frame, list);
+       if (pxframe) {
+               list_del_init(&pxframe->list);
                pxmitpriv->free_xmitframe_cnt--;
                pxframe->buf_addr = NULL;
                pxframe->pxmitbuf = NULL;