usbnet: fix memory leak in error case
Subsystems (5)
Oliver Neukum
maintainerPATCH v3 1/1 usbnet: fix memory leak in error case
usbnet_write_cmd_async() mixed up which buffers
need to be freed in which error case.
v2: add Fixes tag
v3: fix uninitialized buf pointer
Fixes 877bd862f32b8 ("usbnet: introduce usbnet 3 command helpers")
Signed-off-by Oliver Neukum <[email protected]>
--- drivers/net/usb/usbnet.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/net/usb/usbnet.c +12 -5
@@ -2137,7 +2137,7 @@ static void usbnet_async_cmd_cb(struct urb *urb)int usbnet_write_cmd_async (struct usbnet *dev,u8 cmd,u8 reqtype,u16 value,u16 index,const void *data,u16 size) { -struct usb_ctrlrequest *req =NULL ; +struct usb_ctrlrequest *req;struct urb *urb;int err = -ENOMEM ;void *buf =NULL ;
@@ -2155,7 +2155,7 @@ int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype,if (!buf) {netdev_err (dev->net,"Error allocating buffer" " in %s!\n" , __func__); - goto fail_free; + goto fail_free_urb; } }
@@ -2179,14 +2179,21 @@ int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype,if (err <0 ) {netdev_err (dev->net,"Error submitting the control" " message: status=%d\n" , err); - goto fail_free; + goto fail_free_all; }return 0 ; +fail_free_all: +kfree (req); fail_free_buf:kfree (buf); -fail_free: -kfree (req); +/* +* avoid a double free +* needed because the flag can be set only +* after filling the URB +*/ + urb->transfer_flags =0 ; +fail_free_urb:usb_free_urb (urb); fail:return err;
Signature · 1 line
2.35.3
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Tue, 5 Jul 2022 14:53:51 +0200 you wrote:
usbnet_write_cmd_async()mixed up which buffers
need to be freed in which error case.v2: add Fixes tag
v3: fix uninitialized buf pointerFixes 877bd862f32b8 ("usbnet: introduce usbnet 3 command helpers")Signed-off-by Oliver Neukum <[email protected]>[...]
Here is the summary with links:
- [PATCHv3] usbnet: fix memory leak in error case
https://git.kernel.org/netdev/net/c/b55a21b764c1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html