Skip to content

Commit fa29d46

Browse files
committed
Merge branch 'tools-ynl-gen-fix-parse-multi-attr-enum-attribute'
Arkadiusz Kubalewski says: ==================== tools: ynl-gen: fix parse multi-attr enum attribute Fix the issues with parsing enums in ynl.py script. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents d4a7ce6 + df15c15 commit fa29d46

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: tools/net/ynl/lib/ynl.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -417,28 +417,27 @@ def _add_attr(self, space, name, value):
417417
pad = b'\x00' * ((4 - len(attr_payload) % 4) % 4)
418418
return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_payload + pad
419419

420-
def _decode_enum(self, rsp, attr_spec):
421-
raw = rsp[attr_spec['name']]
420+
def _decode_enum(self, raw, attr_spec):
422421
enum = self.consts[attr_spec['enum']]
423-
i = attr_spec.get('value-start', 0)
424422
if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
423+
i = 0
425424
value = set()
426425
while raw:
427426
if raw & 1:
428427
value.add(enum.entries_by_val[i].name)
429428
raw >>= 1
430429
i += 1
431430
else:
432-
value = enum.entries_by_val[raw - i].name
433-
rsp[attr_spec['name']] = value
431+
value = enum.entries_by_val[raw].name
432+
return value
434433

435434
def _decode_binary(self, attr, attr_spec):
436435
if attr_spec.struct_name:
437436
members = self.consts[attr_spec.struct_name]
438437
decoded = attr.as_struct(members)
439438
for m in members:
440439
if m.enum:
441-
self._decode_enum(decoded, m)
440+
decoded[m.name] = self._decode_enum(decoded[m.name], m)
442441
elif attr_spec.sub_type:
443442
decoded = attr.as_c_array(attr_spec.sub_type)
444443
else:
@@ -466,15 +465,16 @@ def _decode(self, attrs, space):
466465
else:
467466
raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}')
468467

468+
if 'enum' in attr_spec:
469+
decoded = self._decode_enum(decoded, attr_spec)
470+
469471
if not attr_spec.is_multi:
470472
rsp[attr_spec['name']] = decoded
471473
elif attr_spec.name in rsp:
472474
rsp[attr_spec.name].append(decoded)
473475
else:
474476
rsp[attr_spec.name] = [decoded]
475477

476-
if 'enum' in attr_spec:
477-
self._decode_enum(rsp, attr_spec)
478478
return rsp
479479

480480
def _decode_extack_path(self, attrs, attr_set, offset, target):

0 commit comments

Comments
 (0)