Merge tag 'u-boot-atmel-fixes-2021.01-b' of https://gitlab.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / scripts / dtc / libfdt / fdt.c
index 8e4cce3..28f4e1a 100644 (file)
@@ -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));