linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8723au: use list_first_entry*
@ 2016-02-23  0:38 Geliang Tang
  2016-02-23  2:39 ` Jes Sorensen
  0 siblings, 1 reply; 6+ messages in thread
From: Geliang Tang @ 2016-02-23  0:38 UTC (permalink / raw)
  To: Larry Finger, Jes Sorensen, Greg Kroah-Hartman, Julian Calaby
  Cc: Geliang Tang, linux-wireless, devel, linux-kernel

Use list_first_entry*() instead of container_of() to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/staging/rtl8723au/core/rtw_recv.c | 49 +++++++++----------------------
 drivers/staging/rtl8723au/core/rtw_xmit.c | 26 +++++-----------
 2 files changed, 22 insertions(+), 53 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_recv.c b/drivers/staging/rtl8723au/core/rtw_recv.c
index 0a7741c..b095d09 100644
--- a/drivers/staging/rtl8723au/core/rtw_recv.c
+++ b/drivers/staging/rtl8723au/core/rtw_recv.c
@@ -104,21 +104,14 @@ void _rtw_free_recv_priv23a(struct recv_priv *precvpriv)
 struct recv_frame *rtw_alloc_recvframe23a(struct rtw_queue *pfree_recv_queue)
 {
 	struct recv_frame *pframe;
-	struct list_head *plist, *phead;
 	struct rtw_adapter *padapter;
 	struct recv_priv *precvpriv;
 
 	spin_lock_bh(&pfree_recv_queue->lock);
 
-	if (list_empty(&pfree_recv_queue->queue))
-		pframe = NULL;
-	else {
-		phead = get_list_head(pfree_recv_queue);
-
-		plist = phead->next;
-
-		pframe = container_of(plist, struct recv_frame, list);
-
+	pframe = list_first_entry_or_null(&pfree_recv_queue->queue,
+					  struct recv_frame, list);
+	if (pframe) {
 		list_del_init(&pframe->list);
 		padapter = pframe->adapter;
 		if (padapter) {
@@ -243,25 +236,17 @@ int rtw_enqueue_recvbuf23a(struct recv_buf *precvbuf, struct rtw_queue *queue)
 	return _SUCCESS;
 }
 
-struct recv_buf *rtw_dequeue_recvbuf23a (struct rtw_queue *queue)
+struct recv_buf *rtw_dequeue_recvbuf23a(struct rtw_queue *queue)
 {
 	unsigned long irqL;
 	struct recv_buf *precvbuf;
-	struct list_head *plist, *phead;
 
 	spin_lock_irqsave(&queue->lock, irqL);
 
-	if (list_empty(&queue->queue)) {
-		precvbuf = NULL;
-	} else {
-		phead = get_list_head(queue);
-
-		plist = phead->next;
-
-		precvbuf = container_of(plist, struct recv_buf, list);
-
+	precvbuf = list_first_entry_or_null(&queue->queue,
+					    struct recv_buf, list);
+	if (precvbuf)
 		list_del_init(&precvbuf->list);
-	}
 
 	spin_unlock_irqrestore(&queue->lock, irqL);
 
@@ -1079,22 +1064,17 @@ static int validate_recv_ctrl_frame(struct rtw_adapter *padapter,
 
 		if ((psta->state & WIFI_SLEEP_STATE) &&
 		    (pstapriv->sta_dz_bitmap & CHKBIT(psta->aid))) {
-			struct list_head *xmitframe_plist, *xmitframe_phead;
+			struct list_head *xmitframe_phead;
 			struct xmit_frame *pxmitframe;
 			struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
 
 			spin_lock_bh(&pxmitpriv->lock);
 
 			xmitframe_phead = get_list_head(&psta->sleep_q);
-			xmitframe_plist = xmitframe_phead->next;
-
-			if (!list_empty(xmitframe_phead)) {
-				pxmitframe = container_of(xmitframe_plist,
-							  struct xmit_frame,
-							  list);
-
-				xmitframe_plist = xmitframe_plist->next;
-
+			pxmitframe = list_first_entry_or_null(xmitframe_phead,
+							      struct xmit_frame,
+							      list);
+			if (pxmitframe) {
 				list_del_init(&pxmitframe->list);
 
 				psta->sleepq_len--;
@@ -1542,7 +1522,7 @@ struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
 struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
 				    struct rtw_queue *defrag_q)
 {
-	struct list_head *plist, *phead;
+	struct list_head *phead;
 	u8 wlanhdr_offset;
 	u8 curfragnum;
 	struct recv_frame *pnfhdr, *ptmp;
@@ -1554,8 +1534,7 @@ struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
 	pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
 
 	phead = get_list_head(defrag_q);
-	plist = phead->next;
-	prframe = container_of(plist, struct recv_frame, list);
+	prframe = list_first_entry(phead, struct recv_frame, list);
 	list_del_init(&prframe->list);
 	skb = prframe->pkt;
 
diff --git a/drivers/staging/rtl8723au/core/rtw_xmit.c b/drivers/staging/rtl8723au/core/rtw_xmit.c
index b82b182..3de40cf 100644
--- a/drivers/staging/rtl8723au/core/rtw_xmit.c
+++ b/drivers/staging/rtl8723au/core/rtw_xmit.c
@@ -1443,24 +1443,18 @@ Must be very very cautious...
 */
 static struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
 {
-	struct xmit_frame *pxframe = NULL;
-	struct list_head *plist, *phead;
+	struct xmit_frame *pxframe;
 	struct rtw_queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
 
 	spin_lock_bh(&pfree_xmit_queue->lock);
 
-	if (list_empty(&pfree_xmit_queue->queue)) {
+	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);
-		pxframe =  NULL;
 	} else {
-		phead = get_list_head(pfree_xmit_queue);
-
-		plist = phead->next;
-
-		pxframe = container_of(plist, struct xmit_frame, list);
-
 		list_del_init(&pxframe->list);
 		pxmitpriv->free_xmitframe_cnt--;
 		RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
@@ -1477,22 +1471,18 @@ static struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
 
 struct xmit_frame *rtw_alloc_xmitframe23a_ext(struct xmit_priv *pxmitpriv)
 {
-	struct xmit_frame *pxframe = NULL;
-	struct list_head *plist, *phead;
+	struct xmit_frame *pxframe;
 	struct rtw_queue *queue = &pxmitpriv->free_xframe_ext_queue;
 
 	spin_lock_bh(&queue->lock);
 
-	if (list_empty(&queue->queue)) {
+	pxframe = list_first_entry_or_null(&queue->queue,
+					   struct xmit_frame, list);
+	if (!pxframe) {
 		RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
 			 "rtw_alloc_xmitframe23a_ext:%d\n",
 			 pxmitpriv->free_xframe_ext_cnt);
-		pxframe =  NULL;
 	} else {
-		phead = get_list_head(queue);
-		plist = phead->next;
-		pxframe = container_of(plist, struct xmit_frame, list);
-
 		list_del_init(&pxframe->list);
 		pxmitpriv->free_xframe_ext_cnt--;
 		RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: rtl8723au: use list_first_entry*
  2016-02-23  0:38 [PATCH] staging: rtl8723au: use list_first_entry* Geliang Tang
@ 2016-02-23  2:39 ` Jes Sorensen
  2016-03-01 15:35   ` [PATCH v2 0/3] " Geliang Tang
  0 siblings, 1 reply; 6+ messages in thread
From: Jes Sorensen @ 2016-02-23  2:39 UTC (permalink / raw)
  To: Geliang Tang
  Cc: Larry Finger, Greg Kroah-Hartman, Julian Calaby, linux-wireless,
	devel, linux-kernel

Geliang Tang <geliangtang@163.com> writes:
> Use list_first_entry*() instead of container_of() to simplify the code.
>
> Signed-off-by: Geliang Tang <geliangtang@163.com>
> ---
>  drivers/staging/rtl8723au/core/rtw_recv.c | 49 +++++++++----------------------
>  drivers/staging/rtl8723au/core/rtw_xmit.c | 26 +++++-----------
>  2 files changed, 22 insertions(+), 53 deletions(-)

This looks fine to me. When these changes gets large, it may be better
to break them down into multiple patches as it's easier to debug if
there is a bug somewhere.


Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>

>
> diff --git a/drivers/staging/rtl8723au/core/rtw_recv.c b/drivers/staging/rtl8723au/core/rtw_recv.c
> index 0a7741c..b095d09 100644
> --- a/drivers/staging/rtl8723au/core/rtw_recv.c
> +++ b/drivers/staging/rtl8723au/core/rtw_recv.c
> @@ -104,21 +104,14 @@ void _rtw_free_recv_priv23a(struct recv_priv *precvpriv)
>  struct recv_frame *rtw_alloc_recvframe23a(struct rtw_queue *pfree_recv_queue)
>  {
>  	struct recv_frame *pframe;
> -	struct list_head *plist, *phead;
>  	struct rtw_adapter *padapter;
>  	struct recv_priv *precvpriv;
>  
>  	spin_lock_bh(&pfree_recv_queue->lock);
>  
> -	if (list_empty(&pfree_recv_queue->queue))
> -		pframe = NULL;
> -	else {
> -		phead = get_list_head(pfree_recv_queue);
> -
> -		plist = phead->next;
> -
> -		pframe = container_of(plist, struct recv_frame, list);
> -
> +	pframe = list_first_entry_or_null(&pfree_recv_queue->queue,
> +					  struct recv_frame, list);
> +	if (pframe) {
>  		list_del_init(&pframe->list);
>  		padapter = pframe->adapter;
>  		if (padapter) {
> @@ -243,25 +236,17 @@ int rtw_enqueue_recvbuf23a(struct recv_buf *precvbuf, struct rtw_queue *queue)
>  	return _SUCCESS;
>  }
>  
> -struct recv_buf *rtw_dequeue_recvbuf23a (struct rtw_queue *queue)
> +struct recv_buf *rtw_dequeue_recvbuf23a(struct rtw_queue *queue)
>  {
>  	unsigned long irqL;
>  	struct recv_buf *precvbuf;
> -	struct list_head *plist, *phead;
>  
>  	spin_lock_irqsave(&queue->lock, irqL);
>  
> -	if (list_empty(&queue->queue)) {
> -		precvbuf = NULL;
> -	} else {
> -		phead = get_list_head(queue);
> -
> -		plist = phead->next;
> -
> -		precvbuf = container_of(plist, struct recv_buf, list);
> -
> +	precvbuf = list_first_entry_or_null(&queue->queue,
> +					    struct recv_buf, list);
> +	if (precvbuf)
>  		list_del_init(&precvbuf->list);
> -	}
>  
>  	spin_unlock_irqrestore(&queue->lock, irqL);
>  
> @@ -1079,22 +1064,17 @@ static int validate_recv_ctrl_frame(struct rtw_adapter *padapter,
>  
>  		if ((psta->state & WIFI_SLEEP_STATE) &&
>  		    (pstapriv->sta_dz_bitmap & CHKBIT(psta->aid))) {
> -			struct list_head *xmitframe_plist, *xmitframe_phead;
> +			struct list_head *xmitframe_phead;
>  			struct xmit_frame *pxmitframe;
>  			struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
>  
>  			spin_lock_bh(&pxmitpriv->lock);
>  
>  			xmitframe_phead = get_list_head(&psta->sleep_q);
> -			xmitframe_plist = xmitframe_phead->next;
> -
> -			if (!list_empty(xmitframe_phead)) {
> -				pxmitframe = container_of(xmitframe_plist,
> -							  struct xmit_frame,
> -							  list);
> -
> -				xmitframe_plist = xmitframe_plist->next;
> -
> +			pxmitframe = list_first_entry_or_null(xmitframe_phead,
> +							      struct xmit_frame,
> +							      list);
> +			if (pxmitframe) {
>  				list_del_init(&pxmitframe->list);
>  
>  				psta->sleepq_len--;
> @@ -1542,7 +1522,7 @@ struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
>  struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
>  				    struct rtw_queue *defrag_q)
>  {
> -	struct list_head *plist, *phead;
> +	struct list_head *phead;
>  	u8 wlanhdr_offset;
>  	u8 curfragnum;
>  	struct recv_frame *pnfhdr, *ptmp;
> @@ -1554,8 +1534,7 @@ struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
>  	pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
>  
>  	phead = get_list_head(defrag_q);
> -	plist = phead->next;
> -	prframe = container_of(plist, struct recv_frame, list);
> +	prframe = list_first_entry(phead, struct recv_frame, list);
>  	list_del_init(&prframe->list);
>  	skb = prframe->pkt;
>  
> diff --git a/drivers/staging/rtl8723au/core/rtw_xmit.c b/drivers/staging/rtl8723au/core/rtw_xmit.c
> index b82b182..3de40cf 100644
> --- a/drivers/staging/rtl8723au/core/rtw_xmit.c
> +++ b/drivers/staging/rtl8723au/core/rtw_xmit.c
> @@ -1443,24 +1443,18 @@ Must be very very cautious...
>  */
>  static struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
>  {
> -	struct xmit_frame *pxframe = NULL;
> -	struct list_head *plist, *phead;
> +	struct xmit_frame *pxframe;
>  	struct rtw_queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
>  
>  	spin_lock_bh(&pfree_xmit_queue->lock);
>  
> -	if (list_empty(&pfree_xmit_queue->queue)) {
> +	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);
> -		pxframe =  NULL;
>  	} else {
> -		phead = get_list_head(pfree_xmit_queue);
> -
> -		plist = phead->next;
> -
> -		pxframe = container_of(plist, struct xmit_frame, list);
> -
>  		list_del_init(&pxframe->list);
>  		pxmitpriv->free_xmitframe_cnt--;
>  		RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
> @@ -1477,22 +1471,18 @@ static struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
>  
>  struct xmit_frame *rtw_alloc_xmitframe23a_ext(struct xmit_priv *pxmitpriv)
>  {
> -	struct xmit_frame *pxframe = NULL;
> -	struct list_head *plist, *phead;
> +	struct xmit_frame *pxframe;
>  	struct rtw_queue *queue = &pxmitpriv->free_xframe_ext_queue;
>  
>  	spin_lock_bh(&queue->lock);
>  
> -	if (list_empty(&queue->queue)) {
> +	pxframe = list_first_entry_or_null(&queue->queue,
> +					   struct xmit_frame, list);
> +	if (!pxframe) {
>  		RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
>  			 "rtw_alloc_xmitframe23a_ext:%d\n",
>  			 pxmitpriv->free_xframe_ext_cnt);
> -		pxframe =  NULL;
>  	} else {
> -		phead = get_list_head(queue);
> -		plist = phead->next;
> -		pxframe = container_of(plist, struct xmit_frame, list);
> -
>  		list_del_init(&pxframe->list);
>  		pxmitpriv->free_xframe_ext_cnt--;
>  		RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 0/3] staging: rtl8723au: use list_first_entry*
  2016-02-23  2:39 ` Jes Sorensen
@ 2016-03-01 15:35   ` Geliang Tang
  2016-03-01 15:35     ` [PATCH v2 1/3] staging: rtl8723au: core: rtw_recv: use list_first_entry_or_null() Geliang Tang
  0 siblings, 1 reply; 6+ messages in thread
From: Geliang Tang @ 2016-03-01 15:35 UTC (permalink / raw)
  To: Larry Finger, Jes Sorensen, Greg Kroah-Hartman, Julian Calaby
  Cc: Geliang Tang, linux-wireless, devel, linux-kernel

On Mon, Feb 22, 2016 at 09:39:15PM -0500, Jes Sorensen wrote:
> Geliang Tang <geliangtang@163.com> writes:
> > Use list_first_entry*() instead of container_of() to simplify the code.
> >
> > Signed-off-by: Geliang Tang <geliangtang@163.com>
> > ---
> >  drivers/staging/rtl8723au/core/rtw_recv.c | 49 +++++++++----------------------
> >  drivers/staging/rtl8723au/core/rtw_xmit.c | 26 +++++-----------
> >  2 files changed, 22 insertions(+), 53 deletions(-)
> 
> This looks fine to me. When these changes gets large, it may be better
> to break them down into multiple patches as it's easier to debug if
> there is a bug somewhere.
>

Changes in v2:
 - split it into three patches.

Geliang Tang (3):
  staging: rtl8723au: core: rtw_recv: use list_first_entry_or_null()
  staging: rtl8723au: core: rtw_xmit: use list_first_entry_or_null()
  staging: rtl8723au: core: rtw_recv: use list_first_entry()

 drivers/staging/rtl8723au/core/rtw_recv.c | 47 +++++++++----------------------
 drivers/staging/rtl8723au/core/rtw_xmit.c | 26 ++++++-----------
 2 files changed, 21 insertions(+), 52 deletions(-)

-- 
2.5.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] staging: rtl8723au: core: rtw_recv: use list_first_entry_or_null()
  2016-03-01 15:35   ` [PATCH v2 0/3] " Geliang Tang
@ 2016-03-01 15:35     ` Geliang Tang
  2016-03-01 15:35       ` [PATCH v2 2/3] staging: rtl8723au: core: rtw_xmit: " Geliang Tang
  0 siblings, 1 reply; 6+ messages in thread
From: Geliang Tang @ 2016-03-01 15:35 UTC (permalink / raw)
  To: Larry Finger, Jes Sorensen, Greg Kroah-Hartman, Julian Calaby
  Cc: Geliang Tang, linux-wireless, devel, linux-kernel

Use list_first_entry_or_null() instead of list_empty() + container_of()
to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 drivers/staging/rtl8723au/core/rtw_recv.c | 42 ++++++++-----------------------
 1 file changed, 11 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_recv.c b/drivers/staging/rtl8723au/core/rtw_recv.c
index 0a7741c..a4dacc3 100644
--- a/drivers/staging/rtl8723au/core/rtw_recv.c
+++ b/drivers/staging/rtl8723au/core/rtw_recv.c
@@ -104,21 +104,14 @@ void _rtw_free_recv_priv23a(struct recv_priv *precvpriv)
 struct recv_frame *rtw_alloc_recvframe23a(struct rtw_queue *pfree_recv_queue)
 {
 	struct recv_frame *pframe;
-	struct list_head *plist, *phead;
 	struct rtw_adapter *padapter;
 	struct recv_priv *precvpriv;
 
 	spin_lock_bh(&pfree_recv_queue->lock);
 
-	if (list_empty(&pfree_recv_queue->queue))
-		pframe = NULL;
-	else {
-		phead = get_list_head(pfree_recv_queue);
-
-		plist = phead->next;
-
-		pframe = container_of(plist, struct recv_frame, list);
-
+	pframe = list_first_entry_or_null(&pfree_recv_queue->queue,
+					  struct recv_frame, list);
+	if (pframe) {
 		list_del_init(&pframe->list);
 		padapter = pframe->adapter;
 		if (padapter) {
@@ -247,21 +240,13 @@ struct recv_buf *rtw_dequeue_recvbuf23a (struct rtw_queue *queue)
 {
 	unsigned long irqL;
 	struct recv_buf *precvbuf;
-	struct list_head *plist, *phead;
 
 	spin_lock_irqsave(&queue->lock, irqL);
 
-	if (list_empty(&queue->queue)) {
-		precvbuf = NULL;
-	} else {
-		phead = get_list_head(queue);
-
-		plist = phead->next;
-
-		precvbuf = container_of(plist, struct recv_buf, list);
-
+	precvbuf = list_first_entry_or_null(&queue->queue,
+					    struct recv_buf, list);
+	if (precvbuf)
 		list_del_init(&precvbuf->list);
-	}
 
 	spin_unlock_irqrestore(&queue->lock, irqL);
 
@@ -1079,22 +1064,17 @@ static int validate_recv_ctrl_frame(struct rtw_adapter *padapter,
 
 		if ((psta->state & WIFI_SLEEP_STATE) &&
 		    (pstapriv->sta_dz_bitmap & CHKBIT(psta->aid))) {
-			struct list_head *xmitframe_plist, *xmitframe_phead;
+			struct list_head *xmitframe_phead;
 			struct xmit_frame *pxmitframe;
 			struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
 
 			spin_lock_bh(&pxmitpriv->lock);
 
 			xmitframe_phead = get_list_head(&psta->sleep_q);
-			xmitframe_plist = xmitframe_phead->next;
-
-			if (!list_empty(xmitframe_phead)) {
-				pxmitframe = container_of(xmitframe_plist,
-							  struct xmit_frame,
-							  list);
-
-				xmitframe_plist = xmitframe_plist->next;
-
+			pxmitframe = list_first_entry_or_null(xmitframe_phead,
+							      struct xmit_frame,
+							      list);
+			if (pxmitframe) {
 				list_del_init(&pxmitframe->list);
 
 				psta->sleepq_len--;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] staging: rtl8723au: core: rtw_xmit: use list_first_entry_or_null()
  2016-03-01 15:35     ` [PATCH v2 1/3] staging: rtl8723au: core: rtw_recv: use list_first_entry_or_null() Geliang Tang
@ 2016-03-01 15:35       ` Geliang Tang
  2016-03-01 15:35         ` [PATCH v2 3/3] staging: rtl8723au: core: rtw_recv: use list_first_entry() Geliang Tang
  0 siblings, 1 reply; 6+ messages in thread
From: Geliang Tang @ 2016-03-01 15:35 UTC (permalink / raw)
  To: Larry Finger, Jes Sorensen, Greg Kroah-Hartman, Julian Calaby
  Cc: Geliang Tang, linux-wireless, devel, linux-kernel

Use list_first_entry_or_null() instead of list_empty() + container_of()
to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 drivers/staging/rtl8723au/core/rtw_xmit.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_xmit.c b/drivers/staging/rtl8723au/core/rtw_xmit.c
index b82b182..3de40cf 100644
--- a/drivers/staging/rtl8723au/core/rtw_xmit.c
+++ b/drivers/staging/rtl8723au/core/rtw_xmit.c
@@ -1443,24 +1443,18 @@ Must be very very cautious...
 */
 static struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
 {
-	struct xmit_frame *pxframe = NULL;
-	struct list_head *plist, *phead;
+	struct xmit_frame *pxframe;
 	struct rtw_queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
 
 	spin_lock_bh(&pfree_xmit_queue->lock);
 
-	if (list_empty(&pfree_xmit_queue->queue)) {
+	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);
-		pxframe =  NULL;
 	} else {
-		phead = get_list_head(pfree_xmit_queue);
-
-		plist = phead->next;
-
-		pxframe = container_of(plist, struct xmit_frame, list);
-
 		list_del_init(&pxframe->list);
 		pxmitpriv->free_xmitframe_cnt--;
 		RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
@@ -1477,22 +1471,18 @@ static struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
 
 struct xmit_frame *rtw_alloc_xmitframe23a_ext(struct xmit_priv *pxmitpriv)
 {
-	struct xmit_frame *pxframe = NULL;
-	struct list_head *plist, *phead;
+	struct xmit_frame *pxframe;
 	struct rtw_queue *queue = &pxmitpriv->free_xframe_ext_queue;
 
 	spin_lock_bh(&queue->lock);
 
-	if (list_empty(&queue->queue)) {
+	pxframe = list_first_entry_or_null(&queue->queue,
+					   struct xmit_frame, list);
+	if (!pxframe) {
 		RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
 			 "rtw_alloc_xmitframe23a_ext:%d\n",
 			 pxmitpriv->free_xframe_ext_cnt);
-		pxframe =  NULL;
 	} else {
-		phead = get_list_head(queue);
-		plist = phead->next;
-		pxframe = container_of(plist, struct xmit_frame, list);
-
 		list_del_init(&pxframe->list);
 		pxmitpriv->free_xframe_ext_cnt--;
 		RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] staging: rtl8723au: core: rtw_recv: use list_first_entry()
  2016-03-01 15:35       ` [PATCH v2 2/3] staging: rtl8723au: core: rtw_xmit: " Geliang Tang
@ 2016-03-01 15:35         ` Geliang Tang
  0 siblings, 0 replies; 6+ messages in thread
From: Geliang Tang @ 2016-03-01 15:35 UTC (permalink / raw)
  To: Larry Finger, Jes Sorensen, Greg Kroah-Hartman, Julian Calaby
  Cc: Geliang Tang, linux-wireless, devel, linux-kernel

Use list_first_entry() instead of container_of() to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 drivers/staging/rtl8723au/core/rtw_recv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_recv.c b/drivers/staging/rtl8723au/core/rtw_recv.c
index a4dacc3..ceb4a07 100644
--- a/drivers/staging/rtl8723au/core/rtw_recv.c
+++ b/drivers/staging/rtl8723au/core/rtw_recv.c
@@ -1522,7 +1522,7 @@ struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
 struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
 				    struct rtw_queue *defrag_q)
 {
-	struct list_head *plist, *phead;
+	struct list_head *phead;
 	u8 wlanhdr_offset;
 	u8 curfragnum;
 	struct recv_frame *pnfhdr, *ptmp;
@@ -1534,8 +1534,7 @@ struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
 	pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
 
 	phead = get_list_head(defrag_q);
-	plist = phead->next;
-	prframe = container_of(plist, struct recv_frame, list);
+	prframe = list_first_entry(phead, struct recv_frame, list);
 	list_del_init(&prframe->list);
 	skb = prframe->pkt;
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-03-01 15:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-23  0:38 [PATCH] staging: rtl8723au: use list_first_entry* Geliang Tang
2016-02-23  2:39 ` Jes Sorensen
2016-03-01 15:35   ` [PATCH v2 0/3] " Geliang Tang
2016-03-01 15:35     ` [PATCH v2 1/3] staging: rtl8723au: core: rtw_recv: use list_first_entry_or_null() Geliang Tang
2016-03-01 15:35       ` [PATCH v2 2/3] staging: rtl8723au: core: rtw_xmit: " Geliang Tang
2016-03-01 15:35         ` [PATCH v2 3/3] staging: rtl8723au: core: rtw_recv: use list_first_entry() Geliang Tang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).