netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tools: ynl-gen: fix parse multi-attr enum attribute
@ 2023-07-11  9:53 Arkadiusz Kubalewski
  2023-07-12  3:59 ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Arkadiusz Kubalewski @ 2023-07-11  9:53 UTC (permalink / raw)
  To: netdev, linux-kernel, kuba, davem, pabeni, edumazet, chuck.lever
  Cc: Arkadiusz Kubalewski

When attribute is enum type and marked as multi-attr, the netlink respond
is not parsed, fails with stack trace:
File "/root/arek/linux-dpll/tools/net/ynl/lib/ynl.py", line 600, in dump
  return self._op(method, vals, dump=True)
File "/root/arek/linux-dpll/tools/net/ynl/lib/ynl.py", line 586, in _op
  rsp_msg = self._decode(gm.raw_attrs, op.attr_set.name)
File "/root/arek/linux-dpll/tools/net/ynl/lib/ynl.py", line 453, in _decode
  self._decode_enum(rsp, attr_spec)
File "/root/arek/linux-dpll/tools/net/ynl/lib/ynl.py", line 410, in _decode_enum
  value = enum.entries_by_val[raw - i].name
TypeError: unsupported operand type(s) for -: 'list' and 'int'
error: 1

Allow succesfull parse of multi-attr enums by decoding and assigning their
names into response in the _decode_enum(..) function.

Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
---
 tools/net/ynl/lib/ynl.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 3b343d6cbbc0..553d82dd6382 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -407,7 +407,14 @@ class YnlFamily(SpecFamily):
                 raw >>= 1
                 i += 1
         else:
-            value = enum.entries_by_val[raw - i].name
+            if attr_spec.is_multi:
+                for index in range(len(raw)):
+                    if (type(raw[index]) == int):
+                        enum_name = enum.entries_by_val[raw[index] - i].name
+                        rsp[attr_spec['name']][index] = enum_name
+                return
+            else:
+                value = enum.entries_by_val[raw - i].name
         rsp[attr_spec['name']] = value
 
     def _decode_binary(self, attr, attr_spec):
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-13  9:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-11  9:53 [PATCH net-next] tools: ynl-gen: fix parse multi-attr enum attribute Arkadiusz Kubalewski
2023-07-12  3:59 ` Jakub Kicinski
2023-07-12  9:47   ` Kubalewski, Arkadiusz
2023-07-12 16:24     ` Jakub Kicinski
2023-07-13  9:22       ` Kubalewski, Arkadiusz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).