netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: kalmia: fix memory leaks
@ 2019-08-14 18:56 Wenwen Wang
  2019-08-18 20:03 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Wenwen Wang @ 2019-08-14 18:56 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: David S. Miller, Greg Kroah-Hartman, Allison Randal,
	Thomas Gleixner, open list:USB NETWORKING DRIVERS,
	open list:NETWORKING DRIVERS, open list

In kalmia_init_and_get_ethernet_addr(), 'usb_buf' is allocated through
kmalloc(). In the following execution, if the 'status' returned by
kalmia_send_init_packet() is not 0, 'usb_buf' is not deallocated, leading
to memory leaks. To fix this issue, add the 'out' label to free 'usb_buf'.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/net/usb/kalmia.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
index d62b670..fc5895f 100644
--- a/drivers/net/usb/kalmia.c
+++ b/drivers/net/usb/kalmia.c
@@ -113,16 +113,16 @@ kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
 	status = kalmia_send_init_packet(dev, usb_buf, ARRAY_SIZE(init_msg_1),
 					 usb_buf, 24);
 	if (status != 0)
-		return status;
+		goto out;
 
 	memcpy(usb_buf, init_msg_2, 12);
 	status = kalmia_send_init_packet(dev, usb_buf, ARRAY_SIZE(init_msg_2),
 					 usb_buf, 28);
 	if (status != 0)
-		return status;
+		goto out;
 
 	memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
-
+out:
 	kfree(usb_buf);
 	return status;
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: kalmia: fix memory leaks
  2019-08-14 18:56 [PATCH] net: kalmia: fix memory leaks Wenwen Wang
@ 2019-08-18 20:03 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-08-18 20:03 UTC (permalink / raw)
  To: wenwen; +Cc: gregkh, allison, tglx, linux-usb, netdev, linux-kernel

From: Wenwen Wang <wenwen@cs.uga.edu>
Date: Wed, 14 Aug 2019 13:56:43 -0500

> In kalmia_init_and_get_ethernet_addr(), 'usb_buf' is allocated through
> kmalloc(). In the following execution, if the 'status' returned by
> kalmia_send_init_packet() is not 0, 'usb_buf' is not deallocated, leading
> to memory leaks. To fix this issue, add the 'out' label to free 'usb_buf'.
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-18 20:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-14 18:56 [PATCH] net: kalmia: fix memory leaks Wenwen Wang
2019-08-18 20:03 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).