common/cnxk: fix memory leak
PATCH 1/1 common/cnxk: fix memory leak
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")
Signed-off-by Anoob Joseph <[email protected]>
Reviewed-by Nithin Kumar Dabilpuram <[email protected]>
Reviewed-by Tejasree Kondoj <[email protected]>
--- drivers/common/cnxk/roc_cpt.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_cpt.c +5 -2
@@ -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 ; }
Signature · 1 line
2.7.4
PATCH v2 1/1 common/cnxk: fix memory leak
The memory allocated for temporarily keeping DPTR need to be freed after operation.
Also, dptr need to be aligned to 8B.
Fixes 71213a8b773c ("common/cnxk: support CPT CTX write through microcode op")
Signed-off-by Anoob Joseph <[email protected]>
Reviewed-by Nithin Kumar Dabilpuram <[email protected]>
Reviewed-by Tejasree Kondoj <[email protected]>
---
v2:
- Fixed commit hash in "Fixes" line
drivers/common/cnxk/roc_cpt.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_cpt.c +5 -2
@@ -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 ; }
Signature · 1 line
2.7.4
Jerin Jacob
AppliedQuoted 4 lines · Anoob Joseph
The memory allocated for temporarily keeping DPTR need to be freed after operation.
Quoted 8 lines
Also, dptr need to be aligned to 8B.
Fixes e0bf49f7622b ("common/cnxk: add code to write CPT CTX through microcode op")Signed-off-by Anoob Joseph <[email protected]>Reviewed-by Nithin Kumar Dabilpuram <[email protected]>Reviewed-by Tejasree Kondoj <[email protected]>
Applied to dpdk-next-net-mrvl/for-next-net. Thanks
Quoted 36 lines
--- drivers/common/cnxk/roc_cpt.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/common/cnxk/roc_cpt.c +5
-3@@ -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