rtlwifi: rtl_usb: Fix for URB leaking when doing ifconfig up/down
authorMichael Schenk <michael.schenk@albis-elcon.com>
Thu, 26 Jan 2017 17:25:04 +0000 (11:25 -0600)
committerWilly Tarreau <w@1wt.eu>
Tue, 20 Jun 2017 12:04:22 +0000 (14:04 +0200)
commit 575ddce0507789bf9830d089557d2199d2f91865 upstream.

In the function rtl_usb_start we pre-allocate a certain number of urbs
for RX path but they will not be freed when calling rtl_usb_stop. This
results in leaking urbs when doing ifconfig up and down. Eventually,
the system has no available urbs.

Signed-off-by: Michael Schenk <michael.schenk@albis-elcon.com>
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/net/wireless/rtlwifi/usb.c

index 3ad79736b255814839a370a06c84b85f14918264..3fc7d0845480dff1eead93ea28c3f80df1cbe838 100644 (file)
@@ -823,6 +823,7 @@ static void rtl_usb_stop(struct ieee80211_hw *hw)
        struct rtl_priv *rtlpriv = rtl_priv(hw);
        struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
        struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
+       struct urb *urb;
 
        /* should after adapter start and interrupt enable. */
        set_hal_stop(rtlhal);
@@ -830,6 +831,23 @@ static void rtl_usb_stop(struct ieee80211_hw *hw)
        /* Enable software */
        SET_USB_STOP(rtlusb);
        rtl_usb_deinit(hw);
+
+       /* free pre-allocated URBs from rtl_usb_start() */
+       usb_kill_anchored_urbs(&rtlusb->rx_submitted);
+
+       tasklet_kill(&rtlusb->rx_work_tasklet);
+       cancel_work_sync(&rtlpriv->works.lps_change_work);
+
+       flush_workqueue(rtlpriv->works.rtl_wq);
+
+       skb_queue_purge(&rtlusb->rx_queue);
+
+       while ((urb = usb_get_from_anchor(&rtlusb->rx_cleanup_urbs))) {
+               usb_free_coherent(urb->dev, urb->transfer_buffer_length,
+                               urb->transfer_buffer, urb->transfer_dma);
+               usb_free_urb(urb);
+       }
+
        rtlpriv->cfg->ops->hw_disable(hw);
 }