2022-11-24 02:20:03

by Ziyang Xuan (William)

[permalink] [raw]
Subject: [PATCH net 2/2] octeontx2-vf: Fix possible memory leak in otx2vf_probe()

In otx2vf_probe(), there are several possible memory leak bugs
in exception paths as follows:
1. Do not release vf->otx2_wq when excute otx2vf_mcam_flow_init() and
otx2_init_tc() failed.
2. Do not unregister devlink when excute otx2_dcbnl_set_ops() failed.

Fixes: 4b0385bc8e6a ("octeontx2-pf: Add TC feature for VFs")
Fixes: 8e67558177f8 ("octeontx2-pf: PFC config support with DCBx")
Fixes: 3cffaed2136c ("octeontx2-pf: Ntuple filters support for VF netdev")
Signed-off-by: Ziyang Xuan <[email protected]>
---
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
index 86653bb8e403..f1b47fecd379 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
@@ -684,11 +684,11 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)

err = otx2vf_mcam_flow_init(vf);
if (err)
- goto err_unreg_netdev;
+ goto err_destroy_wq;

err = otx2_init_tc(vf);
if (err)
- goto err_unreg_netdev;
+ goto err_destroy_wq;

err = otx2_register_dl(vf);
if (err)
@@ -697,13 +697,19 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
#ifdef CONFIG_DCB
err = otx2_dcbnl_set_ops(netdev);
if (err)
- goto err_shutdown_tc;
+ goto err_unreg_dl;
#endif

return 0;

+#ifdef CONFIG_DCB
+err_unreg_dl:
+ otx2_unregister_dl(vf);
+#endif
err_shutdown_tc:
otx2_shutdown_tc(vf);
+err_destroy_wq:
+ destroy_workqueue(vf->otx2_wq);
err_unreg_netdev:
unregister_netdev(netdev);
err_ptp_destroy:
--
2.25.1