[v3,2/8] acl: remove unnecessary null checks

Message ID 20220220182147.9750-3-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series yet more unnecessary NULL checks |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Feb. 20, 2022, 6:21 p.m. UTC
  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(-)
  

Patch

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++) {