forked from luck/tmp_suning_uos_patched
thunderbolt: fix memory leak of object sw
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: b04079837b
("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>
Link: https://lore.kernel.org/r/20191220220526.11307-1-colin.king@canonical.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
845f081002
commit
704a940d55
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue
Block a user