2022-11-24 02:20:06

by Ziyang Xuan (William)

[permalink] [raw]
Subject: [PATCH net 0/2] octeontx2: Fix several bugs in exception paths

Find several obvious bugs during code review in exception paths. Provide
this patchset to fix them. Not tested, just compiled.

Ziyang Xuan (2):
octeontx2-pf: Fix possible memory leak in otx2_probe()
octeontx2-vf: Fix possible memory leak in otx2vf_probe()

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 5 ++++-
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 12 +++++++++---
2 files changed, 13 insertions(+), 4 deletions(-)

--
2.25.1


2022-11-24 02:53:08

by Ziyang Xuan (William)

[permalink] [raw]
Subject: [PATCH net 1/2] octeontx2-pf: Fix possible memory leak in otx2_probe()

In otx2_probe(), there are several possible memory leak bugs
in exception paths as follows:
1. Do not release pf->otx2_wq when excute otx2_init_tc() failed.
2. Do not shutdown tc when excute otx2_register_dl() failed.
3. Do not unregister devlink when initialize SR-IOV failed.

Fixes: 1d4d9e42c240 ("octeontx2-pf: Add tc flower hardware offload on ingress traffic")
Fixes: 2da489432747 ("octeontx2-pf: devlink params support to set mcam entry count")
Signed-off-by: Ziyang Xuan <[email protected]>
---
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
index 303930499a4c..8d7f2c3b0cfd 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
@@ -2900,7 +2900,7 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)

err = otx2_register_dl(pf);
if (err)
- goto err_mcam_flow_del;
+ goto err_register_dl;

/* Initialize SR-IOV resources */
err = otx2_sriov_vfcfg_init(pf);
@@ -2919,8 +2919,11 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
return 0;

err_pf_sriov_init:
+ otx2_unregister_dl(pf);
+err_register_dl:
otx2_shutdown_tc(pf);
err_mcam_flow_del:
+ destroy_workqueue(pf->otx2_wq);
otx2_mcam_flow_del(pf);
err_unreg_netdev:
unregister_netdev(netdev);
--
2.25.1

2022-11-25 13:57:46

by Maciej Fijalkowski

[permalink] [raw]
Subject: Re: [PATCH net 1/2] octeontx2-pf: Fix possible memory leak in otx2_probe()

On Thu, Nov 24, 2022 at 09:56:43AM +0800, Ziyang Xuan wrote:
> In otx2_probe(), there are several possible memory leak bugs
> in exception paths as follows:
> 1. Do not release pf->otx2_wq when excute otx2_init_tc() failed.
> 2. Do not shutdown tc when excute otx2_register_dl() failed.
> 3. Do not unregister devlink when initialize SR-IOV failed.
>
> Fixes: 1d4d9e42c240 ("octeontx2-pf: Add tc flower hardware offload on ingress traffic")
> Fixes: 2da489432747 ("octeontx2-pf: devlink params support to set mcam entry count")
> Signed-off-by: Ziyang Xuan <[email protected]>
> ---
> drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
> index 303930499a4c..8d7f2c3b0cfd 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
> @@ -2900,7 +2900,7 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>
> err = otx2_register_dl(pf);
> if (err)
> - goto err_mcam_flow_del;
> + goto err_register_dl;
>
> /* Initialize SR-IOV resources */
> err = otx2_sriov_vfcfg_init(pf);
> @@ -2919,8 +2919,11 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> return 0;

If otx2_dcbnl_set_ops() fails at the end then shouldn't we also call
otx2_sriov_vfcfg_cleanup() ?

>
> err_pf_sriov_init:
> + otx2_unregister_dl(pf);
> +err_register_dl:
> otx2_shutdown_tc(pf);
> err_mcam_flow_del:
> + destroy_workqueue(pf->otx2_wq);
> otx2_mcam_flow_del(pf);
> err_unreg_netdev:
> unregister_netdev(netdev);
> --
> 2.25.1
>