netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtlwifi: get buffer_desc before trying to alloc new skb
@ 2015-03-12 11:33 Yang Bai
  2015-03-12 16:03 ` Larry Finger
       [not found] ` <1426160036-1542-1-git-send-email-hamo.by-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Yang Bai @ 2015-03-12 11:33 UTC (permalink / raw)
  To: Larry.Finger, chaoming_li, kvalo
  Cc: linux-wireless, netdev, linux-kernel, hamo.by

if rtlpriv->use_new_trx_flow == true and we run out of memory
to alloc a new skb, we will directly jump to no_new tag with
buffer_desc == NULL. Then we will dereference this NULL pointer
in function _rtl_pci_init_one_rxdesc.

Signed-off-by: Yang Bai <hamo.by@gmail.com>
---
 drivers/net/wireless/rtlwifi/pci.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index a62170e..7fe04d1 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -820,17 +820,19 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
 		pci_unmap_single(rtlpci->pdev, *((dma_addr_t *)skb->cb),
 				 rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE);
 
+		if (rtlpriv->use_new_trx_flow)
+			buffer_desc =
+			  &rtlpci->rx_ring[rxring_idx].buffer_desc
+				[rtlpci->rx_ring[rxring_idx].idx];
+
 		/* get a new skb - if fail, old one will be reused */
 		new_skb = dev_alloc_skb(rtlpci->rxbuffersize);
 		if (unlikely(!new_skb))
 			goto no_new;
-		if (rtlpriv->use_new_trx_flow) {
-			buffer_desc =
-			  &rtlpci->rx_ring[rxring_idx].buffer_desc
-				[rtlpci->rx_ring[rxring_idx].idx];
+		if (rtlpriv->use_new_trx_flow)
 			/*means rx wifi info*/
 			pdesc = (struct rtl_rx_desc *)skb->data;
-		}
+
 		memset(&rx_status , 0 , sizeof(rx_status));
 		rtlpriv->cfg->ops->query_rx_desc(hw, &stats,
 						 &rx_status, (u8 *)pdesc, skb);
-- 
2.3.1

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

* Re: [PATCH] rtlwifi: get buffer_desc before trying to alloc new skb
  2015-03-12 11:33 [PATCH] rtlwifi: get buffer_desc before trying to alloc new skb Yang Bai
@ 2015-03-12 16:03 ` Larry Finger
       [not found] ` <1426160036-1542-1-git-send-email-hamo.by-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Larry Finger @ 2015-03-12 16:03 UTC (permalink / raw)
  To: Yang Bai, chaoming_li, kvalo; +Cc: linux-wireless, netdev, linux-kernel

On 03/12/2015 06:33 AM, Yang Bai wrote:
> if rtlpriv->use_new_trx_flow == true and we run out of memory
> to alloc a new skb, we will directly jump to no_new tag with
> buffer_desc == NULL. Then we will dereference this NULL pointer
> in function _rtl_pci_init_one_rxdesc.
>
> Signed-off-by: Yang Bai <hamo.by@gmail.com>

Good catch. The only problem that I have is this fix adds even more branching to 
this interrupt routine. At first glance, I should be able to set buffer_desc in 
the earlier code where the code has already branched. For testing, an RTL8192EE 
card will be needed. Do you have such a card?

Larry

> ---
>   drivers/net/wireless/rtlwifi/pci.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
> index a62170e..7fe04d1 100644
> --- a/drivers/net/wireless/rtlwifi/pci.c
> +++ b/drivers/net/wireless/rtlwifi/pci.c
> @@ -820,17 +820,19 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
>   		pci_unmap_single(rtlpci->pdev, *((dma_addr_t *)skb->cb),
>   				 rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE);
>
> +		if (rtlpriv->use_new_trx_flow)
> +			buffer_desc =
> +			  &rtlpci->rx_ring[rxring_idx].buffer_desc
> +				[rtlpci->rx_ring[rxring_idx].idx];
> +
>   		/* get a new skb - if fail, old one will be reused */
>   		new_skb = dev_alloc_skb(rtlpci->rxbuffersize);
>   		if (unlikely(!new_skb))
>   			goto no_new;
> -		if (rtlpriv->use_new_trx_flow) {
> -			buffer_desc =
> -			  &rtlpci->rx_ring[rxring_idx].buffer_desc
> -				[rtlpci->rx_ring[rxring_idx].idx];
> +		if (rtlpriv->use_new_trx_flow)
>   			/*means rx wifi info*/
>   			pdesc = (struct rtl_rx_desc *)skb->data;
> -		}
> +
>   		memset(&rx_status , 0 , sizeof(rx_status));
>   		rtlpriv->cfg->ops->query_rx_desc(hw, &stats,
>   						 &rx_status, (u8 *)pdesc, skb);
>

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

* Re: [PATCH] rtlwifi: get buffer_desc before trying to alloc new skb
       [not found] ` <1426160036-1542-1-git-send-email-hamo.by-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-03-12 17:29   ` Larry Finger
       [not found]     ` <5501CCFB.3040203-tQ5ms3gMjBLk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Larry Finger @ 2015-03-12 17:29 UTC (permalink / raw)
  To: Yang Bai, kvalo-sgV2jX0FEOL9JmXXK+q4OQ
  Cc: linux-wireless-u79uwXL29TY76Z2rM5mHXA,
	netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

On 03/12/2015 06:33 AM, Yang Bai wrote:
> if rtlpriv->use_new_trx_flow == true and we run out of memory
> to alloc a new skb, we will directly jump to no_new tag with
> buffer_desc == NULL. Then we will dereference this NULL pointer
> in function _rtl_pci_init_one_rxdesc.
>
> Signed-off-by: Yang Bai <hamo.by-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Is the attached patch OK? I have tested it, but it is unlikely that I have hit 
any memory failures, thus that part needs to be checked by eye.

Larry



[-- Attachment #2: 0001-rtlwifi-get-buffer_desc-before-trying-to-alloc-new-s.patch --]
[-- Type: text/x-patch, Size: 2036 bytes --]

>From 74e20cf2bdb8312252363362495b9e517b3637d9 Mon Sep 17 00:00:00 2001
From: Yang Bai <hamo.by-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Thu, 12 Mar 2015 11:56:40 -0500
Subject: [PATCH V2 4.0] rtlwifi: get buffer_desc before trying to alloc new skb

If rtlpriv->use_new_trx_flow == true and we run out of memory
to alloc a new skb, we will directly jump to no_new tag with
buffer_desc == NULL. Then we will dereference this NULL pointer
in function _rtl_pci_init_one_rxdesc.

Signed-off-by: Yang Bai <hamo.by-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Larry Finger <Larry.Finger-tQ5ms3gMjBLk1uMJSBkQmQ@public.gmane.org>
Cc: Stable <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org> [3.18+]
---

V2 - Refactor to reduce the number of tests of use_new_trx_flow.


 drivers/net/wireless/rtlwifi/pci.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index a62170e..7069778 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -801,7 +801,10 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
 								      hw_queue);
 			if (rx_remained_cnt == 0)
 				return;
-
+			buffer_desc =
+			  &rtlpci->rx_ring[rxring_idx].buffer_desc
+				[rtlpci->rx_ring[rxring_idx].idx];
+			pdesc = (struct rtl_rx_desc *)skb->data;
 		} else {	/* rx descriptor */
 			pdesc = &rtlpci->rx_ring[rxring_idx].desc[
 				rtlpci->rx_ring[rxring_idx].idx];
@@ -824,13 +827,6 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
 		new_skb = dev_alloc_skb(rtlpci->rxbuffersize);
 		if (unlikely(!new_skb))
 			goto no_new;
-		if (rtlpriv->use_new_trx_flow) {
-			buffer_desc =
-			  &rtlpci->rx_ring[rxring_idx].buffer_desc
-				[rtlpci->rx_ring[rxring_idx].idx];
-			/*means rx wifi info*/
-			pdesc = (struct rtl_rx_desc *)skb->data;
-		}
 		memset(&rx_status , 0 , sizeof(rx_status));
 		rtlpriv->cfg->ops->query_rx_desc(hw, &stats,
 						 &rx_status, (u8 *)pdesc, skb);
-- 
2.1.4


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

* Re: [PATCH] rtlwifi: get buffer_desc before trying to alloc new skb
       [not found]     ` <5501CCFB.3040203-tQ5ms3gMjBLk1uMJSBkQmQ@public.gmane.org>
@ 2015-03-13  2:36       ` Yang Bai
  0 siblings, 0 replies; 4+ messages in thread
From: Yang Bai @ 2015-03-13  2:36 UTC (permalink / raw)
  To: Larry Finger
  Cc: kvalo-sgV2jX0FEOL9JmXXK+q4OQ,
	linux-wireless-u79uwXL29TY76Z2rM5mHXA,
	netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Fri, Mar 13, 2015 at 1:29 AM, Larry Finger <Larry.Finger-tQ5ms3gMjBLk1uMJSBkQmQ@public.gmane.org> wrote:
> On 03/12/2015 06:33 AM, Yang Bai wrote:
>>
>> if rtlpriv->use_new_trx_flow == true and we run out of memory
>> to alloc a new skb, we will directly jump to no_new tag with
>> buffer_desc == NULL. Then we will dereference this NULL pointer
>> in function _rtl_pci_init_one_rxdesc.
>>
>> Signed-off-by: Yang Bai <hamo.by-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>
>
> Is the attached patch OK? I have tested it, but it is unlikely that I have
> hit any memory failures, thus that part needs to be checked by eye.

Looks good to me. Thanks very much for your review.

Yang
>
> Larry
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2015-03-13  2:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-12 11:33 [PATCH] rtlwifi: get buffer_desc before trying to alloc new skb Yang Bai
2015-03-12 16:03 ` Larry Finger
     [not found] ` <1426160036-1542-1-git-send-email-hamo.by-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-03-12 17:29   ` Larry Finger
     [not found]     ` <5501CCFB.3040203-tQ5ms3gMjBLk1uMJSBkQmQ@public.gmane.org>
2015-03-13  2:36       ` Yang Bai

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).