Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools: ynl-gen: refactor check validation for TypeBinary

We only support a single check at a time for TypeBinary.
Refactor the code to cover 'exact-len' and make adding
new checks easier.

Link: https://lore.kernel.org/20241004063855.1a693dd1@kernel.org
Link: https://patch.msgid.link/20241007155311.1193382-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+15 -10
+15 -10
tools/net/ynl/ynl-gen-c.py
··· 464 464 return f'.type = YNL_PT_BINARY,' 465 465 466 466 def _attr_policy(self, policy): 467 - if 'exact-len' in self.checks: 468 - mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')' 467 + if len(self.checks) == 0: 468 + pass 469 + elif len(self.checks) == 1: 470 + check_name = list(self.checks)[0] 471 + if check_name not in {'exact-len', 'min-len'}: 472 + raise Exception('Unsupported check for binary type: ' + check_name) 469 473 else: 470 - mem = '{ ' 471 - if len(self.checks) == 1 and 'min-len' in self.checks: 472 - mem += '.len = ' + str(self.get_limit('min-len')) 473 - elif len(self.checks) == 0: 474 - mem += '.type = NLA_BINARY' 475 - else: 476 - raise Exception('One or more of binary type checks not implemented, yet') 477 - mem += ', }' 474 + raise Exception('More than one check for binary type not implemented, yet') 475 + 476 + if len(self.checks) == 0: 477 + mem = '{ .type = NLA_BINARY, }' 478 + elif 'exact-len' in self.checks: 479 + mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')' 480 + elif 'min-len' in self.checks: 481 + mem = '{ .len = ' + str(self.get_limit('min-len')) + ', }' 482 + 478 483 return mem 479 484 480 485 def attr_put(self, ri, var):