Skip to content

Commit

Permalink
ynl: support enum-cnt-name attribute in legacy definitions
Browse files Browse the repository at this point in the history
This is similar to existing attr-cnt-name in the attributes
to allow changing the name of the 'count' enum entry.

Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20241204155549.641348-2-sdf@fomichev.me
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Stanislav Fomichev authored and Jakub Kicinski committed Dec 5, 2024
1 parent 302cc44 commit 523d3cc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Documentation/netlink/genetlink-c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ properties:
name-prefix:
description: For enum the prefix of the values, optional.
type: string
enum-cnt-name:
description: Name of the render-max counter enum entry.
type: string
# End genetlink-c

attribute-sets:
Expand Down
3 changes: 3 additions & 0 deletions Documentation/netlink/genetlink-legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ properties:
name-prefix:
description: For enum the prefix of the values, optional.
type: string
enum-cnt-name:
description: Name of the render-max counter enum entry.
type: string
# End genetlink-c
# Start genetlink-legacy
members:
Expand Down
4 changes: 3 additions & 1 deletion Documentation/userspace-api/netlink/c-code-gen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ If ``name-prefix`` is specified it replaces the ``$family-$enum``
portion of the entry name.

Boolean ``render-max`` controls creation of the max values
(which are enabled by default for attribute enums).
(which are enabled by default for attribute enums). These max
values are named ``__$pfx-MAX`` and ``$pfx-MAX``. The name
of the first value can be overridden via ``enum-cnt-name`` property.

Attributes
==========
Expand Down
8 changes: 6 additions & 2 deletions tools/net/ynl/ynl-gen-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ def __init__(self, family, yaml):
self.user_type = 'int'

self.value_pfx = yaml.get('name-prefix', f"{family.ident_name}-{yaml['name']}-")
self.enum_cnt_name = yaml.get('enum-cnt-name', None)

super().__init__(family, yaml)

Expand Down Expand Up @@ -2472,9 +2473,12 @@ def render_uapi(family, cw):
max_val = f' = {enum.get_mask()},'
cw.p(max_name + max_val)
else:
cnt_name = enum.enum_cnt_name
max_name = c_upper(name_pfx + 'max')
cw.p('__' + max_name + ',')
cw.p(max_name + ' = (__' + max_name + ' - 1)')
if not cnt_name:
cnt_name = '__' + name_pfx + 'max'
cw.p(c_upper(cnt_name) + ',')
cw.p(max_name + ' = (' + c_upper(cnt_name) + ' - 1)')
cw.block_end(line=';')
cw.nl()
elif const['type'] == 'const':
Expand Down

0 comments on commit 523d3cc

Please sign in to comment.