2023-06-13 23:23:56

by Kubalewski, Arkadiusz

[permalink] [raw]
Subject: [PATCH net-next] tools: ynl-gen: fix NLA_POLICY_MAX on enums with value

Policy defines max as length of enum list, if enum attribute is
defined with a value, generated netlink policy max value is wrong.
Calculate proper max value for policy where enums that are given
explicit value.

Signed-off-by: Arkadiusz Kubalewski <[email protected]>
---
tools/net/ynl/ynl-gen-c.py | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 4c12c6f8968e..9adcd785db0b 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -279,7 +279,16 @@ class TypeScalar(Type):
elif 'enum' in self.attr:
enum = self.family.consts[self.attr['enum']]
cnt = len(enum['entries'])
- return f"NLA_POLICY_MAX({policy}, {cnt - 1})"
+ values = [0] * cnt
+ for i in range(cnt):
+ if 'value' in enum['entries'][i]:
+ values[i] = enum['entries'][i]['value']
+ else:
+ if i == 0:
+ values[i] = 0;
+ else:
+ values[i] = values[i - 1] + 1
+ return f"NLA_POLICY_MAX({policy}, {max(values)})"
return super()._attr_policy(policy)

def _attr_typol(self):
--
2.37.3