]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ynl: support enum-cnt-name attribute in legacy definitions
authorStanislav Fomichev <sdf@fomichev.me>
Wed, 4 Dec 2024 15:55:42 +0000 (07:55 -0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 5 Dec 2024 20:03:03 +0000 (12:03 -0800)
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>
Documentation/netlink/genetlink-c.yaml
Documentation/netlink/genetlink-legacy.yaml
Documentation/userspace-api/netlink/c-code-gen.rst
tools/net/ynl/ynl-gen-c.py

index 4f803eaac6d8ba20b5288e55bb696d5df74407e3..9660ffb1ed6ac293aa4156179173dc97ff5926b7 100644 (file)
@@ -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:
index 8db0e22fa72c7a3cd09620930f367ac1e5a7aa70..16380e12cabe710b823cf830941e42570d5313de 100644 (file)
@@ -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:
index 89de42c13350285656893415ba734de79ee93b94..46415e6d646d215cee156bdfb0b2f86b2bd8586a 100644 (file)
@@ -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
 ==========
index d8201c4b1520995e8c36f1f0fd22be55f546f80c..bfe95826ae3e48f161a9fcc45710b7e75faf9451 100755 (executable)
@@ -801,6 +801,7 @@ class EnumSet(SpecEnumSet):
             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)
 
@@ -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':