diff mbox series

[ovs-dev,1/3] tests: classifier: Fix the rule number check during trie verification.

Message ID 20250516212521.733714-2-i.maximets@ovn.org
State Accepted
Commit 9234b9b40f8a349e753315869529d635a464cedf
Headers show
Series classifier: Fix crash while setting flow table prefixes. | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Ilya Maximets May 16, 2025, 9:25 p.m. UTC
Same rule can be in multiple prefix trees and so it is possible that
the total number of rules in all trees exceeds the total number of
rules in the classifier.  But the number of rules in a single prefix
tree still can't exceed the total number of rules in the classifier.
Move the check accordingly.

Note: checkpatch complains about usage of the assert(), but it is
everywhere in this file and so, not changing in just this one place.

Fixes: f358a2cb2e54 ("lib/classifier: RCUify prefix trie code.")
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 tests/test-classifier.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Eelco Chaudron May 21, 2025, 7:08 p.m. UTC | #1
On 16 May 2025, at 23:25, Ilya Maximets wrote:

> Same rule can be in multiple prefix trees and so it is possible that
> the total number of rules in all trees exceeds the total number of
> rules in the classifier.  But the number of rules in a single prefix
> tree still can't exceed the total number of rules in the classifier.
> Move the check accordingly.
>
> Note: checkpatch complains about usage of the assert(), but it is
> everywhere in this file and so, not changing in just this one place.
>
> Fixes: f358a2cb2e54 ("lib/classifier: RCUify prefix trie code.")
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>

The change looks good to me.

Acked-by: Eelco Chaudron <echaudro@redhat.com>
diff mbox series

Patch

diff --git a/tests/test-classifier.c b/tests/test-classifier.c
index 2c1604a01..ee022ba1e 100644
--- a/tests/test-classifier.c
+++ b/tests/test-classifier.c
@@ -509,15 +509,15 @@  static void
 verify_tries(struct classifier *cls)
     OVS_NO_THREAD_SAFETY_ANALYSIS
 {
-    unsigned int n_rules = 0;
+    unsigned int n_rules;
     int i;
 
     for (i = 0; i < cls->n_tries; i++) {
         const struct mf_field * cls_field
             = ovsrcu_get(struct mf_field *, &cls->tries[i].field);
-        n_rules += trie_verify(&cls->tries[i].root, 0, cls_field->n_bits);
+        n_rules = trie_verify(&cls->tries[i].root, 0, cls_field->n_bits);
+        assert(n_rules <= cls->n_rules);
     }
-    assert(n_rules <= cls->n_rules);
 }
 
 static void