diff mbox series

[net-next,1/7] ynl: support attr-cnt-name attribute in legacy definitions

Message ID 20241113181023.2030098-2-sdf@fomichev.me (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ethtool: generate uapi header from the spec | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl fail Generated files up to date; build failed; build has 3 warnings/errors; GEN HAS DIFF 2 files changed, 75 insertions(+), 10 deletions(-);
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success Errors and warnings before: 0 (+0) this patch: 0 (+0)
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 3
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 30 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Stanislav Fomichev Nov. 13, 2024, 6:10 p.m. UTC
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>
---
 Documentation/netlink/genetlink-legacy.yaml | 3 +++
 tools/net/ynl/ynl-gen-c.py                  | 8 ++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

Comments

Jakub Kicinski Nov. 13, 2024, 8:03 p.m. UTC | #1
On Wed, 13 Nov 2024 10:10:17 -0800 Stanislav Fomichev wrote:
> This is similar to existing attr-cnt-name in the attributes
> to allow changing the name of the 'count' enum entry.

why attr- ? we have similar attrs for cmd and we use cmd- as a prefix,
so I'd just use enum-

I'd put it into genetlink-c level (you'll have to copy/paste into two
specs), all the non-functional stuff related to C code gen is in the
genetlink-c spec

Please double check Documentation doesn't need extending
Stanislav Fomichev Nov. 13, 2024, 11:39 p.m. UTC | #2
On 11/13, Jakub Kicinski wrote:
> On Wed, 13 Nov 2024 10:10:17 -0800 Stanislav Fomichev wrote:
> > This is similar to existing attr-cnt-name in the attributes
> > to allow changing the name of the 'count' enum entry.
> 
> why attr- ? we have similar attrs for cmd and we use cmd- as a prefix,
> so I'd just use enum-

Mostly because I don't have too much state on the spec side :-[ Did a
copy-paste from the attributes... Will switch to enum.
 
> I'd put it into genetlink-c level (you'll have to copy/paste into two
> specs), all the non-functional stuff related to C code gen is in the
> genetlink-c spec
> 
> Please double check Documentation doesn't need extending

Will do, thanks for the pointers! The doc is definitely missing.
diff mbox series

Patch

diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml
index 8db0e22fa72c..83f874ae7198 100644
--- a/Documentation/netlink/genetlink-legacy.yaml
+++ b/Documentation/netlink/genetlink-legacy.yaml
@@ -119,6 +119,9 @@  additionalProperties: False
           type: string
         # End genetlink-c
         # Start genetlink-legacy
+        attr-cnt-name:
+          description: Name of the render-max counter enum entry.
+          type: string
         members:
           description: List of struct members. Only scalars and strings members allowed.
           type: array
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index c48b69071111..210972b4796a 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -798,6 +798,7 @@  from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
             self.user_type = 'int'
 
         self.value_pfx = yaml.get('name-prefix', f"{family.ident_name}-{yaml['name']}-")
+        self.attr_cnt_name = yaml.get('attr-cnt-name', None)
 
         super().__init__(family, yaml)
 
@@ -2468,9 +2469,12 @@  _C_KW = {
                     max_val = f' = {enum.get_mask()},'
                     cw.p(max_name + max_val)
                 else:
+                    cnt_name = enum.attr_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 = '__' + c_upper(name_pfx + 'max')
+                    cw.p(cnt_name + ',')
+                    cw.p(max_name + ' = (' + cnt_name + ' - 1)')
             cw.block_end(line=';')
             cw.nl()
         elif const['type'] == 'const':