[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230613231709.150622-2-arkadiusz.kubalewski@intel.com>
Date: Wed, 14 Jun 2023 01:17:08 +0200
From: Arkadiusz Kubalewski <arkadiusz.kubalewski@...el.com>
To: netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
kuba@...nel.org, davem@...emloft.net, pabeni@...hat.com,
edumazet@...gle.com, chuck.lever@...cle.com
Cc: Arkadiusz Kubalewski <arkadiusz.kubalewski@...el.com>
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 <arkadiusz.kubalewski@...el.com>
---
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
Powered by blists - more mailing lists