crypto/mlx5: fix driver probing error flow

Message ID 20210729065000.172793-1-michaelba@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series crypto/mlx5: fix driver probing error flow |

Checks

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

Commit Message

Michael Baum July 29, 2021, 6:50 a.m. UTC
In crypto driver probing, there are two validations after context
allocation.

When one of them fails, the context structure was not freed what caused
a memory leak.

Free it.

Fixes: debb27ea3442 ("crypto/mlx5: create login object using DevX")
Fixes: e8db4413cba5 ("crypto/mlx5: add keytag configuration")
Cc: stable@dpdk.org

Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/crypto/mlx5/mlx5_crypto.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Akhil Goyal July 30, 2021, 7:23 p.m. UTC | #1
> In crypto driver probing, there are two validations after context
> allocation.
> 
> When one of them fails, the context structure was not freed what caused
> a memory leak.
> 
> Free it.
> 
> Fixes: debb27ea3442 ("crypto/mlx5: create login object using DevX")
> Fixes: e8db4413cba5 ("crypto/mlx5: add keytag configuration")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Michael Baum <michaelba@nvidia.com>
> Acked-by: Matan Azrad <matan@nvidia.com>
> ---
Applied to dpdk-next-crypto
@Thomas Monjalon: I do not think title and patch description are inline.
You may fix it while pulling on main branch.
  
Thomas Monjalon July 31, 2021, 9:37 a.m. UTC | #2
30/07/2021 21:23, Akhil Goyal:
> > In crypto driver probing, there are two validations after context
> > allocation.
> > 
> > When one of them fails, the context structure was not freed what caused
> > a memory leak.
> > 
> > Free it.
> > 
> > Fixes: debb27ea3442 ("crypto/mlx5: create login object using DevX")
> > Fixes: e8db4413cba5 ("crypto/mlx5: add keytag configuration")
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Michael Baum <michaelba@nvidia.com>
> > Acked-by: Matan Azrad <matan@nvidia.com>
> > ---
> Applied to dpdk-next-crypto
> @Thomas Monjalon: I do not think title and patch description are inline.
> You may fix it while pulling on main branch.

New title:
crypto/mlx5: fix leaks on probing failure
  

Patch

diff --git a/drivers/crypto/mlx5/mlx5_crypto.c b/drivers/crypto/mlx5/mlx5_crypto.c
index ea734f4d5c..b3d5200ca3 100644
--- a/drivers/crypto/mlx5/mlx5_crypto.c
+++ b/drivers/crypto/mlx5/mlx5_crypto.c
@@ -1021,12 +1021,14 @@  mlx5_crypto_dev_probe(struct rte_device *dev)
 	ret = mlx5_crypto_parse_devargs(dev->devargs, &devarg_prms);
 	if (ret) {
 		DRV_LOG(ERR, "Failed to parse devargs.");
+		claim_zero(mlx5_glue->close_device(ctx));
 		return -rte_errno;
 	}
 	login = mlx5_devx_cmd_create_crypto_login_obj(ctx,
 						      &devarg_prms.login_attr);
 	if (login == NULL) {
 		DRV_LOG(ERR, "Failed to configure login.");
+		claim_zero(mlx5_glue->close_device(ctx));
 		return -rte_errno;
 	}
 	crypto_dev = rte_cryptodev_pmd_create(ibv->name, dev,