]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: marvell: prestera: fix memory leak in prestera_rxtx_switch_init()
authorZhengchao Shao <shaozhengchao@huawei.com>
Tue, 8 Nov 2022 02:56:07 +0000 (10:56 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 16 Nov 2022 08:57:12 +0000 (09:57 +0100)
[ Upstream commit 519b58bbfa825f042fcf80261cc18e1e35f85ffd ]

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: 501ef3066c89 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/marvell/prestera/prestera_rxtx.c

index 2a13c318048cc6ddc5292bb303ad84997686aa7a..59a3ea02b8add3c1df5b8558a2716392b50afe0f 100644 (file)
@@ -771,6 +771,7 @@ 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)
@@ -778,7 +779,11 @@ int prestera_rxtx_switch_init(struct prestera_switch *sw)
 
        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)