crypto/caam_jr: fix memory leak and illegal memory access

Message ID 1554813675-13955-1-git-send-email-g.singh@nxp.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series crypto/caam_jr: fix memory leak and illegal memory access |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Gagandeep Singh April 9, 2019, 6:18 a.m. UTC
  Opendir() returns allocated storage which must be freed at the
end of function or in case any return on error. so freeing the
allocation using closedir in an error case.

Coverity issue: 323507
Coverity issue: 325880
Fixes: e7a45f3cc245 ("crypto/caam_jr: add UIO specific operations")
Cc: g.singh@nxp.com

Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
---
 drivers/crypto/caam_jr/caam_jr_uio.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
  

Comments

Akhil Goyal April 16, 2019, 1:47 p.m. UTC | #1
> Opendir() returns allocated storage which must be freed at the
> end of function or in case any return on error. so freeing the
> allocation using closedir in an error case.
> 
> Coverity issue: 323507
> Coverity issue: 325880
> Fixes: e7a45f3cc245 ("crypto/caam_jr: add UIO specific operations")
> Cc: g.singh@nxp.com
> 
> Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> ---
>  drivers/crypto/caam_jr/caam_jr_uio.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)


Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
  
Akhil Goyal April 16, 2019, 2:51 p.m. UTC | #2
> 
> > Opendir() returns allocated storage which must be freed at the
> > end of function or in case any return on error. so freeing the
> > allocation using closedir in an error case.
> >
> > Coverity issue: 323507
> > Coverity issue: 325880
> > Fixes: e7a45f3cc245 ("crypto/caam_jr: add UIO specific operations")
> > Cc: g.singh@nxp.com
> >
> > Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> > ---
> >  drivers/crypto/caam_jr/caam_jr_uio.c | 10 +++++++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> 
> Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
Applied to dpdk-next-crypto

Thanks.
  

Patch

diff --git a/drivers/crypto/caam_jr/caam_jr_uio.c b/drivers/crypto/caam_jr/caam_jr_uio.c
index bf872a2..afd75c9 100644
--- a/drivers/crypto/caam_jr/caam_jr_uio.c
+++ b/drivers/crypto/caam_jr/caam_jr_uio.c
@@ -362,8 +362,8 @@ 
 			job_ring->register_base_addr,
 			(unsigned long)job_ring->map_size, strerror(errno));
 	} else
-		CAAM_JR_DEBUG("  JR UIO memory unmapped at %p",
-				job_ring->register_base_addr);
+		CAAM_JR_DEBUG("JR UIO memory is unmapped");
+
 	job_ring->register_base_addr = NULL;
 }
 
@@ -445,7 +445,11 @@  uio_job_ring *config_job_ring(void)
 			ret = file_read_first_line(SEC_UIO_DEVICE_SYS_ATTR_PATH,
 					dir->d_name, "name", uio_name);
 			CAAM_JR_INFO("sec device uio name: %s", uio_name);
-			SEC_ASSERT(ret == 0, -1, "file_read_first_line failed");
+			if (ret != 0) {
+				CAAM_JR_ERR("file_read_first_line failed\n");
+				closedir(d);
+				return -1;
+			}
 
 			if (file_name_match_extract(uio_name,
 						SEC_UIO_DEVICE_NAME,