Skip to content

Commit

Permalink
tools: ynl: fix render-max for flags definition
Browse files Browse the repository at this point in the history
Properly manage render-max property for flags definition type
introducing mask value and setting it to (last_element << 1) - 1
instead of adding max value set to last_element + 1

Fixes: be5bea1 ("net: add basic C code generators for Netlink")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Lorenzo Bianconi authored and Jakub Kicinski committed Mar 11, 2023
1 parent 7e4f8a0 commit 8f76a4f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tools/net/ynl/ynl-gen-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1931,9 +1931,14 @@ def render_uapi(family, cw):

if const.get('render-max', False):
cw.nl()
max_name = c_upper(name_pfx + 'max')
cw.p('__' + max_name + ',')
cw.p(max_name + ' = (__' + max_name + ' - 1)')
if const['type'] == 'flags':
max_name = c_upper(name_pfx + 'mask')
max_val = f' = {enum.get_mask()},'
cw.p(max_name + max_val)
else:
max_name = c_upper(name_pfx + 'max')
cw.p('__' + max_name + ',')
cw.p(max_name + ' = (__' + max_name + ' - 1)')
cw.block_end(line=';')
cw.nl()
elif const['type'] == 'const':
Expand Down

0 comments on commit 8f76a4f

Please sign in to comment.