* [PATCH net-next] tools: ynl: default to treating enums as flags for mask generation
@ 2023-03-24 19:03 Jakub Kicinski
2023-03-27 8:00 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Kicinski @ 2023-03-24 19:03 UTC (permalink / raw)
To: davem; +Cc: netdev, edumazet, pabeni, Jakub Kicinski
I was a bit too optimistic in commit bf51d27704c9 ("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>
---
tools/net/ynl/lib/nlspec.py | 8 ++++----
tools/net/ynl/ynl-gen-c.py | 3 ++-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index d04450c2a44a..dba70100124a 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -90,8 +90,8 @@ jsonschema = None
def raw_value(self):
return self.value
- def user_value(self):
- if self.enum_set['type'] == 'flags':
+ def user_value(self, as_flags=None):
+ if self.enum_set['type'] == 'flags' or as_flags:
return 1 << self.value
else:
return self.value
@@ -136,10 +136,10 @@ jsonschema = None
return True
return False
- def get_mask(self):
+ def get_mask(self, as_flags=None):
mask = 0
for e in self.entries.values():
- mask += e.user_value()
+ mask += e.user_value(as_flags)
return mask
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 972b87c7aaaf..cc2f8c945340 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -254,7 +254,8 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
def _attr_policy(self, policy):
if 'flags-mask' in self.checks or 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:
flags = self.family.consts[self.checks['flags-mask']]
flag_cnt = len(flags['entries'])
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] tools: ynl: default to treating enums as flags for mask generation
2023-03-24 19:03 [PATCH net-next] tools: ynl: default to treating enums as flags for mask generation Jakub Kicinski
@ 2023-03-27 8:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-27 8:00 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni
Hello:
This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft•net>:
On Fri, 24 Mar 2023 12:03:56 -0700 you wrote:
> I was a bit too optimistic in commit bf51d27704c9 ("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.
>
> [...]
Here is the summary with links:
- [net-next] tools: ynl: default to treating enums as flags for mask generation
https://git.kernel.org/netdev/net-next/c/4c6170d1ae2c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-27 8:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-24 19:03 [PATCH net-next] tools: ynl: default to treating enums as flags for mask generation Jakub Kicinski
2023-03-27 8:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox