* [PATCH][next] thunderbolt: fix memory leak of object sw
@ 2019-12-20 22:05 Colin King
2019-12-23 10:13 ` Mika Westerberg
0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2019-12-20 22:05 UTC (permalink / raw)
To: Andreas Noever, Michael Jamet, Mika Westerberg, Yehezkel Bernat,
Greg Kroah-Hartman, Rajmohan Mani
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
In the case where the call tb_switch_exceeds_max_depth is true
the error reurn path leaks memory in sw. Fix this by setting
the return error code to -EADDRNOTAVAIL and returning via the
error exit path err_free_sw_ports to free sw. sw has been kzalloc'd
so the free of the NULL sw->ports is fine.
Addresses-Coverity: ("Resource leak")
Fixes: b04079837b20 ("thunderbolt: Add initial support for USB4")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/thunderbolt/switch.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index 3454e6154958..ad5479f21174 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -1885,8 +1885,10 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent,
sw->config.enabled = 0;
/* Make sure we do not exceed maximum topology limit */
- if (tb_switch_exceeds_max_depth(sw, depth))
- return ERR_PTR(-EADDRNOTAVAIL);
+ if (tb_switch_exceeds_max_depth(sw, depth)) {
+ ret = -EADDRNOTAVAIL;
+ goto err_free_sw_ports;
+ }
/* initialize ports */
sw->ports = kcalloc(sw->config.max_port_number + 1, sizeof(*sw->ports),
--
2.24.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] thunderbolt: fix memory leak of object sw
2019-12-20 22:05 [PATCH][next] thunderbolt: fix memory leak of object sw Colin King
@ 2019-12-23 10:13 ` Mika Westerberg
2019-12-23 11:52 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Mika Westerberg @ 2019-12-23 10:13 UTC (permalink / raw)
To: Colin King
Cc: Andreas Noever, Michael Jamet, Yehezkel Bernat,
Greg Kroah-Hartman, Rajmohan Mani, kernel-janitors, linux-kernel
On Fri, Dec 20, 2019 at 10:05:26PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> In the case where the call tb_switch_exceeds_max_depth is true
> the error reurn path leaks memory in sw. Fix this by setting
> the return error code to -EADDRNOTAVAIL and returning via the
> error exit path err_free_sw_ports to free sw. sw has been kzalloc'd
> so the free of the NULL sw->ports is fine.
>
> Addresses-Coverity: ("Resource leak")
> Fixes: b04079837b20 ("thunderbolt: Add initial support for USB4")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Greg, can you take this to your usb-next branch where the rest of the
USB4 stuff is?
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] thunderbolt: fix memory leak of object sw
2019-12-23 10:13 ` Mika Westerberg
@ 2019-12-23 11:52 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2019-12-23 11:52 UTC (permalink / raw)
To: Mika Westerberg
Cc: Colin King, Andreas Noever, Michael Jamet, Yehezkel Bernat,
Rajmohan Mani, kernel-janitors, linux-kernel
On Mon, Dec 23, 2019 at 12:13:17PM +0200, Mika Westerberg wrote:
> On Fri, Dec 20, 2019 at 10:05:26PM +0000, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > In the case where the call tb_switch_exceeds_max_depth is true
> > the error reurn path leaks memory in sw. Fix this by setting
> > the return error code to -EADDRNOTAVAIL and returning via the
> > error exit path err_free_sw_ports to free sw. sw has been kzalloc'd
> > so the free of the NULL sw->ports is fine.
> >
> > Addresses-Coverity: ("Resource leak")
> > Fixes: b04079837b20 ("thunderbolt: Add initial support for USB4")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
>
> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
>
> Greg, can you take this to your usb-next branch where the rest of the
> USB4 stuff is?
Will do, thanks.
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-23 11:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-20 22:05 [PATCH][next] thunderbolt: fix memory leak of object sw Colin King
2019-12-23 10:13 ` Mika Westerberg
2019-12-23 11:52 ` Greg Kroah-Hartman
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).