mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-05 01:54:09 +08:00
tools: ynl: default to treating enums as flags for mask generation
I was a bit too optimistic in commit bf51d27704
("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: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
a504d246d2
commit
4c6170d1ae
@ -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):
|
|||||||
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):
|
|||||||
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'])
|
||||||
|
Loading…
Reference in New Issue
Block a user