Skip to content

Commit 399c04c

Browse files
ulfalizergalak
authored andcommitted
scripts/dts: Remove unused variables and imports
Discovered with pylint3. Use the placeholder name '_' for unproblematic unused variables. It's what I'm used to, and pylint knows not to flag it. Also improve the naming a bit in devicetree.py. If a key/value is known to be a specific thing (like a node), then it's helpful to call it that instead of something generic like "value". Signed-off-by: Ulf Magnusson <[email protected]>
1 parent 95650fd commit 399c04c

File tree

6 files changed

+14
-22
lines changed

6 files changed

+14
-22
lines changed

scripts/dts/devicetree.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ def parse_file(fd, ignore_dts_version=False):
197197
continue
198198

199199
if line.startswith('/include/ '):
200-
tag, filename = line.split()
200+
_, filename = line.split()
201201
with open(filename.strip()[1:-1], "r") as new_fd:
202202
nodes.update(parse_file(new_fd, True))
203203
elif line == '/dts-v1/;':
204204
has_v1_tag = True
205205
elif line.startswith('/memreserve/ ') and line.endswith(';'):
206-
tag, start, end = line.split()
206+
_, start, end = line.split()
207207
start = int(start, 16)
208208
end = int(end[:-1], 16)
209209
label = "reserved_memory_0x%x_0x%x" % (start, end)
@@ -238,7 +238,7 @@ def dump_refs(name, value, indent=0):
238238

239239
def dump_all_refs(name, props, indent=0):
240240
out = []
241-
for key, value in props.items():
241+
for value in props.values():
242242
out.extend(dump_refs(name, value, indent))
243243
return out
244244

@@ -260,15 +260,16 @@ def dump_to_dot(nodes, indent=0, start_string='digraph devicetree', name=None):
260260
print("%s\"%s\";" % (spaces, name))
261261

262262
ref_list = []
263-
for key, value in nodes.items():
264-
if value['children']:
265-
refs = dump_to_dot(value['children'], indent + 1, next_subgraph(), get_dot_node_name(value))
263+
for node in nodes.values():
264+
if node['children']:
265+
refs = dump_to_dot(node['children'], indent + 1, next_subgraph(),
266+
get_dot_node_name(node))
266267
ref_list.extend(refs)
267268
else:
268-
print("%s\"%s\";" % (spaces, get_dot_node_name(value)))
269+
print("%s\"%s\";" % (spaces, get_dot_node_name(node)))
269270

270-
for key, value in nodes.items():
271-
refs = dump_all_refs(get_dot_node_name(value), value['props'], indent)
271+
for node in nodes.values():
272+
refs = dump_all_refs(get_dot_node_name(node), node['props'], indent)
272273
ref_list.extend(refs)
273274

274275
if start_string.startswith("digraph"):

scripts/dts/extract/clocks.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#
1717
class DTClocks(DTDirective):
1818
def _extract_consumer(self, node_path, clocks, def_label):
19-
20-
clock_consumer = reduced[node_path]
2119
clock_consumer_bindings = get_binding(node_path)
2220
clock_consumer_label = 'DT_' + node_label(node_path)
2321

@@ -39,7 +37,6 @@ def _extract_consumer(self, node_path, clocks, def_label):
3937
clock_provider = reduced[clock_provider_node_path]
4038
clock_provider_bindings = get_binding(
4139
clock_provider_node_path)
42-
clock_provider_label = node_label(clock_provider_node_path)
4340
nr_clock_cells = int(clock_provider['props'].get(
4441
'#clock-cells', 0))
4542
clock_cells_string = clock_provider_bindings.get(

scripts/dts/extract/compatible.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def extract(self, node_path, prop, def_label):
3131
if not isinstance(compatible, list):
3232
compatible = [compatible, ]
3333

34-
for i, comp in enumerate(compatible):
34+
for comp in compatible:
3535
# Generate #define
3636
insert_defs(node_path,
3737
{'DT_COMPAT_' + str_to_label(comp): '1'},

scripts/dts/extract/flash.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from extract.directive import DTDirective
99

1010
from extract.default import default
11-
from extract.reg import reg
1211

1312
##
1413
# @brief Manage flash directives.
@@ -159,7 +158,6 @@ def extract_flash(self):
159158
node_path = get_parent_path(node_path)
160159
(nr_address_cells, nr_size_cells) = get_addr_size_cells(node_path)
161160

162-
node_compat = get_compat(node_path)
163161
reg = reduced[node_path]['props']['reg']
164162
if type(reg) is not list: reg = [ reg, ]
165163
props = list(reg)

scripts/dts/extract/reg.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class DTReg(DTDirective):
2323
# compatible definition.
2424
#
2525
def extract(self, node_path, names, def_label, div):
26-
node = reduced[node_path]
27-
node_compat = get_compat(node_path)
2826
binding = get_binding(node_path)
2927

3028
reg = reduced[node_path]['props']['reg']

scripts/dts/extract_dts_includes.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88

99
# vim: ai:ts=4:sw=4
1010

11-
import sys
1211
import os, fnmatch
1312
import re
1413
import yaml
1514
import argparse
1615
from collections import defaultdict
17-
from collections.abc import Mapping
1816

1917
from devicetree import parse_file
2018
from extract.globals import *
@@ -149,7 +147,7 @@ def generate_bus_defines(node_path):
149147
try:
150148
parent_binding = get_binding(parent_path)
151149
parent_bus = parent_binding['child']['bus']
152-
except (KeyError, TypeError) as e:
150+
except (KeyError, TypeError):
153151
raise Exception("{0} defines parent {1} as bus master, but {1} is not "
154152
"configured as bus master in binding"
155153
.format(node_path, parent_path))
@@ -202,7 +200,7 @@ def merge_properties(parent, fname, to_dict, from_dict):
202200
# implement !include. 'parent' is the current parent key being looked at.
203201
# 'fname' is the top-level .yaml file.
204202

205-
for k, v in from_dict.items():
203+
for k in from_dict:
206204
if (k in to_dict and isinstance(to_dict[k], dict)
207205
and isinstance(from_dict[k], dict)):
208206
merge_properties(k, fname, to_dict[k], from_dict[k])
@@ -392,7 +390,7 @@ def find_binding_files(binding_dirs):
392390
binding_files = []
393391

394392
for binding_dir in binding_dirs:
395-
for root, dirnames, filenames in os.walk(binding_dir):
393+
for root, _, filenames in os.walk(binding_dir):
396394
for filename in fnmatch.filter(filenames, '*.yaml'):
397395
binding_files.append(os.path.join(root, filename))
398396

0 commit comments

Comments
 (0)