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 <geliangtang@163.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
a67080ee82
commit
b9f1c275b6
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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--;
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
list_del_init(&pxframe->list);
|
||||
|
||||
plist = phead->next;
|
||||
|
||||
pxframe = container_of(plist, struct xmit_frame, 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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user