From 107df351c6f95ef15a045cde85697c0ee3b222b2 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 13 Jul 2021 08:48:11 +0300 Subject: [PATCH] tools: Add coccinelle script for hash compare functions NULL values Signed-off-by: Donatas Abraitis --- .../hash_compare_null_values_check.cocci | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tools/coccinelle/hash_compare_null_values_check.cocci diff --git a/tools/coccinelle/hash_compare_null_values_check.cocci b/tools/coccinelle/hash_compare_null_values_check.cocci new file mode 100644 index 000000000000..38649a228273 --- /dev/null +++ b/tools/coccinelle/hash_compare_null_values_check.cocci @@ -0,0 +1,20 @@ +// There is no need to test for null values in the hash compare +// function as that we are guaranteed to send in data in +// the hash compare functions. +@@ +identifier fn =~ "_hash_cmp"; +type T; +identifier p1; +identifier p2; +@@ + +?static +T fn(...) +{ +... +- if (p1 == NULL && p2 == NULL) +- return ...; +- if (p1 == NULL || p2 == NULL) +- return ...; +... +}