summaryrefslogtreecommitdiffstats
path: root/tools/net
diff options
context:
space:
mode:
authorJiri Pirko <jiri@nvidia.com>2024-02-22 14:43:50 +0100
committerJakub Kicinski <kuba@kernel.org>2024-02-24 03:16:44 +0100
commitffe10a4546feaae085a269f6e99680b9eda7d5a6 (patch)
treef964cb3230db2565bef674b44728f11487237ded /tools/net
parenttools: ynl: allow user to specify flag attr with bool values (diff)
downloadlinux-ffe10a4546feaae085a269f6e99680b9eda7d5a6.tar.xz
linux-ffe10a4546feaae085a269f6e99680b9eda7d5a6.zip
tools: ynl: process all scalar types encoding in single elif statement
As a preparation to handle enums for scalar values, unify the processing of all scalar types in a single elif statement. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://lore.kernel.org/r/20240222134351.224704-3-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/net')
-rw-r--r--tools/net/ynl/lib/ynl.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 1c5c7662dc9a..e459a130170b 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -474,14 +474,14 @@ class YnlFamily(SpecFamily):
attr_payload = self._encode_struct(attr.struct_name, value)
else:
raise Exception(f'Unknown type for binary attribute, value: {value}')
- elif attr.is_auto_scalar:
+ elif attr['type'] in NlAttr.type_formats or attr.is_auto_scalar:
scalar = int(value)
- real_type = attr["type"][0] + ('32' if scalar.bit_length() <= 32 else '64')
- format = NlAttr.get_format(real_type, attr.byte_order)
- attr_payload = format.pack(int(value))
- elif attr['type'] in NlAttr.type_formats:
- format = NlAttr.get_format(attr['type'], attr.byte_order)
- attr_payload = format.pack(int(value))
+ if attr.is_auto_scalar:
+ attr_type = attr["type"][0] + ('32' if scalar.bit_length() <= 32 else '64')
+ else:
+ attr_type = attr["type"]
+ format = NlAttr.get_format(attr_type, attr.byte_order)
+ attr_payload = format.pack(scalar)
elif attr['type'] in "bitfield32":
attr_payload = struct.pack("II", int(value["value"]), int(value["selector"]))
elif attr['type'] == 'sub-message':