# --- T2-COPYRIGHT-NOTE-BEGIN --- # T2 SDE: package/*/kexec-tools/hotfix-ppc32.patch # Copyright (C) 2024 The T2 SDE Project # # This Copyright note is generated by scripts/Create-CopyPatch, # more information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License version 2 as used by the T2 SDE. # --- T2-COPYRIGHT-NOTE-END --- --- kexec-tools-2.0.29-rc1/kexec/arch/ppc/kexec-ppc.c.vanilla 2024-07-14 09:37:42.620938667 +0000 +++ kexec-tools-2.0.29-rc1/kexec/arch/ppc/kexec-ppc.c 2024-07-14 10:09:17.547252869 +0000 @@ -92,38 +92,55 @@ { char buf[MAXBYTES]; unsigned long *p; - unsigned long nbytes = dt_address_cells + dt_size_cells; + unsigned long nbytes = dt_address_cells + dt_size_cells, i; + unsigned long long _start, _end; if (lseek(fd, 0, SEEK_SET) == -1) { fprintf(stderr, "Error in file seek\n"); return -1; } - if (read(fd, buf, nbytes) != nbytes) { - fprintf(stderr, "Error reading the memory region info\n"); - return -1; - } - p = (unsigned long*)buf; - if (dt_address_cells == sizeof(unsigned long)) { - *start = p[0]; - p++; - } else if (dt_address_cells == sizeof(unsigned long long)) { - *start = ((unsigned long long *)p)[0]; - p = (unsigned long long *)p + 1; - } else { - fprintf(stderr, "Unsupported value for #address-cells : %ld\n", - dt_address_cells); - return -1; - } + *start = ~0ULL; *end = 0; + for (i = 0; ; ++i) { + if (read(fd, buf, nbytes) != nbytes) { + if (i == 0) { + fprintf(stderr, "Error reading the memory region info\n"); + return -1; + } + break; + } - if (dt_size_cells == sizeof(unsigned long)) - *end = *start + p[0]; - else if (dt_size_cells == sizeof(unsigned long long)) - *end = *start + ((unsigned long long *)p)[0]; - else { - fprintf(stderr, "Unsupported value for #size-cells : %ld\n", - dt_size_cells); - return -1; + p = (unsigned long*)buf; + if (dt_address_cells == sizeof(unsigned long)) { + _start = p[0]; + p++; + } else if (dt_address_cells == sizeof(unsigned long long)) { + _start = ((unsigned long long *)p)[0]; + p = (unsigned long long *)p + 1; + } else { + fprintf(stderr, "Unsupported value for #address-cells : %ld\n", + dt_address_cells); + return -1; + } + + if (dt_size_cells == sizeof(unsigned long)) + _end = _start + p[0]; + else if (dt_size_cells == sizeof(unsigned long long)) + _end = _start + ((unsigned long long *)p)[0]; + else { + fprintf(stderr, "Unsupported value for #size-cells : %ld\n", + dt_size_cells); + return -1; + } + + // valid size? + if (_start == _end) + continue; + + if (_start < *start) + *start = _start; + if (_end > *end) + *end = _end; } return 0; @@ -193,12 +215,12 @@ } - static void cleanup_memory_ranges(void) - { - free(memory_range); - free(base_memory_range); - free(exclude_range); - } +static void cleanup_memory_ranges(void) +{ + free(memory_range); + free(base_memory_range); + free(exclude_range); +} /* * Allocate memory for various data structures used to hold --- kexec-tools-2.0.29-rc1/kexec/arch/ppc/fs2dt.c.vanilla 2024-07-14 12:45:25.830477940 +0200 +++ kexec-tools-2.0.29-rc1/kexec/arch/ppc/fs2dt.c 2024-07-14 23:47:58.097188761 +0200 @@ -161,7 +161,7 @@ if (!rlen) { /* - * User did not pass any ranges for thsi region. Hence, write + * User did not pass any ranges for this region. Hence, write * (0,0) duple in linux,usable-memory property such that * this region will be ignored. */ @@ -238,9 +238,12 @@ die("unrecoverable error: could not open \"%s\": %s\n", pathname, strerror(errno)); - if (read(fd, dt, len) != len) - die("unrecoverable error: could not read \"%s\": %s\n", - pathname, strerror(errno)); + for (int i = 0, ret; i < len; i += ret) { + ret = read(fd, ((char*)dt) + i, len - i); + if (ret <= 0) + die("unrecoverable error: could not read \"%s\": %s\n", + pathname, strerror(errno)); + } checkprop(fn, dt, len);