DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Konstantin Ananyev <konstantin.ananyev@intel.com>,
	Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Subject: [PATCH v3 2/8] acl: remove unnecessary null checks
Date: Sun, 20 Feb 2022 10:21:41 -0800	[thread overview]
Message-ID: <20220220182147.9750-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20220220182147.9750-1-stephen@networkplumber.org>

This function already handles NULL as valid input.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_acl.c          | 12 ++++--------
 lib/acl/rte_acl.h            |  1 +
 lib/table/rte_swx_table_wm.c |  3 +--
 lib/table/rte_table_acl.c    | 15 +++++----------
 4 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/app/test/test_acl.c b/app/test/test_acl.c
index 4d51098925c4..623f34682e69 100644
--- a/app/test/test_acl.c
+++ b/app/test/test_acl.c
@@ -1171,8 +1171,7 @@ test_create_find_add(void)
 		printf("Line %i: Creating context with existing name "
 			"test failed!\n",
 			__LINE__);
-		if (tmp)
-			rte_acl_free(tmp);
+		rte_acl_free(tmp);
 		goto err;
 	}
 
@@ -1182,8 +1181,7 @@ test_create_find_add(void)
 		printf("Line %i: Creating context with existing "
 			"name test 2 failed!\n",
 			__LINE__);
-		if (tmp)
-			rte_acl_free(tmp);
+		rte_acl_free(tmp);
 		goto err;
 	}
 
@@ -1191,16 +1189,14 @@ test_create_find_add(void)
 	tmp = rte_acl_find_existing(acx_name);
 	if (tmp != acx) {
 		printf("Line %i: Finding %s failed!\n", __LINE__, acx_name);
-		if (tmp)
-			rte_acl_free(tmp);
+		rte_acl_free(tmp);
 		goto err;
 	}
 
 	tmp = rte_acl_find_existing(acx2_name);
 	if (tmp != acx2) {
 		printf("Line %i: Finding %s failed!\n", __LINE__, acx2_name);
-		if (tmp)
-			rte_acl_free(tmp);
+		rte_acl_free(tmp);
 		goto err;
 	}
 
diff --git a/lib/acl/rte_acl.h b/lib/acl/rte_acl.h
index f7f5f0870122..c33a688433b1 100644
--- a/lib/acl/rte_acl.h
+++ b/lib/acl/rte_acl.h
@@ -165,6 +165,7 @@ rte_acl_find_existing(const char *name);
  *
  * @param ctx
  *   ACL context to free
+ *   If NULL then, the function does nothing.
  */
 void
 rte_acl_free(struct rte_acl_ctx *ctx);
diff --git a/lib/table/rte_swx_table_wm.c b/lib/table/rte_swx_table_wm.c
index e260be106221..c9d42a855249 100644
--- a/lib/table/rte_swx_table_wm.c
+++ b/lib/table/rte_swx_table_wm.c
@@ -375,8 +375,7 @@ table_free(void *table)
 	if (!t)
 		return;
 
-	if (t->acl_ctx)
-		rte_acl_free(t->acl_ctx);
+	rte_acl_free(t->acl_ctx);
 	env_free(t, t->total_size);
 }
 
diff --git a/lib/table/rte_table_acl.c b/lib/table/rte_table_acl.c
index 14d54019f0bb..d15f03448796 100644
--- a/lib/table/rte_table_acl.c
+++ b/lib/table/rte_table_acl.c
@@ -148,8 +148,7 @@ rte_table_acl_free(void *table)
 	}
 
 	/* Free previously allocated resources */
-	if (acl->ctx != NULL)
-		rte_acl_free(acl->ctx);
+	rte_acl_free(acl->ctx);
 
 	rte_free(acl);
 
@@ -320,8 +319,7 @@ rte_table_acl_entry_add(
 	}
 
 	/* Commit changes */
-	if (acl->ctx != NULL)
-		rte_acl_free(acl->ctx);
+	rte_acl_free(acl->ctx);
 	acl->ctx = ctx;
 	*key_found = 0;
 	*entry_ptr = &acl->memory[free_pos * acl->entry_size];
@@ -400,8 +398,7 @@ rte_table_acl_entry_delete(
 	}
 
 	/* Commit changes */
-	if (acl->ctx != NULL)
-		rte_acl_free(acl->ctx);
+	rte_acl_free(acl->ctx);
 
 	acl->ctx = ctx;
 	*key_found = 1;
@@ -577,8 +574,7 @@ rte_table_acl_entry_add_bulk(
 	}
 
 	/* Commit changes */
-	if (acl->ctx != NULL)
-		rte_acl_free(acl->ctx);
+	rte_acl_free(acl->ctx);
 	acl->ctx = ctx;
 
 	for (i = 0; i < n_keys; i++) {
@@ -696,8 +692,7 @@ rte_table_acl_entry_delete_bulk(
 	}
 
 	/* Commit changes */
-	if (acl->ctx != NULL)
-		rte_acl_free(acl->ctx);
+	rte_acl_free(acl->ctx);
 
 	acl->ctx = ctx;
 	for (i = 0; i < n_keys; i++) {
-- 
2.34.1


  parent reply	other threads:[~2022-02-20 18:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-19 23:43 [PATCH 0/3] more " Stephen Hemminger
2022-02-19 23:43 ` [PATCH 1/3] cocci/nullfree: add more functions Stephen Hemminger
2022-02-19 23:43 ` [PATCH 2/3] acl: remove unncessary null checks in calls to rte_acl_free() Stephen Hemminger
2022-02-19 23:43 ` [PATCH 3/3] lpm: remove unnecessary NULL checks Stephen Hemminger
2022-02-20  0:51 ` [PATCH v2 0/7] fix more unnecessary null checks Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 1/7] cocci/nullfree: add more functions Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 2/7] acl: remove unnecessary null checks Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 3/7] lpm: remove unnecessary NULL checks Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 4/7] lib: document existing free functions Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 5/7] test: remove unecessary NULL checks before free Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 6/7] fips_validation: remove unnecessary NULL check Stephen Hemminger
2022-02-20  0:51   ` [PATCH v2 7/7] event/sw: " Stephen Hemminger
2022-02-20  5:18 ` [PATCH 0/3] more unnecessary null checks Jerin Jacob
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 1/8] cocci/nullfree: add more functions Stephen Hemminger
2022-02-20 18:21   ` Stephen Hemminger [this message]
2022-02-20 18:21   ` [PATCH v3 3/8] lpm: remove unnecessary NULL checks Stephen Hemminger
2022-02-21  2:47     ` Ruifeng Wang
2022-02-21 15:51     ` Medvedkin, Vladimir
2022-02-20 18:21   ` [PATCH v3 4/8] lib: document existing free functions Stephen Hemminger
2022-02-27 20:48     ` Thomas Monjalon
2022-02-28  9:42       ` Bruce Richardson
2022-02-28 17:08         ` Stephen Hemminger
2022-06-22  9:23           ` Thomas Monjalon
2022-06-22 14:55             ` Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 5/8] test: remove unnecessary NULL checks before free Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 6/8] fips_validation: remove unnecessary NULL check Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 7/8] event/sw: " Stephen Hemminger
2022-02-20 18:21   ` [PATCH v3 8/8] pipeline: remove unnecessary checks for NULL pointer before free Stephen Hemminger
2022-06-22 20:52   ` [PATCH v4] lib: document existing free functions Stephen Hemminger
2022-06-23  0:37     ` fengchengwen
2022-06-24 12:35     ` David Marchand
2022-06-24 12:41   ` [PATCH v3 0/8] yet more unnecessary NULL checks David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220220182147.9750-3-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).