From 832bfad7451e2e7bd23c96edff2be050905ac3f6 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Fri, 16 Oct 2020 15:42:50 +0100 Subject: libfdt: Fix signedness comparison warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a combination of upstream libfdt commits to fix warnings about comparing signed and unsigned integers: ========== scripts/dtc/libfdt/fdt.c: In function ‘fdt_offset_ptr’: scripts/dtc/libfdt/fdt.c:137:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if ((absoffset < offset) ... ========== For a detailed description of the fixes, see the dtc repo: https://git.kernel.org/pub/scm/utils/dtc/dtc.git/log/?id=73e0f143b73d808 For this patch the commits between 73e0f143b73d8088 and ca19c3db2bf62000 have been combined and adjusted for the slight differences in U-Boot's libfdt code base. Signed-off-by: Andre Przywara --- scripts/dtc/libfdt/fdt.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'scripts/dtc/libfdt/fdt.c') diff --git a/scripts/dtc/libfdt/fdt.c b/scripts/dtc/libfdt/fdt.c index 8e4cce3b9be..28f4e1a5f15 100644 --- a/scripts/dtc/libfdt/fdt.c +++ b/scripts/dtc/libfdt/fdt.c @@ -131,16 +131,20 @@ int fdt_check_header(const void *fdt) const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) { - unsigned absoffset = offset + fdt_off_dt_struct(fdt); + unsigned int uoffset = offset; + unsigned int absoffset = offset + fdt_off_dt_struct(fdt); + + if (offset < 0) + return NULL; if (fdt_chk_basic()) - if ((absoffset < offset) + if ((absoffset < uoffset) || ((absoffset + len) < absoffset) || (absoffset + len) > fdt_totalsize(fdt)) return NULL; if (!fdt_chk_version() || fdt_version(fdt) >= 0x11) - if (((offset + len) < offset) + if (((uoffset + len) < uoffset) || ((offset + len) > fdt_size_dt_struct(fdt))) return NULL; @@ -302,9 +306,12 @@ const char *fdt_find_string_(const char *strtab, int tabsize, const char *s) int fdt_move(const void *fdt, void *buf, int bufsize) { + if (fdt_chk_basic() && bufsize < 0) + return -FDT_ERR_NOSPACE; + FDT_RO_PROBE(fdt); - if (fdt_totalsize(fdt) > bufsize) + if (fdt_totalsize(fdt) > (unsigned int)bufsize) return -FDT_ERR_NOSPACE; memmove(buf, fdt, fdt_totalsize(fdt)); -- cgit v1.2.3