diff mbox series

octeontx2-vf: Add missing free for alloc_percpu

Message ID 20230316023911.3615-1-jiasheng@iscas.ac.cn (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series octeontx2-vf: Add missing free for alloc_percpu | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
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: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jiasheng Jiang March 16, 2023, 2:39 a.m. UTC
Add the free_percpu for the allocated "vf->hw.lmt_info" in order to avoid
memory leak, same as the "pf->hw.lmt_info" in
`drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c`.

Fixes: 5c0512072f65 ("octeontx2-pf: cn10k: Use runtime allocated LMTLINE region")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Michal Swiatkowski March 16, 2023, 8:10 a.m. UTC | #1
On Thu, Mar 16, 2023 at 10:39:11AM +0800, Jiasheng Jiang wrote:
> Add the free_percpu for the allocated "vf->hw.lmt_info" in order to avoid
> memory leak, same as the "pf->hw.lmt_info" in
> `drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c`.
> 
> Fixes: 5c0512072f65 ("octeontx2-pf: cn10k: Use runtime allocated LMTLINE region")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
> index 7f8ffbf79cf7..9db2e2d218bb 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
> @@ -709,6 +709,8 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  err_ptp_destroy:
>  	otx2_ptp_destroy(vf);
>  err_detach_rsrc:
> +	if (vf->hw.lmt_info)
> +		free_percpu(vf->hw.lmt_info);
>  	if (test_bit(CN10K_LMTST, &vf->hw.cap_flag))
>  		qmem_free(vf->dev, vf->dync_lmt);
I wonder if it wouldn't be more error prune when You create a function
to unroll cn10k_lmtst_init() like cn10k_lmtst_deinit(). These two if can
be there, maybe also sth else is missing.

Otherwise it is fine
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

>  	otx2_detach_resources(&vf->mbox);
> @@ -762,6 +764,8 @@ static void otx2vf_remove(struct pci_dev *pdev)
>  	otx2_shutdown_tc(vf);
>  	otx2vf_disable_mbox_intr(vf);
>  	otx2_detach_resources(&vf->mbox);
> +	if (vf->hw.lmt_info)
> +		free_percpu(vf->hw.lmt_info);
>  	if (test_bit(CN10K_LMTST, &vf->hw.cap_flag))
>  		qmem_free(vf->dev, vf->dync_lmt);
>  	otx2vf_vfaf_mbox_destroy(vf);
> -- 
> 2.25.1
>
Geethasowjanya Akula March 16, 2023, 9 a.m. UTC | #2
>-----Original Message-----
>From: Michal Swiatkowski <michal.swiatkowski@linux.intel.com> 
>Sent: Thursday, March 16, 2023 1:40 PM
>To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
>Cc: Sunil Kovvuri Goutham <sgoutham@marvell.com>; Geethasowjanya Akula <gakula@marvell.com>; Subbaraya Sundeep Bhatta <sbhatta@marvell.com>; Hariprasad Kelam <hkelam@marvell.com>; >davem@davemloft.net; edumazet@google.com; kuba@kernel.org; pabeni@redhat.com; richardcochran@gmail.com; netdev@vger.kernel.org; linux-kernel@vger.kernel.org
>Subject: [EXT] Re: [PATCH] octeontx2-vf: Add missing free for alloc_percpu

>External Email

>----------------------------------------------------------------------
>On Thu, Mar 16, 2023 at 10:39:11AM +0800, Jiasheng Jiang wrote:
>> Add the free_percpu for the allocated "vf->hw.lmt_info" in order to 
>> avoid memory leak, same as the "pf->hw.lmt_info" in 
>> `drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c`.
>> 
>> Fixes: 5c0512072f65 ("octeontx2-pf: cn10k: Use runtime allocated 
>> LMTLINE region")
>> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
>> ---
>>  drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>> 
>> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c 
>> b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
>> index 7f8ffbf79cf7..9db2e2d218bb 100644
>> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
>> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
>> @@ -709,6 +709,8 @@ static int otx2vf_probe(struct pci_dev *pdev, 
>> const struct pci_device_id *id)
>>  err_ptp_destroy:
>>  	otx2_ptp_destroy(vf);
>>  err_detach_rsrc:
>> +	if (vf->hw.lmt_info)
>> +		free_percpu(vf->hw.lmt_info);
>>  	if (test_bit(CN10K_LMTST, &vf->hw.cap_flag))
>>  		qmem_free(vf->dev, vf->dync_lmt);
>I wonder if it wouldn't be more error prune when You create a function to unroll cn10k_lmtst_init() like cn10k_lmtst_deinit(). These two if can be there, maybe also sth else is missing.

>Otherwise it is fine
>Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

>>  	otx2_detach_resources(&vf->mbox);
>> @@ -762,6 +764,8 @@ static void otx2vf_remove(struct pci_dev *pdev)
>>  	otx2_shutdown_tc(vf);
>>  	otx2vf_disable_mbox_intr(vf);
>>  	otx2_detach_resources(&vf->mbox);
>> +	if (vf->hw.lmt_info)
>> +		free_percpu(vf->hw.lmt_info);

Ack. Thanks for the patch.

>>  	if (test_bit(CN10K_LMTST, &vf->hw.cap_flag))
>>  		qmem_free(vf->dev, vf->dync_lmt);
>>  	otx2vf_vfaf_mbox_destroy(vf);
>> --
>> 2.25.1
>> 

Geetha.
Jakub Kicinski March 17, 2023, 4:24 a.m. UTC | #3
On Thu, 16 Mar 2023 10:39:11 +0800 Jiasheng Jiang wrote:
> +	if (vf->hw.lmt_info)
> +		free_percpu(vf->hw.lmt_info);
>  	if (test_bit(CN10K_LMTST, &vf->hw.cap_flag))
>  		qmem_free(vf->dev, vf->dync_lmt);
>  	otx2_detach_resources(&vf->mbox);
> @@ -762,6 +764,8 @@ static void otx2vf_remove(struct pci_dev *pdev)
>  	otx2_shutdown_tc(vf);
>  	otx2vf_disable_mbox_intr(vf);
>  	otx2_detach_resources(&vf->mbox);
> +	if (vf->hw.lmt_info)
> +		free_percpu(vf->hw.lmt_info);

No need for the if () checks, free_percpu() seems to handle NULL just
fine.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
index 7f8ffbf79cf7..9db2e2d218bb 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
@@ -709,6 +709,8 @@  static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 err_ptp_destroy:
 	otx2_ptp_destroy(vf);
 err_detach_rsrc:
+	if (vf->hw.lmt_info)
+		free_percpu(vf->hw.lmt_info);
 	if (test_bit(CN10K_LMTST, &vf->hw.cap_flag))
 		qmem_free(vf->dev, vf->dync_lmt);
 	otx2_detach_resources(&vf->mbox);
@@ -762,6 +764,8 @@  static void otx2vf_remove(struct pci_dev *pdev)
 	otx2_shutdown_tc(vf);
 	otx2vf_disable_mbox_intr(vf);
 	otx2_detach_resources(&vf->mbox);
+	if (vf->hw.lmt_info)
+		free_percpu(vf->hw.lmt_info);
 	if (test_bit(CN10K_LMTST, &vf->hw.cap_flag))
 		qmem_free(vf->dev, vf->dync_lmt);
 	otx2vf_vfaf_mbox_destroy(vf);