Skip to contentSkip to conversation

tools: ynl-gen: don't output external constants

PATCH Applied Jakub Kicinski 2 participants 3 messages Feb 3, 2025 – Feb 6, 2025

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/2 tools: ynl-gen: don't output external constants

A definition with a "header" property is an "external" definition for C code, as in it is defined already in another C header file. Other languages will need the exact value but C codegen should not recreate it. So don't output those definitions in the uAPI header.

---
CC: [email protected]
CC: [email protected]

---
 tools/net/ynl/pyynl/ynl_gen_c.py | 3 +++
 1 file changed, 3 insertions(+)
tools/net/ynl/pyynl/ynl_gen_c.py +3 -0
index c2eabc90dce8..aa08b8b1463d 100755
@@ -2549,6 +2549,9 @@ _C_KW = {
 
     defines = []
     for const in family['definitions']:
+        if const.get('header'):
+            continue
+
         if const['type'] != 'const':
             cw.writes_defines(defines)
             defines = []
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH 2/2 tools: ynl-gen: support limits using definitions

Support using defines / constants in integer checks. Carolina will need this for rate API extensions.

---
CC: [email protected]
CC: [email protected]

---
 Documentation/netlink/genetlink-c.yaml      | 5 +++--
 Documentation/netlink/genetlink-legacy.yaml | 5 +++--
 Documentation/netlink/genetlink.yaml        | 5 +++--
 tools/net/ynl/pyynl/ynl_gen_c.py            | 5 ++++-
 4 files changed, 13 insertions(+), 7 deletions(-)
Documentation/netlink/genetlink-c.yaml +3 -2
index 9660ffb1ed6a..44f2226160ca 100644
@@ -14,9 +14,10 @@ $schema: https://json-schema.org/draft-07/schema
     pattern: ^[0-9A-Za-z_-]+( - 1)?$
     minimum: 0
   len-or-limit:
-    # literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
+    # literal int, const name, or limit based on fixed-width type
+    # e.g. u8-min, u16-max, etc.
     type: [ string, integer ]
-    pattern: ^[su](8|16|32|64)-(min|max)$
+    pattern: ^[0-9A-Za-z_-]+$
     minimum: 0
 
 # Schema for specs
Documentation/netlink/genetlink-legacy.yaml +3 -2
index 16380e12cabe..ed64acf1bef7 100644
@@ -14,9 +14,10 @@ $schema: https://json-schema.org/draft-07/schema
     pattern: ^[0-9A-Za-z_-]+( - 1)?$
     minimum: 0
   len-or-limit:
-    # literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
+    # literal int, const name, or limit based on fixed-width type
+    # e.g. u8-min, u16-max, etc.
     type: [ string, integer ]
-    pattern: ^[su](8|16|32|64)-(min|max)$
+    pattern: ^[0-9A-Za-z_-]+$
     minimum: 0
 
 # Schema for specs
Documentation/netlink/genetlink.yaml +3 -2
index b036227b46f1..e43e50dba2e4 100644
@@ -14,9 +14,10 @@ $schema: https://json-schema.org/draft-07/schema
     pattern: ^[0-9A-Za-z_-]+( - 1)?$
     minimum: 0
   len-or-limit:
-    # literal int or limit based on fixed-width type e.g. u8-min, u16-max, etc.
+    # literal int, const name, or limit based on fixed-width type
+    # e.g. u8-min, u16-max, etc.
     type: [ string, integer ]
-    pattern: ^[su](8|16|32|64)-(min|max)$
+    pattern: ^[0-9A-Za-z_-]+$
     minimum: 0
 
 # Schema for specs
tools/net/ynl/pyynl/ynl_gen_c.py +4 -1
index aa08b8b1463d..b22082fd660e 100755
@@ -100,7 +100,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
         if isinstance(value, int):
             return value
         if value in self.family.consts:
-            raise Exception("Resolving family constants not implemented, yet")
+            return self.family.consts[value]["value"]
         return limit_to_number(value)
 
     def get_limit_str(self, limit, default=None, suffix=''):
@@ -110,6 +110,9 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
         if isinstance(value, int):
             return str(value) + suffix
         if value in self.family.consts:
+            const = self.family.consts[value]
+            if const.get('header'):
+                return c_upper(value)
             return c_upper(f"{self.family['name']}-{value}")
         return c_upper(value)
 
Signature · 1 line
2.48.1
#2 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Mon, 3 Feb 2025 13:55:09 -0800 you wrote:

A definition with a "header" property is an "external" definition for C code, as in it is defined already in another C header file. Other languages will need the exact value but C codegen should not recreate it. So don't output those definitions in the uAPI header.

[...]

Here is the summary with links:
- [net-next,1/2] tools: ynl-gen: don't output external constants

    https://git.kernel.org/netdev/net-next/c/7e8b24e24ac4
  - [net-next,2/2] tools: ynl-gen: support limits using definitions
    https://git.kernel.org/netdev/net-next/c/fa796178e5eb

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html