Commit 4c6170d1 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

tools: ynl: default to treating enums as flags for mask generation

I was a bit too optimistic in commit bf51d277 ("tools: ynl: fix
get_mask utility routine"), not every mask we use is necessarily
coming from an enum of type "flags". We also allow flipping an
enum into flags on per-attribute basis. That's done by
the 'enum-as-flags' property of an attribute.

Restore this functionality, it's not currently used by any in-tree
family.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a504d246
...@@ -90,8 +90,8 @@ class SpecEnumEntry(SpecElement): ...@@ -90,8 +90,8 @@ class SpecEnumEntry(SpecElement):
def raw_value(self): def raw_value(self):
return self.value return self.value
def user_value(self): def user_value(self, as_flags=None):
if self.enum_set['type'] == 'flags': if self.enum_set['type'] == 'flags' or as_flags:
return 1 << self.value return 1 << self.value
else: else:
return self.value return self.value
...@@ -136,10 +136,10 @@ class SpecEnumSet(SpecElement): ...@@ -136,10 +136,10 @@ class SpecEnumSet(SpecElement):
return True return True
return False return False
def get_mask(self): def get_mask(self, as_flags=None):
mask = 0 mask = 0
for e in self.entries.values(): for e in self.entries.values():
mask += e.user_value() mask += e.user_value(as_flags)
return mask return mask
......
...@@ -254,7 +254,8 @@ class TypeScalar(Type): ...@@ -254,7 +254,8 @@ class TypeScalar(Type):
def _attr_policy(self, policy): def _attr_policy(self, policy):
if 'flags-mask' in self.checks or self.is_bitfield: if 'flags-mask' in self.checks or self.is_bitfield:
if self.is_bitfield: if self.is_bitfield:
mask = self.family.consts[self.attr['enum']].get_mask() enum = self.family.consts[self.attr['enum']]
mask = enum.get_mask(as_flags=True)
else: else:
flags = self.family.consts[self.checks['flags-mask']] flags = self.family.consts[self.checks['flags-mask']]
flag_cnt = len(flags['entries']) flag_cnt = len(flags['entries'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment