Skip to content

Commit

Permalink
tools: ynl-gen: fix enum index in _decode_enum(..)
Browse files Browse the repository at this point in the history
Remove wrong index adjustment, which is leftover from adding
support for sparse enums.
enum.entries_by_val() function shall not subtract the start-value, as
it is indexed with real enum value.

Fixes: c311aaa ("tools: ynl: fix enum-as-flags in the generic CLI")
Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://lore.kernel.org/r/20230725101642.267248-2-arkadiusz.kubalewski@intel.com
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Arkadiusz Kubalewski authored and Jakub Kicinski committed Jul 26, 2023
1 parent d4a7ce6 commit d7ddf5f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/net/ynl/lib/ynl.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,16 @@ def _add_attr(self, space, name, value):
def _decode_enum(self, rsp, attr_spec):
raw = rsp[attr_spec['name']]
enum = self.consts[attr_spec['enum']]
i = attr_spec.get('value-start', 0)
if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
i = 0
value = set()
while raw:
if raw & 1:
value.add(enum.entries_by_val[i].name)
raw >>= 1
i += 1
else:
value = enum.entries_by_val[raw - i].name
value = enum.entries_by_val[raw].name
rsp[attr_spec['name']] = value

def _decode_binary(self, attr, attr_spec):
Expand Down

0 comments on commit d7ddf5f

Please sign in to comment.