[03/13] librte_security: fix session counter

Message ID 20200312151654.7218-4-l.wojciechow@partner.samsung.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series Fixes and unit tests for librte_security |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Lukasz Wojciechowski March 12, 2020, 3:16 p.m. UTC
  Fix session counter to be decreased in rte_security_session_destroy
only when session was successfully destoyed.

Formerly session counter was decreased prior session destroying
and returning session object to mempool. It remained decreased even
if session was not destroyed and mempool object released making counter
invalid.

Signed-off-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Change-Id: I75ebfc26811ec2159b973fae36b2c9fb08868f11
---
 lib/librte_security/rte_security.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Anoob Joseph March 17, 2020, 5:08 p.m. UTC | #1
Hi Lukasz,

The title need to be changed (librte_security -> security). With that change,

Acked-by: Anoob Joseph <anoobj@marvell.com>

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Lukasz Wojciechowski
> Sent: Thursday, March 12, 2020 8:47 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH 03/13] librte_security: fix session counter
> 
> Fix session counter to be decreased in rte_security_session_destroy only when
> session was successfully destoyed.
> 
> Formerly session counter was decreased prior session destroying and returning
> session object to mempool. It remained decreased even if session was not
> destroyed and mempool object released making counter invalid.
> 
> Signed-off-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
> Change-Id: I75ebfc26811ec2159b973fae36b2c9fb08868f11
> ---
>  lib/librte_security/rte_security.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/librte_security/rte_security.c b/lib/librte_security/rte_security.c
> index 40a0e9ce5..74a314903 100644
> --- a/lib/librte_security/rte_security.c
> +++ b/lib/librte_security/rte_security.c
> @@ -87,14 +87,16 @@ rte_security_session_destroy(struct rte_security_ctx
> *instance,
>  	RTE_PTR_OR_ERR_RET(instance->ops->session_destroy, -ENOTSUP);
>  	RTE_PTR_OR_ERR_RET(sess, -EINVAL);
> 
> +	ret = instance->ops->session_destroy(instance->device, sess);
> +	if (ret != 0)
> +		return ret;
> +
> +	rte_mempool_put(rte_mempool_from_obj(sess), (void *)sess);
> +
>  	if (instance->sess_cnt)
>  		instance->sess_cnt--;
> 
> -	ret = instance->ops->session_destroy(instance->device, sess);
> -	if (!ret)
> -		rte_mempool_put(rte_mempool_from_obj(sess), (void *)sess);
> -
> -	return ret;
> +	return 0;
>  }
> 
>  int
> --
> 2.17.1
  

Patch

diff --git a/lib/librte_security/rte_security.c b/lib/librte_security/rte_security.c
index 40a0e9ce5..74a314903 100644
--- a/lib/librte_security/rte_security.c
+++ b/lib/librte_security/rte_security.c
@@ -87,14 +87,16 @@  rte_security_session_destroy(struct rte_security_ctx *instance,
 	RTE_PTR_OR_ERR_RET(instance->ops->session_destroy, -ENOTSUP);
 	RTE_PTR_OR_ERR_RET(sess, -EINVAL);
 
+	ret = instance->ops->session_destroy(instance->device, sess);
+	if (ret != 0)
+		return ret;
+
+	rte_mempool_put(rte_mempool_from_obj(sess), (void *)sess);
+
 	if (instance->sess_cnt)
 		instance->sess_cnt--;
 
-	ret = instance->ops->session_destroy(instance->device, sess);
-	if (!ret)
-		rte_mempool_put(rte_mempool_from_obj(sess), (void *)sess);
-
-	return ret;
+	return 0;
 }
 
 int