From b9f1c275b695ff9339cfd0c2ea841f53d4205611 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Mon, 1 Feb 2016 22:37:13 +0800 Subject: [PATCH] staging: rtl8188eu: use list_first_entry_or_null() Use list_first_entry_or_null() instead of list_empty() + container_of() to simplify the code. Signed-off-by: Geliang Tang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/rtl8188eu/core/rtw_cmd.c | 12 +-- drivers/staging/rtl8188eu/core/rtw_mlme.c | 19 ++--- drivers/staging/rtl8188eu/core/rtw_recv.c | 15 +--- drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 23 +++--- drivers/staging/rtl8188eu/core/rtw_xmit.c | 84 ++++++-------------- 5 files changed, 48 insertions(+), 105 deletions(-) diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c index 433b926ceae7..1de792905e82 100644 --- a/drivers/staging/rtl8188eu/core/rtw_cmd.c +++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c @@ -69,23 +69,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; } diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c index abab854e6889..9c2e65904c0f 100644 --- a/drivers/staging/rtl8188eu/core/rtw_mlme.c +++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c @@ -128,25 +128,22 @@ void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv) } } -struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv)/* _queue *free_queue) */ +struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv) + /* _queue *free_queue) */ { - struct wlan_network *pnetwork; + struct wlan_network *pnetwork; struct __queue *free_queue = &pmlmepriv->free_bss_pool; - struct list_head *plist = NULL; spin_lock_bh(&free_queue->lock); - - if (list_empty(&free_queue->queue)) { - pnetwork = NULL; + pnetwork = list_first_entry_or_null(&free_queue->queue, + struct wlan_network, list); + if (!pnetwork) goto exit; - } - plist = free_queue->queue.next; - - pnetwork = container_of(plist, struct wlan_network, list); list_del_init(&pnetwork->list); - RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("_rtw_alloc_network: ptr=%p\n", plist)); + RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, + ("_rtw_alloc_network: ptr=%p\n", &pnetwork->list)); pnetwork->network_type = 0; pnetwork->fixed = false; pnetwork->last_scanned = jiffies; diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c index 3f03999b4d22..c81639cae1ea 100644 --- a/drivers/staging/rtl8188eu/core/rtw_recv.c +++ b/drivers/staging/rtl8188eu/core/rtw_recv.c @@ -127,22 +127,15 @@ void _rtw_free_recv_priv(struct recv_priv *precvpriv) struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue) { struct recv_frame *hdr; - struct list_head *plist, *phead; struct adapter *padapter; struct recv_priv *precvpriv; - if (list_empty(&pfree_recv_queue->queue)) { - hdr = NULL; - } else { - phead = get_list_head(pfree_recv_queue); - - plist = phead->next; - - hdr = container_of(plist, struct recv_frame, list); - + hdr = list_first_entry_or_null(&pfree_recv_queue->queue, + struct recv_frame, list); + if (hdr) { list_del_init(&hdr->list); padapter = hdr->adapter; - if (padapter != NULL) { + if (padapter) { precvpriv = &padapter->recvpriv; if (pfree_recv_queue == &precvpriv->free_recv_queue) precvpriv->free_recvframe_cnt--; diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c index 1beeac46bfe7..ce655b6d9a23 100644 --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c @@ -179,9 +179,9 @@ u32 _rtw_free_sta_priv(struct sta_priv *pstapriv) return _SUCCESS; } -struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr) +struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr) { - s32 index; + s32 index; struct list_head *phash_list; struct sta_info *psta; struct __queue *pfree_sta_queue; @@ -189,17 +189,15 @@ struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr) int i = 0; u16 wRxSeqInitialValue = 0xffff; - pfree_sta_queue = &pstapriv->free_sta_queue; - spin_lock_bh(&(pfree_sta_queue->lock)); - - if (list_empty(&pfree_sta_queue->queue)) { + spin_lock_bh(&pfree_sta_queue->lock); + psta = list_first_entry_or_null(&pfree_sta_queue->queue, + struct sta_info, list); + if (!psta) { spin_unlock_bh(&pfree_sta_queue->lock); - psta = NULL; } else { - psta = container_of((&pfree_sta_queue->queue)->next, struct sta_info, list); - list_del_init(&(psta->list)); + list_del_init(&psta->list); spin_unlock_bh(&pfree_sta_queue->lock); _rtw_init_stainfo(psta); memcpy(psta->hwaddr, hwaddr, ETH_ALEN); @@ -210,14 +208,11 @@ struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr) psta = NULL; goto exit; } - phash_list = &(pstapriv->sta_hash[index]); - - spin_lock_bh(&(pstapriv->sta_hash_lock)); + phash_list = &pstapriv->sta_hash[index]; + spin_lock_bh(&pstapriv->sta_hash_lock); list_add_tail(&psta->hash_list, phash_list); - pstapriv->asoc_sta_count++; - spin_unlock_bh(&pstapriv->sta_hash_lock); /* Commented by Albert 2009/08/13 */ diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c b/drivers/staging/rtl8188eu/core/rtw_xmit.c index e778132b73dc..d5ce1e2a1658 100644 --- a/drivers/staging/rtl8188eu/core/rtw_xmit.c +++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c @@ -1216,40 +1216,24 @@ void rtw_count_tx_stats(struct adapter *padapter, struct xmit_frame *pxmitframe, struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv) { unsigned long irql; - struct xmit_buf *pxmitbuf = NULL; - struct list_head *plist, *phead; + struct xmit_buf *pxmitbuf; struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue; - spin_lock_irqsave(&pfree_queue->lock, irql); - - if (list_empty(&pfree_queue->queue)) { - pxmitbuf = NULL; - } else { - phead = get_list_head(pfree_queue); - - plist = phead->next; - - pxmitbuf = container_of(plist, struct xmit_buf, list); - - list_del_init(&(pxmitbuf->list)); - } - - if (pxmitbuf != NULL) { + pxmitbuf = list_first_entry_or_null(&pfree_queue->queue, + struct xmit_buf, list); + if (pxmitbuf) { + list_del_init(&pxmitbuf->list); pxmitpriv->free_xmit_extbuf_cnt--; - pxmitbuf->priv_data = NULL; /* pxmitbuf->ext_tag = true; */ - if (pxmitbuf->sctx) { DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__); rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC); } } - spin_unlock_irqrestore(&pfree_queue->lock, irql); - return pxmitbuf; } @@ -1278,28 +1262,16 @@ s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf) struct xmit_buf *rtw_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; - /* DBG_88E("+rtw_alloc_xmitbuf\n"); */ spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irql); - - if (list_empty(&pfree_xmitbuf_queue->queue)) { - pxmitbuf = NULL; - } else { - phead = get_list_head(pfree_xmitbuf_queue); - - plist = phead->next; - - pxmitbuf = container_of(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--; pxmitbuf->priv_data = NULL; if (pxmitbuf->sctx) { @@ -1309,7 +1281,6 @@ struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv) } spin_unlock_irqrestore(&pfree_xmitbuf_queue->lock, irql); - return pxmitbuf; } @@ -1355,38 +1326,33 @@ Must be very very cautious... */ -struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)/* _queue *pfree_xmit_queue) */ +struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv) + /* _queue *pfree_xmit_queue) */ { /* Please remember to use all the osdep_service api, and lock/unlock or _enter/_exit critical to protect pfree_xmit_queue */ - - 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_bh(&pfree_xmit_queue->lock); - - if (list_empty(&pfree_xmit_queue->queue)) { - RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe:%d\n", pxmitpriv->free_xmitframe_cnt)); - pxframe = NULL; + pxframe = list_first_entry_or_null(&pfree_xmit_queue->queue, + struct xmit_frame, list); + if (!pxframe) { + RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, + ("rtw_alloc_xmitframe:%d\n", + pxmitpriv->free_xmitframe_cnt)); } else { - phead = get_list_head(pfree_xmit_queue); - - plist = phead->next; - - pxframe = container_of(plist, struct xmit_frame, list); + list_del_init(&pxframe->list); - list_del_init(&(pxframe->list)); - } - - if (pxframe != NULL) { /* default value setting */ + /* default value setting */ pxmitpriv->free_xmitframe_cnt--; - RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv->free_xmitframe_cnt)); + RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, + ("rtw_alloc_xmitframe():free_xmitframe_cnt=%d\n", + pxmitpriv->free_xmitframe_cnt)); pxframe->buf_addr = NULL; pxframe->pxmitbuf = NULL; @@ -1402,10 +1368,8 @@ struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)/* _queue *pf pxframe->agg_num = 1; pxframe->ack_report = 0; } - spin_unlock_bh(&pfree_xmit_queue->lock); - return pxframe; } -- 2.20.1