Skip to content

Commit

Permalink
rtl8xxxu: prevent potential memory leak
Browse files Browse the repository at this point in the history
[ Upstream commit 8627945 ]

Free the skb if usb_submit_urb fails on rx_urb. And free the urb
no matter usb_submit_urb succeeds or not in rtl8xxxu_submit_int_urb.

Signed-off-by: Chris Chiu <chiu@endlessm.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20200906040424.22022-1-chiu@endlessm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Chris Chiu authored and gregkh committed Oct 29, 2020
1 parent d5eb55b commit a463876
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -5447,7 +5447,6 @@ static int rtl8xxxu_submit_int_urb(struct ieee80211_hw *hw)
ret = usb_submit_urb(urb, GFP_KERNEL);
if (ret) {
usb_unanchor_urb(urb);
usb_free_urb(urb);
goto error;
}

Expand All @@ -5456,6 +5455,7 @@ static int rtl8xxxu_submit_int_urb(struct ieee80211_hw *hw)
rtl8xxxu_write32(priv, REG_USB_HIMR, val32);

error:
usb_free_urb(urb);
return ret;
}

Expand Down Expand Up @@ -5781,6 +5781,7 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw)
struct rtl8xxxu_priv *priv = hw->priv;
struct rtl8xxxu_rx_urb *rx_urb;
struct rtl8xxxu_tx_urb *tx_urb;
struct sk_buff *skb;
unsigned long flags;
int ret, i;

Expand Down Expand Up @@ -5831,6 +5832,13 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw)
rx_urb->hw = hw;

ret = rtl8xxxu_submit_rx_urb(priv, rx_urb);
if (ret) {
if (ret != -ENOMEM) {
skb = (struct sk_buff *)rx_urb->urb.context;
dev_kfree_skb(skb);
}
rtl8xxxu_queue_rx_urb(priv, rx_urb);
}
}
exit:
/*
Expand Down

0 comments on commit a463876

Please sign in to comment.