common/cnxk: fix memory leak

Message ID 1636517315-414-1-git-send-email-anoobj@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Jerin Jacob
Headers
Series common/cnxk: fix memory leak |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional fail Functional Testing issues

Commit Message

Anoob Joseph Nov. 10, 2021, 4:08 a.m. UTC
  The memory allocated for temporarily keeping DPTR need to be freed after
operation.

Also, dptr need to be aligned to 8B.

Fixes: e0bf49f7622b ("common/cnxk: add code to write CPT CTX through microcode op")
Cc: schalla@marvell.com

Signed-off-by: Anoob Joseph <anoobj@marvell.com>
Reviewed-by: Nithin Kumar Dabilpuram <ndabilpuram@marvell.com>
Reviewed-by: Tejasree Kondoj <ktejasree@marvell.com>
---
 drivers/common/cnxk/roc_cpt.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Jerin Jacob Nov. 11, 2021, 3:18 p.m. UTC | #1
On Wed, Nov 10, 2021 at 9:39 AM Anoob Joseph <anoobj@marvell.com> wrote:
>
> The memory allocated for temporarily keeping DPTR need to be freed after
> operation.
>
> Also, dptr need to be aligned to 8B.
>
> Fixes: e0bf49f7622b ("common/cnxk: add code to write CPT CTX through microcode op")
> Cc: schalla@marvell.com
>
> Signed-off-by: Anoob Joseph <anoobj@marvell.com>
> Reviewed-by: Nithin Kumar Dabilpuram <ndabilpuram@marvell.com>
> Reviewed-by: Tejasree Kondoj <ktejasree@marvell.com>

Applied to dpdk-next-net-mrvl/for-next-net. Thanks


> ---
>  drivers/common/cnxk/roc_cpt.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/common/cnxk/roc_cpt.c b/drivers/common/cnxk/roc_cpt.c
> index 5c8c328..51cd612 100644
> --- a/drivers/common/cnxk/roc_cpt.c
> +++ b/drivers/common/cnxk/roc_cpt.c
> @@ -930,12 +930,14 @@ roc_cpt_ctx_write(struct roc_cpt_lf *lf, void *sa_dptr, void *sa_cptr,
>                 plt_err("Couldn't allocate memory for result address");
>                 return -ENOMEM;
>         }
> -       dptr = plt_zmalloc(sa_len, 0);
> -       if (!dptr) {
> +
> +       dptr = plt_zmalloc(sa_len, 8);
> +       if (dptr == NULL) {
>                 plt_err("Couldn't allocate memory for SA dptr");
>                 plt_free(res);
>                 return -ENOMEM;
>         }
> +
>         for (i = 0; i < (sa_len / 8); i++)
>                 dptr[i] = plt_cpu_to_be_64(((uint64_t *)sa_dptr)[i]);
>
> @@ -962,6 +964,7 @@ roc_cpt_ctx_write(struct roc_cpt_lf *lf, void *sa_dptr, void *sa_cptr,
>                 plt_delay_ms(1);
>
>         plt_free(res);
> +       plt_free(dptr);
>
>         return 0;
>  }
> --
> 2.7.4
>
  

Patch

diff --git a/drivers/common/cnxk/roc_cpt.c b/drivers/common/cnxk/roc_cpt.c
index 5c8c328..51cd612 100644
--- a/drivers/common/cnxk/roc_cpt.c
+++ b/drivers/common/cnxk/roc_cpt.c
@@ -930,12 +930,14 @@  roc_cpt_ctx_write(struct roc_cpt_lf *lf, void *sa_dptr, void *sa_cptr,
 		plt_err("Couldn't allocate memory for result address");
 		return -ENOMEM;
 	}
-	dptr = plt_zmalloc(sa_len, 0);
-	if (!dptr) {
+
+	dptr = plt_zmalloc(sa_len, 8);
+	if (dptr == NULL) {
 		plt_err("Couldn't allocate memory for SA dptr");
 		plt_free(res);
 		return -ENOMEM;
 	}
+
 	for (i = 0; i < (sa_len / 8); i++)
 		dptr[i] = plt_cpu_to_be_64(((uint64_t *)sa_dptr)[i]);
 
@@ -962,6 +964,7 @@  roc_cpt_ctx_write(struct roc_cpt_lf *lf, void *sa_dptr, void *sa_cptr,
 		plt_delay_ms(1);
 
 	plt_free(res);
+	plt_free(dptr);
 
 	return 0;
 }