Skip to contentSkip to conversation

rtlwifi: fix memory leak in rtl_usb_probe

PATCH In review Navid Emamdoost 2 participants 3 messages Oct 4, 2019 – Oct 5, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtlwifi: fix memory leak in rtl_usb_probe

In rtl_usb_probe, a new hw is allocated via ieee80211_alloc_hw(). This allocation should be released in case of allocation failure for rtlpriv->usb_data.

Fixes a7959c1394d4 ("rtlwifi: Preallocate USB read buffers and eliminate kalloc in read routine")
---
 drivers/net/wireless/realtek/rtlwifi/usb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtlwifi/usb.c +3 -1
index 4b59f3b46b28..265f95261da8 100644
@@ -1021,8 +1021,10 @@ int rtl_usb_probe(struct usb_interface *intf,
 	rtlpriv->hw = hw;
 	rtlpriv->usb_data = kcalloc(RTL_USB_MAX_RX_COUNT, sizeof(u32),
 				    GFP_KERNEL);
-	if (!rtlpriv->usb_data)
+	if (!rtlpriv->usb_data) {
+		ieee80211_free_hw(hw);
 		return -ENOMEM;
+	}
 
 	/* this spin lock must be initialized early */
 	spin_lock_init(&rtlpriv->locks.usb_lock);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines

In rtl_usb_probe, a new hw is allocated via ieee80211_alloc_hw(). This allocation should be released in case of allocation failure for rtlpriv->usb_data.

Fixes a7959c1394d4 ("rtlwifi: Preallocate USB read buffers and eliminate kalloc in read routine")

Which event did trigger the sending of this patch variant after a similar change was integrated already?
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id?93616951138a598d930dcaec40f2bfd9ce43bb
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/patchwork/comment/1331936/

Regards,
Markus

#2 lore raw

Oh! It's duplicate, thanks for catching that.

Quoted 15 lines · Markus Elfring
Quoted 6 lines

In rtl_usb_probe, a new hw is allocated via ieee80211_alloc_hw(). This allocation should be released in case of allocation failure for rtlpriv->usb_data.

Fixes a7959c1394d4 ("rtlwifi: Preallocate USB read buffers and eliminate kalloc in read routine")

Which event did trigger the sending of this patch variant after a similar change was integrated already?
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id?93616951138a598d930dcaec40f2bfd9ce43bb
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/patchwork/comment/1331936/

Regards,
Markus

Signature · 1 line
Navid.