* [PATCH][usb-next] usb: core: fix memory leak on port_dev_path allocation
@ 2018-10-03 9:59 ` Colin King
0 siblings, 0 replies; 3+ messages in thread
From: Colin King @ 2018-10-03 9:59 UTC (permalink / raw)
To: Greg Kroah-Hartman, Alan Stern, Jon Flatley, linux-usb
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Currently the allocation of port_dev_path from the call to
kobject_get_path is not being kfree'd, causing a memory leak. Fix
this by kfree'ing this at the end of the function. Add an extra
error exit path to fix one of the early leaks when envp[0] fails
to be allocated.
Detected by CoverityScan, CID#1473771 ("Resource Leak")
Fixes: 201af55da8a3 ("usb: core: added uevent for over-current")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/usb/core/hub.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 7801bb30bdba..8ae781ce1a80 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -5168,7 +5168,7 @@ static void port_over_current_notify(struct usb_port *port_dev)
envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path);
if (!envp[0])
- return;
+ goto exit_path;
envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
port_dev->over_current_count);
@@ -5180,6 +5180,8 @@ static void port_over_current_notify(struct usb_port *port_dev)
kfree(envp[1]);
exit:
kfree(envp[0]);
+exit_path:
+ kfree(port_dev_path);
}
static void port_event(struct usb_hub *hub, int port1)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH][usb-next] usb: core: fix memory leak on port_dev_path allocation
@ 2018-10-03 9:59 ` Colin King
0 siblings, 0 replies; 3+ messages in thread
From: Colin King @ 2018-10-03 9:59 UTC (permalink / raw)
To: Greg Kroah-Hartman, Alan Stern, Jon Flatley, linux-usb
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Currently the allocation of port_dev_path from the call to
kobject_get_path is not being kfree'd, causing a memory leak. Fix
this by kfree'ing this at the end of the function. Add an extra
error exit path to fix one of the early leaks when envp[0] fails
to be allocated.
Detected by CoverityScan, CID#1473771 ("Resource Leak")
Fixes: 201af55da8a3 ("usb: core: added uevent for over-current")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/usb/core/hub.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 7801bb30bdba..8ae781ce1a80 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -5168,7 +5168,7 @@ static void port_over_current_notify(struct usb_port *port_dev)
envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path);
if (!envp[0])
- return;
+ goto exit_path;
envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
port_dev->over_current_count);
@@ -5180,6 +5180,8 @@ static void port_over_current_notify(struct usb_port *port_dev)
kfree(envp[1]);
exit:
kfree(envp[0]);
+exit_path:
+ kfree(port_dev_path);
}
static void port_event(struct usb_hub *hub, int port1)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [usb-next] usb: core: fix memory leak on port_dev_path allocation
@ 2018-10-03 9:59 ` Colin King
0 siblings, 0 replies; 3+ messages in thread
From: Colin King @ 2018-10-03 9:59 UTC (permalink / raw)
To: Greg Kroah-Hartman, Alan Stern, Jon Flatley, linux-usb
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Currently the allocation of port_dev_path from the call to
kobject_get_path is not being kfree'd, causing a memory leak. Fix
this by kfree'ing this at the end of the function. Add an extra
error exit path to fix one of the early leaks when envp[0] fails
to be allocated.
Detected by CoverityScan, CID#1473771 ("Resource Leak")
Fixes: 201af55da8a3 ("usb: core: added uevent for over-current")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/usb/core/hub.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 7801bb30bdba..8ae781ce1a80 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -5168,7 +5168,7 @@ static void port_over_current_notify(struct usb_port *port_dev)
envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path);
if (!envp[0])
- return;
+ goto exit_path;
envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
port_dev->over_current_count);
@@ -5180,6 +5180,8 @@ static void port_over_current_notify(struct usb_port *port_dev)
kfree(envp[1]);
exit:
kfree(envp[0]);
+exit_path:
+ kfree(port_dev_path);
}
static void port_event(struct usb_hub *hub, int port1)
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-10-03 10:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-03 9:59 [PATCH][usb-next] usb: core: fix memory leak on port_dev_path allocation Colin King
2018-10-03 9:59 ` [usb-next] " Colin King
2018-10-03 9:59 ` [PATCH][usb-next] " Colin King
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.