diff options
author | Colin Ian King <colin.king@canonical.com> | 2018-10-03 05:59:57 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-10-09 10:02:29 -0400 |
commit | bf7f547ecdd707e7b4fcbc467b4f9ddb29915391 (patch) | |
tree | c21940ba483db09d750220cbf08a5a8bec514566 | |
parent | 6503016ea5d3945f9af1eeac23ba99f408f3af1e (diff) |
usb: core: fix memory leak on port_dev_path allocation
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/core/hub.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index bf76a3dd4359..c6077d582d29 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -5170,7 +5170,7 @@ static void port_over_current_notify(struct usb_port *port_dev) | |||
5170 | 5170 | ||
5171 | envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path); | 5171 | envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path); |
5172 | if (!envp[0]) | 5172 | if (!envp[0]) |
5173 | return; | 5173 | goto exit_path; |
5174 | 5174 | ||
5175 | envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u", | 5175 | envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u", |
5176 | port_dev->over_current_count); | 5176 | port_dev->over_current_count); |
@@ -5182,6 +5182,8 @@ static void port_over_current_notify(struct usb_port *port_dev) | |||
5182 | kfree(envp[1]); | 5182 | kfree(envp[1]); |
5183 | exit: | 5183 | exit: |
5184 | kfree(envp[0]); | 5184 | kfree(envp[0]); |
5185 | exit_path: | ||
5186 | kfree(port_dev_path); | ||
5185 | } | 5187 | } |
5186 | 5188 | ||
5187 | static void port_event(struct usb_hub *hub, int port1) | 5189 | static void port_event(struct usb_hub *hub, int port1) |