fiptool: refactor remove_image()
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Fri, 27 Jan 2017 04:31:40 +0000 (13:31 +0900)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Fri, 27 Jan 2017 06:03:46 +0000 (15:03 +0900)
We need not handle the image_head as a special case.  Just use
a double-pointer to simplify the traverse.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
tools/fiptool/fiptool.c

index 7a5c2cd72321db9d8ac80c31051c923ee74ccb5c..fef1ea832349882dded3f1258f84390441dc987c 100644 (file)
@@ -276,20 +276,20 @@ static void free_image(image_t *image)
 
 static void remove_image(image_t *image)
 {
-       image_t *tmp = image_head, *prev;
-
-       if (tmp == image) {
-               image_head = tmp->next;
-               free_image(tmp);
-       } else {
-               while (tmp != NULL && tmp != image) {
-                       prev = tmp;
-                       tmp = tmp->next;
-               }
-               assert(tmp != NULL);
-               prev->next = tmp->next;
-               free_image(tmp);
+       image_t *tmp, **p = &image_head;
+
+       while (*p) {
+               if (*p == image)
+                       break;
+               p = &(*p)->next;
        }
+
+       assert(*p != NULL);
+
+       tmp = *p;
+       *p = tmp->next;
+       free_image(tmp);
+
        nr_images--;
 }