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.

Merge branch 'tools-ynl-fix-errors-reported-by-ruff'

Matthieu Baerts says:

====================
tools: ynl: fix errors reported by Ruff

When looking at the YNL code to add a new feature, my text editor
automatically executed 'ruff check', and found out at least one
interesting error: one variable was used while not being defined.

I then decided to fix this error, and all the other ones reported by
Ruff. After this series, 'ruff check' reports no more errors with
version 0.12.12.
====================

Link: https://patch.msgid.link/20250909-net-next-ynl-ruff-v1-0-238c2bccdd99@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+25 -31
+6 -8
tools/net/ynl/pyynl/ethtool.py
··· 2 2 # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 3 3 4 4 import argparse 5 - import json 6 5 import pathlib 7 6 import pprint 8 7 import sys ··· 50 51 for spec in desc: 51 52 try: 52 53 field, name, tp = spec 53 - except: 54 + except ValueError: 54 55 field, name = spec 55 56 tp = 'int' 56 57 ··· 155 156 global args 156 157 args = parser.parse_args() 157 158 158 - script_abs_dir = os.path.dirname(os.path.abspath(sys.argv[0])) 159 159 spec = os.path.join(spec_dir(), 'ethtool.yaml') 160 160 schema = os.path.join(schema_dir(), 'genetlink-legacy.yaml') 161 161 ··· 253 255 reply = dumpit(ynl, args, 'channels-get') 254 256 print(f'Channel parameters for {args.device}:') 255 257 256 - print(f'Pre-set maximums:') 258 + print('Pre-set maximums:') 257 259 print_field(reply, 258 260 ('rx-max', 'RX'), 259 261 ('tx-max', 'TX'), 260 262 ('other-max', 'Other'), 261 263 ('combined-max', 'Combined')) 262 264 263 - print(f'Current hardware settings:') 265 + print('Current hardware settings:') 264 266 print_field(reply, 265 267 ('rx-count', 'RX'), 266 268 ('tx-count', 'TX'), ··· 274 276 275 277 print(f'Ring parameters for {args.device}:') 276 278 277 - print(f'Pre-set maximums:') 279 + print('Pre-set maximums:') 278 280 print_field(reply, 279 281 ('rx-max', 'RX'), 280 282 ('rx-mini-max', 'RX Mini'), 281 283 ('rx-jumbo-max', 'RX Jumbo'), 282 284 ('tx-max', 'TX')) 283 285 284 - print(f'Current hardware settings:') 286 + print('Current hardware settings:') 285 287 print_field(reply, 286 288 ('rx', 'RX'), 287 289 ('rx-mini', 'RX Mini'), ··· 296 298 return 297 299 298 300 if args.statistics: 299 - print(f'NIC statistics:') 301 + print('NIC statistics:') 300 302 301 303 # TODO: pass id? 302 304 strset = dumpit(ynl, args, 'strset-get')
+1 -1
tools/net/ynl/pyynl/lib/__init__.py
··· 8 8 9 9 __all__ = ["SpecAttr", "SpecAttrSet", "SpecEnumEntry", "SpecEnumSet", 10 10 "SpecFamily", "SpecOperation", "SpecSubMessage", "SpecSubMessageFormat", 11 - "YnlFamily", "Netlink", "NlError"] 11 + "YnlFamily", "Netlink", "NlError", "YnlDocGenerator"]
+1 -1
tools/net/ynl/pyynl/lib/nlspec.py
··· 501 501 return SpecStruct(self, elem) 502 502 503 503 def new_sub_message(self, elem): 504 - return SpecSubMessage(self, elem); 504 + return SpecSubMessage(self, elem) 505 505 506 506 def new_operation(self, elem, req_val, rsp_val): 507 507 return SpecOperation(self, elem, req_val, rsp_val)
+3 -4
tools/net/ynl/pyynl/lib/ynl.py
··· 9 9 import struct 10 10 from struct import Struct 11 11 import sys 12 - import yaml 13 12 import ipaddress 14 13 import uuid 15 14 import queue ··· 705 706 return attr.as_bin() 706 707 707 708 def _rsp_add(self, rsp, name, is_multi, decoded): 708 - if is_multi == None: 709 + if is_multi is None: 709 710 if name in rsp and type(rsp[name]) is not list: 710 711 rsp[name] = [rsp[name]] 711 712 is_multi = True ··· 738 739 decoded = {} 739 740 offset = 0 740 741 if msg_format.fixed_header: 741 - decoded.update(self._decode_struct(attr.raw, msg_format.fixed_header)); 742 + decoded.update(self._decode_struct(attr.raw, msg_format.fixed_header)) 742 743 offset = self._struct_size(msg_format.fixed_header) 743 744 if msg_format.attr_set: 744 745 if msg_format.attr_set in self.attr_sets: 745 746 subdict = self._decode(NlAttrs(attr.raw, offset), msg_format.attr_set) 746 747 decoded.update(subdict) 747 748 else: 748 - raise Exception(f"Unknown attribute-set '{attr_space}' when decoding '{attr_spec.name}'") 749 + raise Exception(f"Unknown attribute-set '{msg_format.attr_set}' when decoding '{attr_spec.name}'") 749 750 return decoded 750 751 751 752 def _decode(self, attrs, space, outer_attrs = None):
+14 -17
tools/net/ynl/pyynl/ynl_gen_c.py
··· 2 2 # SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 3 3 4 4 import argparse 5 - import collections 6 5 import filecmp 7 6 import pathlib 8 7 import os ··· 13 14 14 15 sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix()) 15 16 from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, SpecEnumEntry 16 - from lib import SpecSubMessage, SpecSubMessageFormat 17 + from lib import SpecSubMessage 17 18 18 19 19 20 def c_upper(name): ··· 397 398 if 'enum' in self.attr: 398 399 enum = self.family.consts[self.attr['enum']] 399 400 low, high = enum.value_range() 400 - if low == None and high == None: 401 + if low is None and high is None: 401 402 self.checks['sparse'] = True 402 403 else: 403 404 if 'min' not in self.checks: ··· 484 485 ri.cw.p(f"char *{self.c_name};") 485 486 486 487 def _attr_typol(self): 487 - typol = f'.type = YNL_PT_NUL_STR, ' 488 + typol = '.type = YNL_PT_NUL_STR, ' 488 489 if self.is_selector: 489 490 typol += '.is_selector = 1, ' 490 491 return typol ··· 538 539 ri.cw.p(f"void *{self.c_name};") 539 540 540 541 def _attr_typol(self): 541 - return f'.type = YNL_PT_BINARY,' 542 + return '.type = YNL_PT_BINARY,' 542 543 543 544 def _attr_policy(self, policy): 544 545 if len(self.checks) == 0: ··· 635 636 return "struct nla_bitfield32" 636 637 637 638 def _attr_typol(self): 638 - return f'.type = YNL_PT_BITFIELD32, ' 639 + return '.type = YNL_PT_BITFIELD32, ' 639 640 640 641 def _attr_policy(self, policy): 641 - if not 'enum' in self.attr: 642 + if 'enum' not in self.attr: 642 643 raise Exception('Enum required for bitfield32 attr') 643 644 enum = self.family.consts[self.attr['enum']] 644 645 mask = enum.get_mask(as_flags=True) ··· 908 909 else: 909 910 sel_var = f"{var}->{sel}" 910 911 get_lines = [f'if (!{sel_var})', 911 - f'return ynl_submsg_failed(yarg, "%s", "%s");' % 912 + 'return ynl_submsg_failed(yarg, "%s", "%s");' % 912 913 (self.name, self['selector']), 913 914 f"if ({self.nested_render_name}_parse(&parg, {sel_var}, attr))", 914 915 "return YNL_PARSE_CB_ERROR;"] ··· 1562 1563 if family.is_classic(): 1563 1564 self.fixed_hdr_len = f"sizeof(struct {c_lower(fixed_hdr)})" 1564 1565 else: 1565 - raise Exception(f"Per-op fixed header not supported, yet") 1566 + raise Exception("Per-op fixed header not supported, yet") 1566 1567 1567 1568 1568 1569 # 'do' and 'dump' response parsing is identical ··· 2098 2099 if ri.family.is_classic(): 2099 2100 iter_line = f"ynl_attr_for_each(attr, nlh, sizeof({struct.fixed_header}))" 2100 2101 else: 2101 - raise Exception(f"Per-op fixed header not supported, yet") 2102 + raise Exception("Per-op fixed header not supported, yet") 2102 2103 2103 2104 array_nests = set() 2104 2105 multi_attrs = set() ··· 2501 2502 2502 2503 def print_nlflags_set(ri, direction): 2503 2504 name = op_prefix(ri, direction) 2504 - ri.cw.write_func_prot(f'static inline void', f"{name}_set_nlflags", 2505 + ri.cw.write_func_prot('static inline void', f"{name}_set_nlflags", 2505 2506 [f"struct {name} *req", "__u16 nl_flags"]) 2506 2507 ri.cw.block_start() 2507 2508 ri.cw.p('req->_nlmsg_flags = nl_flags;') ··· 2532 2533 line = attr.presence_member(ri.ku_space, type_filter) 2533 2534 if line: 2534 2535 if not meta_started: 2535 - ri.cw.block_start(line=f"struct") 2536 + ri.cw.block_start(line="struct") 2536 2537 meta_started = True 2537 2538 ri.cw.p(line) 2538 2539 if meta_started: ··· 2696 2697 ri.cw.nl() 2697 2698 2698 2699 _free_type_members(ri, 'rsp', ri.struct['reply'], ref='obj.') 2699 - ri.cw.p(f'free(rsp);') 2700 + ri.cw.p('free(rsp);') 2700 2701 ri.cw.block_end() 2701 2702 ri.cw.block_end() 2702 2703 ri.cw.nl() ··· 2707 2708 ri.cw.block_start() 2708 2709 _free_type_members_iter(ri, ri.struct['reply']) 2709 2710 _free_type_members(ri, 'rsp', ri.struct['reply'], ref='obj.') 2710 - ri.cw.p(f'free(rsp);') 2711 + ri.cw.p('free(rsp);') 2711 2712 ri.cw.block_end() 2712 2713 ri.cw.nl() 2713 2714 ··· 2802 2803 cw.p('/* Sparse enums validation callbacks */') 2803 2804 first = False 2804 2805 2805 - sign = '' if attr.type[0] == 'u' else '_signed' 2806 - suffix = 'ULL' if attr.type[0] == 'u' else 'LL' 2807 2806 cw.write_func_prot('static int', f'{c_lower(attr.enum_name)}_validate', 2808 2807 ['const struct nlattr *attr', 'struct netlink_ext_ack *extack']) 2809 2808 cw.block_start() ··· 3321 3324 cw.block_start(f'{symbol} = ') 3322 3325 cw.p(f'.name\t\t= "{family.c_name}",') 3323 3326 if family.is_classic(): 3324 - cw.p(f'.is_classic\t= true,') 3327 + cw.p('.is_classic\t= true,') 3325 3328 cw.p(f'.classic_id\t= {family.get("protonum")},') 3326 3329 if family.is_classic(): 3327 3330 if family.fixed_header: