DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/2] remove unnecessary null checks in OpenSSL usage
@ 2023-11-02 23:02 Stephen Hemminger
  2023-11-02 23:02 ` [PATCH 1/2] nullfree: add matches for null free cases from OpenSSL Stephen Hemminger
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Stephen Hemminger @ 2023-11-02 23:02 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

OpenSSL follows null free conventions

Stephen Hemminger (2):
  nullfree: add matches for null free cases from OpenSSL
  crypto/openssl: remove unnecessary NULL checks before free

 devtools/cocci/nullfree.cocci                |  9 +++++
 drivers/crypto/openssl/rte_openssl_pmd.c     | 36 +++++++-------------
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  3 +-
 3 files changed, 22 insertions(+), 26 deletions(-)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] nullfree: add matches for null free cases from OpenSSL
  2023-11-02 23:02 [PATCH 0/2] remove unnecessary null checks in OpenSSL usage Stephen Hemminger
@ 2023-11-02 23:02 ` Stephen Hemminger
  2023-11-02 23:02 ` [PATCH 2/2] crypto/openssl: remove unnecessary NULL checks before free Stephen Hemminger
  2023-11-09 20:12 ` [EXT] [PATCH 0/2] remove unnecessary null checks in OpenSSL usage Akhil Goyal
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2023-11-02 23:02 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

OpenSSL functions follow the design parameter that free
of NULL is ok.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 devtools/cocci/nullfree.cocci | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/devtools/cocci/nullfree.cocci b/devtools/cocci/nullfree.cocci
index 9ca3fc2864..c58aad4fb7 100644
--- a/devtools/cocci/nullfree.cocci
+++ b/devtools/cocci/nullfree.cocci
@@ -126,4 +126,13 @@ expression E;
 |
 - if (E != NULL) trie_free(E);
 + trie_free(E);
+|
+- if (E != NULL) EVP_PKEY_CTX_free(E);
++ EVP_PKEY_CTX_free(E);
+|
+- if (E != NULL) EVP_PKEY_free(E);
++ EVP_PKEY_free(E);
+|
+- if (E != NULL) BN_free(E);
++ BN_free(E);
 )
-- 
2.41.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] crypto/openssl: remove unnecessary NULL checks before free
  2023-11-02 23:02 [PATCH 0/2] remove unnecessary null checks in OpenSSL usage Stephen Hemminger
  2023-11-02 23:02 ` [PATCH 1/2] nullfree: add matches for null free cases from OpenSSL Stephen Hemminger
@ 2023-11-02 23:02 ` Stephen Hemminger
  2023-11-07 14:12   ` Ji, Kai
  2023-11-09 20:12 ` [EXT] [PATCH 0/2] remove unnecessary null checks in OpenSSL usage Akhil Goyal
  2 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2023-11-02 23:02 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Kai Ji

Found with nullfree.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/crypto/openssl/rte_openssl_pmd.c     | 36 +++++++-------------
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  3 +-
 2 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index c234882417..090320602d 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -1957,10 +1957,8 @@ process_openssl_dsa_sign_op_evp(struct rte_crypto_op *cop,
 err_dsa_sign:
 	if (params)
 		OSSL_PARAM_free(params);
-	if (key_ctx)
-		EVP_PKEY_CTX_free(key_ctx);
-	if (dsa_ctx)
-		EVP_PKEY_CTX_free(dsa_ctx);
+	EVP_PKEY_CTX_free(key_ctx);
+	EVP_PKEY_CTX_free(dsa_ctx);
 	return -1;
 }
 
@@ -2039,10 +2037,8 @@ process_openssl_dsa_verify_op_evp(struct rte_crypto_op *cop,
 		DSA_SIG_free(sign);
 	if (params)
 		OSSL_PARAM_free(params);
-	if (key_ctx)
-		EVP_PKEY_CTX_free(key_ctx);
-	if (dsa_ctx)
-		EVP_PKEY_CTX_free(dsa_ctx);
+	EVP_PKEY_CTX_free(key_ctx);
+	EVP_PKEY_CTX_free(dsa_ctx);
 
 	return ret;
 }
@@ -2294,16 +2290,12 @@ process_openssl_dh_op_evp(struct rte_crypto_op *cop,
 	ret = 0;
 
  err_dh:
-	if (pub_key)
-		BN_free(pub_key);
-	if (priv_key)
-		BN_free(priv_key);
+	BN_free(pub_key);
+	BN_free(priv_key);
 	if (params)
 		OSSL_PARAM_free(params);
-	if (dhpkey)
-		EVP_PKEY_free(dhpkey);
-	if (peerkey)
-		EVP_PKEY_free(peerkey);
+	EVP_PKEY_free(dhpkey);
+	EVP_PKEY_free(peerkey);
 
 	EVP_PKEY_CTX_free(dh_ctx);
 
@@ -2880,17 +2872,13 @@ process_openssl_sm2_op_evp(struct rte_crypto_op *cop,
 	ret = 0;
 	cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
 err_sm2:
-	if (kctx)
-		EVP_PKEY_CTX_free(kctx);
+	EVP_PKEY_CTX_free(kctx);
 
-	if (sctx)
-		EVP_PKEY_CTX_free(sctx);
+	EVP_PKEY_CTX_free(sctx);
 
-	if (cctx)
-		EVP_PKEY_CTX_free(cctx);
+	EVP_PKEY_CTX_free(cctx);
 
-	if (pkey)
-		EVP_PKEY_free(pkey);
+	EVP_PKEY_free(pkey);
 
 	return ret;
 }
diff --git a/drivers/crypto/openssl/rte_openssl_pmd_ops.c b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
index 2862c294a9..419a767817 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd_ops.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
@@ -1431,8 +1431,7 @@ static void openssl_reset_asym_session(struct openssl_asym_session *sess)
 	switch (sess->xfrm_type) {
 	case RTE_CRYPTO_ASYM_XFORM_RSA:
 #if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
-		if (sess->u.r.ctx)
-			EVP_PKEY_CTX_free(sess->u.r.ctx);
+		EVP_PKEY_CTX_free(sess->u.r.ctx);
 #else
 		if (sess->u.r.rsa)
 			RSA_free(sess->u.r.rsa);
-- 
2.41.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] crypto/openssl: remove unnecessary NULL checks before free
  2023-11-02 23:02 ` [PATCH 2/2] crypto/openssl: remove unnecessary NULL checks before free Stephen Hemminger
@ 2023-11-07 14:12   ` Ji, Kai
  0 siblings, 0 replies; 5+ messages in thread
From: Ji, Kai @ 2023-11-07 14:12 UTC (permalink / raw)
  To: Stephen Hemminger, dev

[-- Attachment #1: Type: text/plain, Size: 3555 bytes --]

Acked-by: Kai Ji <kai.ji@intel.com>
________________________________
From: Stephen Hemminger <stephen@networkplumber.org>
Sent: 02 November 2023 23:02
To: dev@dpdk.org <dev@dpdk.org>
Cc: Stephen Hemminger <stephen@networkplumber.org>; Ji, Kai <kai.ji@intel.com>
Subject: [PATCH 2/2] crypto/openssl: remove unnecessary NULL checks before free

Found with nullfree.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/crypto/openssl/rte_openssl_pmd.c     | 36 +++++++-------------
 drivers/crypto/openssl/rte_openssl_pmd_ops.c |  3 +-
 2 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index c234882417..090320602d 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -1957,10 +1957,8 @@ process_openssl_dsa_sign_op_evp(struct rte_crypto_op *cop,
 err_dsa_sign:
         if (params)
                 OSSL_PARAM_free(params);
-       if (key_ctx)
-               EVP_PKEY_CTX_free(key_ctx);
-       if (dsa_ctx)
-               EVP_PKEY_CTX_free(dsa_ctx);
+       EVP_PKEY_CTX_free(key_ctx);
+       EVP_PKEY_CTX_free(dsa_ctx);
         return -1;
 }

@@ -2039,10 +2037,8 @@ process_openssl_dsa_verify_op_evp(struct rte_crypto_op *cop,
                 DSA_SIG_free(sign);
         if (params)
                 OSSL_PARAM_free(params);
-       if (key_ctx)
-               EVP_PKEY_CTX_free(key_ctx);
-       if (dsa_ctx)
-               EVP_PKEY_CTX_free(dsa_ctx);
+       EVP_PKEY_CTX_free(key_ctx);
+       EVP_PKEY_CTX_free(dsa_ctx);

         return ret;
 }
@@ -2294,16 +2290,12 @@ process_openssl_dh_op_evp(struct rte_crypto_op *cop,
         ret = 0;

  err_dh:
-       if (pub_key)
-               BN_free(pub_key);
-       if (priv_key)
-               BN_free(priv_key);
+       BN_free(pub_key);
+       BN_free(priv_key);
         if (params)
                 OSSL_PARAM_free(params);
-       if (dhpkey)
-               EVP_PKEY_free(dhpkey);
-       if (peerkey)
-               EVP_PKEY_free(peerkey);
+       EVP_PKEY_free(dhpkey);
+       EVP_PKEY_free(peerkey);

         EVP_PKEY_CTX_free(dh_ctx);

@@ -2880,17 +2872,13 @@ process_openssl_sm2_op_evp(struct rte_crypto_op *cop,
         ret = 0;
         cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
 err_sm2:
-       if (kctx)
-               EVP_PKEY_CTX_free(kctx);
+       EVP_PKEY_CTX_free(kctx);

-       if (sctx)
-               EVP_PKEY_CTX_free(sctx);
+       EVP_PKEY_CTX_free(sctx);

-       if (cctx)
-               EVP_PKEY_CTX_free(cctx);
+       EVP_PKEY_CTX_free(cctx);

-       if (pkey)
-               EVP_PKEY_free(pkey);
+       EVP_PKEY_free(pkey);

         return ret;
 }
diff --git a/drivers/crypto/openssl/rte_openssl_pmd_ops.c b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
index 2862c294a9..419a767817 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd_ops.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd_ops.c
@@ -1431,8 +1431,7 @@ static void openssl_reset_asym_session(struct openssl_asym_session *sess)
         switch (sess->xfrm_type) {
         case RTE_CRYPTO_ASYM_XFORM_RSA:
 #if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
-               if (sess->u.r.ctx)
-                       EVP_PKEY_CTX_free(sess->u.r.ctx);
+               EVP_PKEY_CTX_free(sess->u.r.ctx);
 #else
                 if (sess->u.r.rsa)
                         RSA_free(sess->u.r.rsa);
--
2.41.0


[-- Attachment #2: Type: text/html, Size: 7679 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [EXT] [PATCH 0/2] remove unnecessary null checks in OpenSSL usage
  2023-11-02 23:02 [PATCH 0/2] remove unnecessary null checks in OpenSSL usage Stephen Hemminger
  2023-11-02 23:02 ` [PATCH 1/2] nullfree: add matches for null free cases from OpenSSL Stephen Hemminger
  2023-11-02 23:02 ` [PATCH 2/2] crypto/openssl: remove unnecessary NULL checks before free Stephen Hemminger
@ 2023-11-09 20:12 ` Akhil Goyal
  2 siblings, 0 replies; 5+ messages in thread
From: Akhil Goyal @ 2023-11-09 20:12 UTC (permalink / raw)
  To: Stephen Hemminger, dev

> OpenSSL follows null free conventions
> 
> Stephen Hemminger (2):
>   nullfree: add matches for null free cases from OpenSSL
>   crypto/openssl: remove unnecessary NULL checks before free
> 
>  devtools/cocci/nullfree.cocci                |  9 +++++
>  drivers/crypto/openssl/rte_openssl_pmd.c     | 36 +++++++-------------
>  drivers/crypto/openssl/rte_openssl_pmd_ops.c |  3 +-
>  3 files changed, 22 insertions(+), 26 deletions(-)
Series Applied to dpdk-next-crypto
Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-09 20:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-02 23:02 [PATCH 0/2] remove unnecessary null checks in OpenSSL usage Stephen Hemminger
2023-11-02 23:02 ` [PATCH 1/2] nullfree: add matches for null free cases from OpenSSL Stephen Hemminger
2023-11-02 23:02 ` [PATCH 2/2] crypto/openssl: remove unnecessary NULL checks before free Stephen Hemminger
2023-11-07 14:12   ` Ji, Kai
2023-11-09 20:12 ` [EXT] [PATCH 0/2] remove unnecessary null checks in OpenSSL usage Akhil Goyal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).