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: use names of constants in generated limits

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>

authored by

Jakub Kicinski and committed by
Paolo Abeni
bcbbfaa2 97802ffc

+26 -16
+3 -3
net/core/netdev-genl-gen.c
··· 14 14 /* Integer value ranges */ 15 15 static const struct netlink_range_validation netdev_a_page_pool_id_range = { 16 16 .min = 1ULL, 17 - .max = 4294967295ULL, 17 + .max = U32_MAX, 18 18 }; 19 19 20 20 static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = { 21 21 .min = 1ULL, 22 - .max = 2147483647ULL, 22 + .max = S32_MAX, 23 23 }; 24 24 25 25 static const struct netlink_range_validation netdev_a_napi_defer_hard_irqs_range = { 26 - .max = 2147483647ULL, 26 + .max = S32_MAX, 27 27 }; 28 28 29 29 /* Common nested types */
+23 -13
tools/net/ynl/ynl-gen-c.py
··· 80 80 value = self.checks.get(limit, default) 81 81 if value is None: 82 82 return value 83 - elif value in self.family.consts: 83 + if isinstance(value, int): 84 + return value 85 + if value in self.family.consts: 86 + raise Exception("Resolving family constants not implemented, yet") 87 + return limit_to_number(value) 88 + 89 + def get_limit_str(self, limit, default=None, suffix=''): 90 + value = self.checks.get(limit, default) 91 + if value is None: 92 + return '' 93 + if isinstance(value, int): 94 + return str(value) + suffix 95 + if value in self.family.consts: 84 96 return c_upper(f"{self.family['name']}-{value}") 85 - if not isinstance(value, int): 86 - value = limit_to_number(value) 87 - return value 97 + return c_upper(value) 88 98 89 99 def resolve(self): 90 100 if 'name-prefix' in self.attr: ··· 368 358 elif 'full-range' in self.checks: 369 359 return f"NLA_POLICY_FULL_RANGE({policy}, &{c_lower(self.enum_name)}_range)" 370 360 elif 'range' in self.checks: 371 - return f"NLA_POLICY_RANGE({policy}, {self.get_limit('min')}, {self.get_limit('max')})" 361 + return f"NLA_POLICY_RANGE({policy}, {self.get_limit_str('min')}, {self.get_limit_str('max')})" 372 362 elif 'min' in self.checks: 373 - return f"NLA_POLICY_MIN({policy}, {self.get_limit('min')})" 363 + return f"NLA_POLICY_MIN({policy}, {self.get_limit_str('min')})" 374 364 elif 'max' in self.checks: 375 - return f"NLA_POLICY_MAX({policy}, {self.get_limit('max')})" 365 + return f"NLA_POLICY_MAX({policy}, {self.get_limit_str('max')})" 376 366 return super()._attr_policy(policy) 377 367 378 368 def _attr_typol(self): ··· 423 413 424 414 def _attr_policy(self, policy): 425 415 if 'exact-len' in self.checks: 426 - mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')' 416 + mem = 'NLA_POLICY_EXACT_LEN(' + self.get_limit_str('exact-len') + ')' 427 417 else: 428 418 mem = '{ .type = ' + policy 429 419 if 'max-len' in self.checks: 430 - mem += ', .len = ' + str(self.get_limit('max-len')) 420 + mem += ', .len = ' + self.get_limit_str('max-len') 431 421 mem += ', }' 432 422 return mem 433 423 ··· 486 476 if len(self.checks) == 0: 487 477 mem = '{ .type = NLA_BINARY, }' 488 478 elif 'exact-len' in self.checks: 489 - mem = 'NLA_POLICY_EXACT_LEN(' + str(self.get_limit('exact-len')) + ')' 479 + mem = 'NLA_POLICY_EXACT_LEN(' + self.get_limit_str('exact-len') + ')' 490 480 elif 'min-len' in self.checks: 491 - mem = '{ .len = ' + str(self.get_limit('min-len')) + ', }' 481 + mem = '{ .len = ' + self.get_limit_str('min-len') + ', }' 492 482 493 483 return mem 494 484 ··· 2176 2166 cw.block_start(line=f'static const struct netlink_range_validation{sign} {c_lower(attr.enum_name)}_range =') 2177 2167 members = [] 2178 2168 if 'min' in attr.checks: 2179 - members.append(('min', str(attr.get_limit('min')) + suffix)) 2169 + members.append(('min', attr.get_limit_str('min', suffix=suffix))) 2180 2170 if 'max' in attr.checks: 2181 - members.append(('max', str(attr.get_limit('max')) + suffix)) 2171 + members.append(('max', attr.get_limit_str('max', suffix=suffix))) 2182 2172 cw.write_struct_init(members) 2183 2173 cw.block_end(line=';') 2184 2174 cw.nl()