Skip to content

Commit

Permalink
rtlwifi: prevent memory leak in rtl_usb_probe
Browse files Browse the repository at this point in the history
In rtl_usb_probe if allocation for usb_data fails the allocated hw
should be released. In addition the allocated rtlpriv->usb_data should
be released on error handling path.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  • Loading branch information
Navidem authored and Kalle Valo committed Oct 1, 2019
1 parent 6e7d597 commit 3f93616
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/net/wireless/realtek/rtlwifi/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1083,6 +1085,7 @@ int rtl_usb_probe(struct usb_interface *intf,
_rtl_usb_io_handler_release(hw);
usb_put_dev(udev);
complete(&rtlpriv->firmware_loading_complete);
kfree(rtlpriv->usb_data);
return -ENODEV;
}
EXPORT_SYMBOL(rtl_usb_probe);
Expand Down

0 comments on commit 3f93616

Please sign in to comment.