Commit 818ff7b2 authored by Geliang Tang's avatar Geliang Tang Committed by Greg Kroah-Hartman

staging: rtl8712: use list_first_entry_or_null()

Use list_first_entry_or_null() instead of list_empty() + LIST_CONTAINOR()
to simplify the code.
Signed-off-by: default avatarGeliang Tang <geliangtang@163.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 97e2ba90
......@@ -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,
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;
}
......
......@@ -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);
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;
}
......
......@@ -105,17 +105,13 @@ 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) {
......
......@@ -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,
spin_lock_irqsave(&pfree_sta_queue->lock, flags);
psta = list_first_entry_or_null(&pfree_sta_queue->queue,
struct sta_info, list);
list_del_init(&(psta->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;
}
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment