The memory configuration and initrd values exposed in the device tree are in
big endian format and should be swapped when running in little endian mode.

Signed-off-by: Laurent Dufour <[email protected]>
---
 kexec/arch/ppc64/crashdump-ppc64.c |    5 +++--
 kexec/arch/ppc64/kexec-ppc64.c     |   10 ++++++----
 kexec/fs2dt.c                      |    7 ++++---
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/kexec/arch/ppc64/crashdump-ppc64.c 
b/kexec/arch/ppc64/crashdump-ppc64.c
index e31dd6d..65ad65a 100644
--- a/kexec/arch/ppc64/crashdump-ppc64.c
+++ b/kexec/arch/ppc64/crashdump-ppc64.c
@@ -252,8 +252,9 @@ static int get_crash_memory_ranges(struct memory_range 
**range, int *ranges)
                                goto err;
                        }
 
-                       start = ((unsigned long long *)buf)[0];
-                       end = start + ((unsigned long long *)buf)[1];
+                       start = be64_to_cpu(((unsigned long long *)buf)[0]);
+                       end = start +
+                               be64_to_cpu(((unsigned long long *)buf)[1]);
                        if (start == 0 && end >= (BACKUP_SRC_END + 1))
                                start = BACKUP_SRC_END + 1;
 
diff --git a/kexec/arch/ppc64/kexec-ppc64.c b/kexec/arch/ppc64/kexec-ppc64.c
index af9112b..5ead9c5 100644
--- a/kexec/arch/ppc64/kexec-ppc64.c
+++ b/kexec/arch/ppc64/kexec-ppc64.c
@@ -278,8 +278,8 @@ static int get_base_ranges(void)
                                if (realloc_memory_ranges() < 0)
                                        break;
                        }
-                       start = ((uint64_t *)buf)[0];
-                       end = start + ((uint64_t *)buf)[1];
+                       start =  be64_to_cpu(((uint64_t *)buf)[0]);
+                       end = start + be64_to_cpu(((uint64_t *)buf)[1]);
                        add_base_memory_range(start, end);
                        fclose(file);
                }
@@ -492,6 +492,7 @@ static int get_devtree_details(unsigned long kexec_flags)
                                        perror(fname);
                                        goto error_openfile;
                                }
+                               initrd_start = be64_to_cpu(initrd_start);
                                fclose(file);
 
                                memset(fname, 0, sizeof(fname));
@@ -511,6 +512,7 @@ static int get_devtree_details(unsigned long kexec_flags)
                                        perror(fname);
                                        goto error_openfile;
                                }
+                               initrd_end = be64_to_cpu(initrd_end);
                                fclose(file);
 
                                /* Add initrd address to exclude_range */
@@ -568,8 +570,8 @@ static int get_devtree_details(unsigned long kexec_flags)
                                perror(fname);
                                goto error_openfile;
                        }
-                       rmo_base = ((uint64_t *)buf)[0];
-                       rmo_top = rmo_base + ((uint64_t *)buf)[1];
+                       rmo_base = be64_to_cpu(((uint64_t *)buf)[0]);
+                       rmo_top = rmo_base + be64_to_cpu(((uint64_t *)buf)[1]);
                        if (rmo_top > 0x30000000UL)
                                rmo_top = 0x30000000UL;
 
diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c
index 7202dc1..80d41fa 100644
--- a/kexec/fs2dt.c
+++ b/kexec/fs2dt.c
@@ -309,10 +309,11 @@ static void add_usable_mem_property(int fd, size_t len)
                die("unrecoverable error: error reading \"%s\": %s\n",
                    pathname, strerror(errno));
 
-       if (~0ULL - buf[0] < buf[1])
-               die("unrecoverable error: mem property overflow\n");
        base = be64_to_cpu(buf[0]);
-       end = base + be64_to_cpu(buf[1]);
+       end = be64_to_cpu(buf[1]);
+       if (~0ULL - base < end)
+               die("unrecoverable error: mem property overflow\n");
+       end += base;
 
        ranges = malloc(ranges_size * sizeof(*ranges));
        if (!ranges)


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Reply via email to