From: Anton Danilov <littlesmilingcloud@gmail.com>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>,
Thorsten Leemhuis <linux@leemhuis.info>,
Chuck Lever <chuck.lever@oracle.com>,
Jakub Kicinski <kuba@kernel.org>,
Donald Hunter <donald.hunter@gmail.com>,
Paolo Abeni <pabeni@redhat.com>,
"Remy D. Farley" <one-d-wide@protonmail.com>,
Rachel Menge <rachelmenge@linux.microsoft.com>,
netdev@vger.kernel.org
Subject: [PATCH 6.12.y 1/4] tools: ynl-gen: use names of constants in generated limits
Date: Sat, 10 Oct 2026 06:51:13 +0300 [thread overview]
Message-ID: <20261010035116.578385-2-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20261010035116.578385-1-littlesmilingcloud@gmail.com>
From: Jakub Kicinski <kuba@kernel.org>
commit bcbbfaa2612d7d0e9c3eafade5f6e93c3672f34f upstream.
YNL specs can use string expressions for limits, like s32-min
or u16-max. We convert all of those into their numeric values
when generating the code, which isn't always helpful. Try to
retain the string representations in the output. Any sort of
calculations still need the integers.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Joe Damato <jdamato@fastly.com>
Link: https://patch.msgid.link/20241010151248.2049755-1-kuba@kernel.org
[pabeni@redhat.com: regenerated netdev-genl-gen.c]
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
[ Anton: 6.12.y has the older TypeBinary._attr_policy(), switch its
get_limit() calls to get_limit_str() there. Drop the
netdev_a_napi_defer_hard_irqs_range hunk from netdev-genl-gen.c,
that range does not exist in 6.12.y. The file now matches what
ynl-gen-c.py generates. ]
Assisted-by: LLM
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
net/core/netdev-genl-gen.c | 4 ++--
tools/net/ynl/ynl-gen-c.py | 36 +++++++++++++++++++++++-------------
2 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/net/core/netdev-genl-gen.c b/net/core/netdev-genl-gen.c
index 8614988fc67b..b54f5948555f 100644
--- a/net/core/netdev-genl-gen.c
+++ b/net/core/netdev-genl-gen.c
@@ -14,12 +14,12 @@
/* Integer value ranges */
static const struct netlink_range_validation netdev_a_page_pool_id_range = {
.min = 1ULL,
- .max = 4294967295ULL,
+ .max = U32_MAX,
};
static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = {
.min = 1ULL,
- .max = 2147483647ULL,
+ .max = S32_MAX,
};
/* Common nested types */
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index c78f1c1bca75..00c05791a669 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -80,11 +80,21 @@ class Type(SpecAttr):
value = self.checks.get(limit, default)
if value is None:
return value
- elif value in self.family.consts:
+ if isinstance(value, int):
+ return value
+ if value in self.family.consts:
+ raise Exception("Resolving family constants not implemented, yet")
+ return limit_to_number(value)
+
+ def get_limit_str(self, limit, default=None, suffix=''):
+ value = self.checks.get(limit, default)
+ if value is None:
+ return ''
+ if isinstance(value, int):
+ return str(value) + suffix
+ if value in self.family.consts:
return c_upper(f"{self.family['name']}-{value}")
- if not isinstance(value, int):
- value = limit_to_number(value)
- return value
+ return c_upper(value)
def resolve(self):
if 'name-prefix' in self.attr:
@@ -358,11 +368,11 @@ class TypeScalar(Type):
elif 'full-range' in self.checks:
return f"NLA_POLICY_FULL_RANGE({policy}, &{c_lower(self.enum_name)}_range)"
elif 'range' in self.checks:
- return f"NLA_POLICY_RANGE({policy}, {self.get_limit('min')}, {self.get_limit('max')})"
+ return f"NLA_POLICY_RANGE({policy}, {self.get_limit_str('min')}, {self.get_limit_str('max')})"
elif 'min' in self.checks:
- return f"NLA_POLICY_MIN({policy}, {self.get_limit('min')})"
+ return f"NLA_POLICY_MIN({policy}, {self.get_limit_str('min')})"
elif 'max' in self.checks:
- return f"NLA_POLICY_MAX({policy}, {self.get_limit('max')})"
+ return f"NLA_POLICY_MAX({policy}, {self.get_limit_str('max')})"
return super()._attr_policy(policy)
def _attr_typol(self):
@@ -413,11 +423,11 @@ class TypeString(Type):
def _attr_policy(self, policy):
if 'exact-len' in self.checks:
- mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')'
+ mem = 'NLA_POLICY_EXACT_LEN(' + self.get_limit_str('exact-len') + ')'
else:
mem = '{ .type = ' + policy
if 'max-len' in self.checks:
- mem += ', .len = ' + str(self.get_limit('max-len'))
+ mem += ', .len = ' + self.get_limit_str('max-len')
mem += ', }'
return mem
@@ -465,11 +475,11 @@ class TypeBinary(Type):
def _attr_policy(self, policy):
if 'exact-len' in self.checks:
- mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')'
+ mem = 'NLA_POLICY_EXACT_LEN(' + self.get_limit_str('exact-len') + ')'
else:
mem = '{ '
if len(self.checks) == 1 and 'min-len' in self.checks:
- mem += '.len = ' + str(self.get_limit('min-len'))
+ mem += '.len = ' + self.get_limit_str('min-len')
elif len(self.checks) == 0:
mem += '.type = NLA_BINARY'
else:
@@ -2161,9 +2171,9 @@ def print_kernel_policy_ranges(family, cw):
cw.block_start(line=f'static const struct netlink_range_validation{sign} {c_lower(attr.enum_name)}_range =')
members = []
if 'min' in attr.checks:
- members.append(('min', str(attr.get_limit('min')) + suffix))
+ members.append(('min', attr.get_limit_str('min', suffix=suffix)))
if 'max' in attr.checks:
- members.append(('max', str(attr.get_limit('max')) + suffix))
+ members.append(('max', attr.get_limit_str('max', suffix=suffix)))
cw.write_struct_init(members)
cw.block_end(line=';')
cw.nl()
--
2.47.3
next prev parent reply other threads:[~2026-10-10 3:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2026060807-egging-prune-a3ae@gregkh>
2026-10-10 3:51 ` [PATCH 6.12.y 0/4] tools: ynl: fix spec validation in 6.12.y Anton Danilov
2026-10-10 3:51 ` Anton Danilov [this message]
2026-10-10 3:51 ` [PATCH 6.12.y 2/4] tools: ynl-gen: support limits using definitions Anton Danilov
2026-10-10 3:51 ` [PATCH 6.12.y 3/4] tools: ynl: add scope qualifier for definitions Anton Danilov
2026-10-10 3:51 ` [PATCH 6.12.y 4/4] doc/netlink: netlink-raw: Add max check Anton Danilov
2026-10-11 16:48 ` [PATCH 6.12.y 0/4] tools: ynl: fix spec validation in 6.12.y Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261010035116.578385-2-littlesmilingcloud@gmail.com \
--to=littlesmilingcloud@gmail.com \
--cc=chuck.lever@oracle.com \
--cc=donald.hunter@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=kuba@kernel.org \
--cc=linux@leemhuis.info \
--cc=netdev@vger.kernel.org \
--cc=one-d-wide@protonmail.com \
--cc=pabeni@redhat.com \
--cc=rachelmenge@linux.microsoft.com \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox