diff mbox series

[net,1/2] octeontx2-pf: Fix possible memory leak in otx2_probe()

Message ID e024450cf08f469fb1e0153b78a04a54829dfddb.1669253985.git.william.xuanziyang@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series octeontx2: Fix several bugs in exception paths | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Ziyang Xuan (William) Nov. 24, 2022, 1:56 a.m. UTC
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 <william.xuanziyang@huawei.com>
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Fijalkowski, Maciej Nov. 25, 2022, 1:46 p.m. UTC | #1
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 <william.xuanziyang@huawei.com>
> ---
>  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
>
Ziyang Xuan (William) Nov. 26, 2022, 1:04 a.m. UTC | #2
> 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 <william.xuanziyang@huawei.com>
>> ---
>>  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() ?

I think it does not need. This is the probe process. PF and VF are all not ready to work,
so pf->vf_configs[i].link_event_work does not scheduled. And pf->vf_configs memory resource will
be freed by devm subsystem if probe failed. There are not memory leak and other problems.

@Sunil Goutham, Please help to confirm.

Thanks.

> 
>>  
>>  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
>>
> .
>
Ziyang Xuan (William) Dec. 2, 2022, 1:44 a.m. UTC | #3
>> 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 <william.xuanziyang@huawei.com>
>>> ---
>>>  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() ?
> 
> I think it does not need. This is the probe process. PF and VF are all not ready to work,
> so pf->vf_configs[i].link_event_work does not scheduled. And pf->vf_configs memory resource will
> be freed by devm subsystem if probe failed. There are not memory leak and other problems.
> 
Hello Sunil Goutham, Maciej Fijalkowski,

What do you think about my analysis? Look forward to your reply.

Thank you!

> @Sunil Goutham, Please help to confirm.
> 
> Thanks.
> 
>>
>>>  
>>>  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
>>>
>> .
>>
> .
>
Ziyang Xuan (William) Dec. 2, 2022, 8:34 a.m. UTC | #4
> 
> ________________________________________
> From: Ziyang Xuan (William) <william.xuanziyang@huawei.com>
> Sent: Friday, December 2, 2022 7:14 AM
> To: Maciej Fijalkowski; sunil.kovvuri@gmail.com; Sunil Kovvuri Goutham
> Cc: Geethasowjanya Akula; Subbaraya Sundeep Bhatta; Hariprasad Kelam; davem@davemloft.net; edumazet@google.com; kuba@kernel.org; pabeni@redhat.com; netdev@vger.kernel.org; Naveen Mamindlapalli; Rakesh Babu Saladi; linux-kernel@vger.kernel.org
> Subject: [EXT] Re: [PATCH net 1/2] octeontx2-pf: Fix possible memory leak in otx2_probe()
> 
> External Email
> 
> ----------------------------------------------------------------------
>>>> 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 <william.xuanziyang@huawei.com>
>>>>> ---
>>>>>  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() ?
>>>
>>> I think it does not need. This is the probe process. PF and VF are all not ready to work,
>>> so pf->vf_configs[i].link_event_work does not scheduled. And pf->vf_configs memory resource will
>>> be freed by devm subsystem if probe failed. There are not memory leak and other problems.
>>>
>> Hello Sunil Goutham, Maciej Fijalkowski,
> 
>> What do you think about my analysis? Look forward to your >reply.
> otx2_sriov_vfcfg_cleanup() is not required. Since PF probe is failed, link event won't get triggered.
> 
Hello Geetha,

If there is not any other question, can you add "Reviewed-by" for my patchset?

Thank you!

> Thanks,
> Geetha.
>> Thank you!
> 
>>> @Sunil Goutham, Please help to confirm.
>>>
>>> Thanks.
>>>
>>>>
>>>>>
>>>>>  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
>>>>>
>>>> .
>>>>
>>> .
>>>
> .
>
diff mbox series

Patch

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);