diff mbox

rtlwifi: get buffer_desc before trying to alloc new skb

Message ID 5501CCFB.3040203@lwfinger.net (mailing list archive)
State Changes Requested
Delegated to: Kalle Valo
Headers show

Commit Message

Larry Finger March 12, 2015, 5:29 p.m. UTC
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>

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

Comments

Yang Bai March 13, 2015, 2:36 a.m. UTC | #1
On Fri, Mar 13, 2015 at 1:29 AM, Larry Finger <Larry.Finger@lwfinger.net> 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@gmail.com>
>
>
> 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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

From 74e20cf2bdb8312252363362495b9e517b3637d9 Mon Sep 17 00:00:00 2001
From: Yang Bai <hamo.by@gmail.com>
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@gmail.com>
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Stable <stable@vger.kernel.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