binman: Handle some newer pylint warnings
RFC PATCH 1/1 binman: Handle some newer pylint warnings
With a newer pylint we have a few warnings show up now that are harder to handle. The first problem is that when we call self.Raise(...) this is no longer enough to have pylint see that we're now bailing out and won't attempt to reference an unassigned variable. This is all of the pylint disabling, with the exception of _AddNode.
The problem with _AddNode is that before we call this function we set fsw as libfdt.FdtSw() and I'm unsure how best to rework the code.
The final problem is in CheckSetHashValue() where the function only handles one algorithm but the intention is to handle others as well. Once another algorithm is added and then also error handling for no algorithm is added, we would not attempt to use data before it's been assigned.
As I'm not confident all of these are the right way to handle the problem I've marked this as RFC and not split the changes up more.
---
Cc: Simon Glass <[email protected]>
--- tools/binman/etype/fdtmap.py | 1 + tools/binman/etype/image_header.py | 1 + tools/binman/etype/pre_load.py | 1 + tools/binman/etype/x509_cert.py | 1 + tools/binman/ftest.py | 1 + tools/binman/state.py | 4 ++-- 6 files changed, 7 insertions(+), 2 deletions(-)
tools/binman/etype/fdtmap.py +1 -0
@@ -109,6 +109,7 @@ class Entry_fdtmap(Entry): def _AddNode(node): """Add a node to the FDT map""" for pname, prop in node.props.items(): + # pylint: disable=locally-disabled, possibly-used-before-assignment fsw.property(pname, prop.bytes) for subnode in node.subnodes: with fsw.add_node(subnode.name):
tools/binman/etype/image_header.py +1 -0
@@ -72,6 +72,7 @@ class Entry_image_header(Entry): image_size = self.section.GetImageSize() or 0 base = (0 if self.location != 'end' else image_size) offset = (image_pos - base) & 0xffffffff + # pylint: disable=locally-disabled, possibly-used-before-assignment data = IMAGE_HEADER_MAGIC + struct.pack('<I', offset) return data
tools/binman/etype/pre_load.py +1 -0
@@ -122,6 +122,7 @@ class Entry_pre_load(Entry_collection): else: self.Raise(padding_name + " is not supported") + # pylint: disable=locally-disabled, possibly-used-before-assignment sig = padding.new(key, **padding_args).sign(hash_image) hash_sig = SHA256.new()
tools/binman/etype/x509_cert.py +1 -0
@@ -141,6 +141,7 @@ class Entry_x509_cert(Entry_collection): dm_data_ext_boot_block=self.dm_data_ext_boot_block, bootcore_opts=self.bootcore_opts ) + # pylint: disable=locally-disabled, possibly-used-before-assignment if stdout is not None: data = tools.read_file(output_fname) else:
tools/binman/ftest.py +1 -0
@@ -6387,6 +6387,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap expect_val = entry.image_pos elif prop_name == 'size': expect_val = entry.size + # pylint: disable=locally-disabled, possibly-used-before-assignment self.assertEqual(expect_val, val) def testSymbolsElfBad(self):
tools/binman/state.py +2 -2
@@ -410,8 +410,8 @@ def CheckSetHashValue(node, get_data_func): m = hashlib.sha256() m.update(get_data_func()) data = m.digest() - for n in GetUpdateNodes(hash_node): - n.SetData('value', data) + for n in GetUpdateNodes(hash_node): + n.SetData('value', data) def SetAllowEntryExpansion(allow): """Set whether post-pack expansion of entries is allowed
Signature · 1 line
2.43.0
Quoted 95 lines · Tom Rini
With a newer pylint we have a few warnings show up now that are harder to handle. The first problem is that when we call
self.Raise(...)this is no longer enough to have pylint see that we're now bailing out and won't attempt to reference an unassigned variable. This is all of the pylint disabling, with the exception of_AddNode.The problem with
_AddNodeis that before we call this function we set fsw aslibfdt.FdtSw()and I'm unsure how best to rework the code.The final problem is in
CheckSetHashValue()where the function only handles one algorithm but the intention is to handle others as well. Once another algorithm is added and then also error handling for no algorithm is added, we would not attempt to use data before it's been assigned.As I'm not confident all of these are the right way to handle the problem I've marked this as RFC and not split the changes up more.
Signed-off-by Tom Rini <[email protected]>---
Cc: Simon Glass <[email protected]>--- tools/binman/etype/fdtmap.py | 1 + tools/binman/etype/image_header.py | 1 + tools/binman/etype/pre_load.py | 1 + tools/binman/etype/x509_cert.py | 1 + tools/binman/ftest.py | 1 + tools/binman/state.py | 4 ++-- 6 files changed, 7 insertions(+), 2 deletions(-)tools/binman/etype/fdtmap.py +1
-0@@ -109,6 +109,7 @@ class Entry_fdtmap(Entry): def _AddNode(node): """Add a node to the FDT map""" for pname, prop in node.props.items(): + # pylint: disable=locally-disabled, possibly-used-before-assignment fsw.property(pname, prop.bytes) for subnode in node.subnodes: with fsw.add_node(subnode.name):tools/binman/etype/image_header.py +1
-0@@ -72,6 +72,7 @@ class Entry_image_header(Entry): image_size = self.section.GetImageSize() or 0 base = (0 if self.location != 'end' else image_size) offset = (image_pos - base) & 0xffffffff + # pylint: disable=locally-disabled, possibly-used-before-assignment data = IMAGE_HEADER_MAGIC + struct.pack('<I', offset) return datatools/binman/etype/pre_load.py +1
-0@@ -122,6 +122,7 @@ class Entry_pre_load(Entry_collection): else: self.Raise(padding_name + " is not supported") + # pylint: disable=locally-disabled, possibly-used-before-assignment sig = padding.new(key, **padding_args).sign(hash_image) hash_sig = SHA256.new()tools/binman/etype/x509_cert.py +1
-0@@ -141,6 +141,7 @@ class Entry_x509_cert(Entry_collection): dm_data_ext_boot_block=self.dm_data_ext_boot_block, bootcore_opts=self.bootcore_opts ) + # pylint: disable=locally-disabled, possibly-used-before-assignment if stdout is not None: data = tools.read_file(output_fname) else:tools/binman/ftest.py +1
-0@@ -6387,6 +6387,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap expect_val = entry.image_pos elif prop_name == 'size': expect_val = entry.size + # pylint: disable=locally-disabled, possibly-used-before-assignment self.assertEqual(expect_val, val) def testSymbolsElfBad(self):tools/binman/state.py +0
-0
tools/binman/state.py def CheckSetHashValue(node, get_data_func): · line 417
Quoted 10 lines
tools/binman/state.py +2
-2@@ -410,8 +410,8 @@ def CheckSetHashValue(node, get_data_func): m = hashlib.sha256() m.update(get_data_func()) data = m.digest() - for n in GetUpdateNodes(hash_node): - n.SetData('value', data) + for n in GetUpdateNodes(hash_node): + n.SetData('value', data) def SetAllowEntryExpansion(allow): """Set whether post-pack expansion of entries is allowed
Any thoughts on this Simon? Moving to a newer Ubuntu host for CI is blocked on moving to a newer pylint. Thanks.
Signature · 1 line
Tom
Hi Tom,
Quoted 106 lines · Tom Rini
Quoted 103 lines · Tom Rini
With a newer pylint we have a few warnings show up now that are harder to handle. The first problem is that when we call
self.Raise(...)this is no longer enough to have pylint see that we're now bailing out and won't attempt to reference an unassigned variable. This is all of the pylint disabling, with the exception of_AddNode.The problem with
_AddNodeis that before we call this function we set fsw aslibfdt.FdtSw()and I'm unsure how best to rework the code.The final problem is in
CheckSetHashValue()where the function only handles one algorithm but the intention is to handle others as well. Once another algorithm is added and then also error handling for no algorithm is added, we would not attempt to use data before it's been assigned.As I'm not confident all of these are the right way to handle the problem I've marked this as RFC and not split the changes up more.
Signed-off-by Tom Rini <[email protected]>---
Cc: Simon Glass <[email protected]>--- tools/binman/etype/fdtmap.py | 1 + tools/binman/etype/image_header.py | 1 + tools/binman/etype/pre_load.py | 1 + tools/binman/etype/x509_cert.py | 1 + tools/binman/ftest.py | 1 + tools/binman/state.py | 4 ++-- 6 files changed, 7 insertions(+), 2 deletions(-)tools/binman/etype/fdtmap.py +1
-0@@ -109,6 +109,7 @@ class Entry_fdtmap(Entry): def _AddNode(node): """Add a node to the FDT map""" for pname, prop in node.props.items(): + # pylint: disable=locally-disabled, possibly-used-before-assignment fsw.property(pname, prop.bytes) for subnode in node.subnodes: with fsw.add_node(subnode.name):tools/binman/etype/image_header.py +1
-0@@ -72,6 +72,7 @@ class Entry_image_header(Entry): image_size = self.section.GetImageSize() or 0 base = (0 if self.location != 'end' else image_size) offset = (image_pos - base) & 0xffffffff + # pylint: disable=locally-disabled, possibly-used-before-assignment data = IMAGE_HEADER_MAGIC + struct.pack('<I', offset) return datatools/binman/etype/pre_load.py +1
-0@@ -122,6 +122,7 @@ class Entry_pre_load(Entry_collection): else: self.Raise(padding_name + " is not supported") + # pylint: disable=locally-disabled, possibly-used-before-assignment sig = padding.new(key, **padding_args).sign(hash_image) hash_sig = SHA256.new()tools/binman/etype/x509_cert.py +1
-0@@ -141,6 +141,7 @@ class Entry_x509_cert(Entry_collection): dm_data_ext_boot_block=self.dm_data_ext_boot_block, bootcore_opts=self.bootcore_opts ) + # pylint: disable=locally-disabled, possibly-used-before-assignment if stdout is not None: data = tools.read_file(output_fname) else:tools/binman/ftest.py +1
-0@@ -6387,6 +6387,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap expect_val = entry.image_pos elif prop_name == 'size': expect_val = entry.size + # pylint: disable=locally-disabled, possibly-used-before-assignment self.assertEqual(expect_val, val) def testSymbolsElfBad(self):tools/binman/state.py +2
-2@@ -410,8 +410,8 @@ def CheckSetHashValue(node, get_data_func): m = hashlib.sha256() m.update(get_data_func()) data = m.digest() - for n in GetUpdateNodes(hash_node): - n.SetData('value', data) + for n in GetUpdateNodes(hash_node): + n.SetData('value', data)
Quoted 5 lines
tools/binman/state.py def CheckSetHashValue(node, get_data_func): · line 417
Quoted 2 lines
tools/binman/state.py +0
-0def SetAllowEntryExpansion(allow): """Set whether post-pack expansion of entries is allowedAny thoughts on this Simon? Moving to a newer Ubuntu host for CI is blocked on moving to a newer pylint. Thanks.
There is no need to disable these warnings so far as I can tell and it sets a bad precedent. We should just fix the code. I can send a patch for this if you like?
Regards,
Simon
Quoted 115 lines · Simon Glass
Hi Tom,
Quoted 106 lines · Tom Rini
Quoted 103 lines · Tom Rini
With a newer pylint we have a few warnings show up now that are harder to handle. The first problem is that when we call
self.Raise(...)this is no longer enough to have pylint see that we're now bailing out and won't attempt to reference an unassigned variable. This is all of the pylint disabling, with the exception of_AddNode.The problem with
_AddNodeis that before we call this function we set fsw aslibfdt.FdtSw()and I'm unsure how best to rework the code.The final problem is in
CheckSetHashValue()where the function only handles one algorithm but the intention is to handle others as well. Once another algorithm is added and then also error handling for no algorithm is added, we would not attempt to use data before it's been assigned.As I'm not confident all of these are the right way to handle the problem I've marked this as RFC and not split the changes up more.
Signed-off-by Tom Rini <[email protected]>---
Cc: Simon Glass <[email protected]>--- tools/binman/etype/fdtmap.py | 1 + tools/binman/etype/image_header.py | 1 + tools/binman/etype/pre_load.py | 1 + tools/binman/etype/x509_cert.py | 1 + tools/binman/ftest.py | 1 + tools/binman/state.py | 4 ++-- 6 files changed, 7 insertions(+), 2 deletions(-)tools/binman/etype/fdtmap.py +1
-0@@ -109,6 +109,7 @@ class Entry_fdtmap(Entry): def _AddNode(node): """Add a node to the FDT map""" for pname, prop in node.props.items(): + # pylint: disable=locally-disabled, possibly-used-before-assignment fsw.property(pname, prop.bytes) for subnode in node.subnodes: with fsw.add_node(subnode.name):tools/binman/etype/image_header.py +1
-0@@ -72,6 +72,7 @@ class Entry_image_header(Entry): image_size = self.section.GetImageSize() or 0 base = (0 if self.location != 'end' else image_size) offset = (image_pos - base) & 0xffffffff + # pylint: disable=locally-disabled, possibly-used-before-assignment data = IMAGE_HEADER_MAGIC + struct.pack('<I', offset) return datatools/binman/etype/pre_load.py +1
-0@@ -122,6 +122,7 @@ class Entry_pre_load(Entry_collection): else: self.Raise(padding_name + " is not supported") + # pylint: disable=locally-disabled, possibly-used-before-assignment sig = padding.new(key, **padding_args).sign(hash_image) hash_sig = SHA256.new()tools/binman/etype/x509_cert.py +1
-0@@ -141,6 +141,7 @@ class Entry_x509_cert(Entry_collection): dm_data_ext_boot_block=self.dm_data_ext_boot_block, bootcore_opts=self.bootcore_opts ) + # pylint: disable=locally-disabled, possibly-used-before-assignment if stdout is not None: data = tools.read_file(output_fname) else:tools/binman/ftest.py +1
-0@@ -6387,6 +6387,7 @@ fdt fdtmap Extract the devicetree blob from the fdtmap expect_val = entry.image_pos elif prop_name == 'size': expect_val = entry.size + # pylint: disable=locally-disabled, possibly-used-before-assignment self.assertEqual(expect_val, val) def testSymbolsElfBad(self):tools/binman/state.py +2
-2@@ -410,8 +410,8 @@ def CheckSetHashValue(node, get_data_func): m = hashlib.sha256() m.update(get_data_func()) data = m.digest() - for n in GetUpdateNodes(hash_node): - n.SetData('value', data) + for n in GetUpdateNodes(hash_node): + n.SetData('value', data)Quoted 5 lines
tools/binman/state.py def CheckSetHashValue(node, get_data_func): · line 417
Quoted 2 lines
tools/binman/state.py +0
-0def SetAllowEntryExpansion(allow): """Set whether post-pack expansion of entries is allowedAny thoughts on this Simon? Moving to a newer Ubuntu host for CI is blocked on moving to a newer pylint. Thanks.
Quoted 3 lines
There is no need to disable these warnings so far as I can tell and it sets a bad precedent. We should just fix the code. I can send a patch for this if you like?
Yes, if you can fix the code please do as I don't see how to and they need to be disabled for pylint_err to pass with current pylint versions, thanks!
Signature · 1 line
Tom