Subject: [PATCH net-next V3 01/15] tools: ynl-gen: allow noncontiguous enums

From: Saeed Mahameed <[email-masked]>
Date: Fri, 25 Apr 2025 14:47:54 -0700

From: Jiri Pirko <[email-masked]>

In case the enum has holes, instead of hard stop, avoid the policy value
checking and it to the code.

Signed-off-by: Jiri Pirko <[email-masked]>
---
 tools/net/ynl/pyynl/ynl_gen_c.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index 0d930c17f963..56d6aa162773 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -358,10 +358,10 @@ class TypeScalar(Type):
         if 'enum' in self.attr:
             enum = self.family.consts[self.attr['enum']]
             low, high = enum.value_range()
-            if 'min' not in self.checks:
+            if low and 'min' not in self.checks:
                 if low != 0 or self.type[0] == 's':
                     self.checks['min'] = low
-            if 'max' not in self.checks:
+            if high and 'max' not in self.checks:
                 self.checks['max'] = high
 
         if 'min' in self.checks and 'max' in self.checks:
@@ -862,7 +862,7 @@ class EnumSet(SpecEnumSet):
         high = max([x.value for x in self.entries.values()])
 
         if high - low + 1 != len(self.entries):
-            raise Exception("Can't get value range for a noncontiguous enum")
+            return None, None
 
         return low, high
 
-- 
2.49.0