Skip to content

Commit

Permalink
net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init()
Browse files Browse the repository at this point in the history
When prestera_sdma_switch_init() failed, the memory pointed to by
sw->rxtx isn't released. Fix it. Only be compiled, not be tested.

Fixes: 501ef30 ("net: marvell: prestera: Add driver for Prestera family ASIC devices")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Reviewed-by: Vadym Kochan <vadym.kochan@plvision.eu>
Link: https://lore.kernel.org/r/20221108025607.338450-1-shaozhengchao@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Zhengchao Shao authored and Jakub Kicinski committed Nov 9, 2022
1 parent 2b01450 commit 519b58b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/net/ethernet/marvell/prestera/prestera_rxtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,14 +776,19 @@ static netdev_tx_t prestera_sdma_xmit(struct prestera_sdma *sdma,
int prestera_rxtx_switch_init(struct prestera_switch *sw)
{
struct prestera_rxtx *rxtx;
int err;

rxtx = kzalloc(sizeof(*rxtx), GFP_KERNEL);
if (!rxtx)
return -ENOMEM;

sw->rxtx = rxtx;

return prestera_sdma_switch_init(sw);
err = prestera_sdma_switch_init(sw);
if (err)
kfree(rxtx);

return err;
}

void prestera_rxtx_switch_fini(struct prestera_switch *sw)
Expand Down

0 comments on commit 519b58b

Please sign in to comment.