]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: relocate-rela: Open binary u-boot file later
authorMichal Simek <michal.simek@amd.com>
Fri, 24 Jun 2022 12:14:59 +0000 (14:14 +0200)
committerMichal Simek <michal.simek@amd.com>
Fri, 24 Jun 2022 12:14:59 +0000 (14:14 +0200)
There is no value to open u-boot binary file so early. Better to check all
values first and then open binary file.

Signed-off-by: Michal Simek <michal.simek@amd.com>
Link: https://lore.kernel.org/r/9c2b4ebadbe83497db28af02f6af2623793ffdb6.1655299267.git.michal.simek@amd.com
tools/relocate-rela.c

index f0bc548617a43e8f53d56e2d112c3b635abd35b7..8839871118692c72726faefb2c7ab4b65df9204b 100644 (file)
@@ -73,13 +73,6 @@ int main(int argc, char **argv)
                return 1;
        }
 
-       f = fopen(argv[1], "r+b");
-       if (!f) {
-               fprintf(stderr, "%s: Cannot open %s: %s\n",
-                       argv[0], argv[1], strerror(errno));
-               return 2;
-       }
-
        if (!read_num(argv[2], &text_base) ||
            !read_num(argv[3], &rela_start) ||
            !read_num(argv[4], &rela_end)) {
@@ -95,6 +88,13 @@ int main(int argc, char **argv)
        rela_start -= text_base;
        rela_end -= text_base;
 
+       f = fopen(argv[1], "r+b");
+       if (!f) {
+               fprintf(stderr, "%s: Cannot open %s: %s\n",
+                       argv[0], argv[1], strerror(errno));
+               return 2;
+       }
+
        fseek(f, 0, SEEK_END);
        file_size = ftell(f);
        rewind(f);