tools: ynl-gen: don't output external constants
Subsystems (3)
Jakub Kicinski
maintainerPATCH 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
@@ -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
Jakub Kicinski
maintainerPATCH 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
@@ -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
@@ -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
@@ -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
@@ -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
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.
Signed-off-by Jakub Kicinski <[email protected]>[...]
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