[PATCH net 2/4] tools: ynl-gen: use macro for binary min-len check

Asbjørn Sloth Tønnesen posted 4 patches 1 month ago
[PATCH net 2/4] tools: ynl-gen: use macro for binary min-len check
Posted by Asbjørn Sloth Tønnesen 1 month ago
This patch changes the generated min-len check for binary
attributes to use the NLA_POLICY_MIN_LEN() macro, and thereby
ensures that .validation_type is not left at NLA_VALIDATE_NONE.

This doesn't change any currently generated code, as it isn't
used in any specs currently used for generating code.

Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink")
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
---
 tools/net/ynl/pyynl/ynl_gen_c.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index ef032e17fec44..52f955ed84a7f 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -556,7 +556,7 @@ class TypeBinary(Type):
         elif 'exact-len' in self.checks:
             mem = 'NLA_POLICY_EXACT_LEN(' + self.get_limit_str('exact-len') + ')'
         elif 'min-len' in self.checks:
-            mem = '{ .len = ' + self.get_limit_str('min-len') + ', }'
+            mem = 'NLA_POLICY_MIN_LEN(' + self.get_limit_str('min-len') + ')'
         elif 'max-len' in self.checks:
             mem = 'NLA_POLICY_MAX_LEN(' + self.get_limit_str('max-len') + ')'
 
-- 
2.50.1

Re: [PATCH net 2/4] tools: ynl-gen: use macro for binary min-len check
Posted by Jakub Kicinski 1 month ago
On Mon,  1 Sep 2025 14:50:21 +0000 Asbjørn Sloth Tønnesen wrote:
> This patch changes the generated min-len check for binary
> attributes to use the NLA_POLICY_MIN_LEN() macro, and thereby
> ensures that .validation_type is not left at NLA_VALIDATE_NONE.

Please test this well and include the results in the commit message.
I'm pretty sure it's fine as is.
Re: [PATCH net 2/4] tools: ynl-gen: use macro for binary min-len check
Posted by Asbjørn Sloth Tønnesen 1 month ago
Thank you for the quick reviews.

On 9/1/25 6:52 PM, Jakub Kicinski wrote:
> On Mon,  1 Sep 2025 14:50:21 +0000 Asbjørn Sloth Tønnesen wrote:
>> This patch changes the generated min-len check for binary
>> attributes to use the NLA_POLICY_MIN_LEN() macro, and thereby
>> ensures that .validation_type is not left at NLA_VALIDATE_NONE.
> 
> Please test this well and include the results in the commit message.
> I'm pretty sure it's fine as is.

You are right, because .type is unset, then .validation_type doesn't matter.

Sorry, I didn't do enough testing for the fixes, I had looked at the NLA_BINARY
case in validate_nla(), not NLA_UNSPEC.

Will re-post for net-next without fixes, and a new commit message.