[U-Boot] [PATCH 15/24] binman: Avoid changing a dict during iteration

Simon Glass sjg at chromium.org
Sat May 18 04:00:45 UTC 2019


This code works OK in Python 2 but Python 3 complains. Adjust it to avoid
deleting elements from a dict while iterating through it.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/binman/control.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/binman/control.py b/tools/binman/control.py
index ce25eb54858..20186ee1980 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -131,10 +131,13 @@ def Binman(options, args):
 
             if options.image:
                 skip = []
+                new_images = OrderedDict()
                 for name, image in images.items():
-                    if name not in options.image:
-                        del images[name]
+                    if name in options.image:
+                        new_images[name] = image
+                    else:
                         skip.append(name)
+                images = new_images
                 if skip and options.verbosity >= 2:
                     print('Skipping images: %s' % ', '.join(skip))
 
-- 
2.21.0.1020.gf2820cf01a-goog



More information about the U-Boot mailing list