From ce40c6279a46dde35e25a6d31416e4e1ce519a18 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 13 Jul 2021 08:46:10 +0300 Subject: [PATCH 1/2] bgpd: Do not check for NULL values for vni_hash_cmp() 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. Signed-off-by: Donatas Abraitis --- bgpd/bgp_evpn.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index c99f539c7b..3d8c4e3ae6 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -111,11 +111,7 @@ static bool vni_hash_cmp(const void *p1, const void *p2) const struct bgpevpn *vpn1 = p1; const struct bgpevpn *vpn2 = p2; - if (!vpn1 && !vpn2) - return true; - if (!vpn1 || !vpn2) - return false; - return (vpn1->vni == vpn2->vni); + return vpn1->vni == vpn2->vni; } int vni_list_cmp(void *p1, void *p2) From 107df351c6f95ef15a045cde85697c0ee3b222b2 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 13 Jul 2021 08:48:11 +0300 Subject: [PATCH 2/2] 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 0000000000..38649a2282 --- /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 ...; +... +}