summaryrefslogtreecommitdiffstats
path: root/scripts/dtc/libfdt/fdt_sw.c
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@arm.com>2020-10-16 15:42:50 +0100
committerTom Rini <trini@konsulko.com>2020-11-10 14:31:08 -0500
commit832bfad7451e2e7bd23c96edff2be050905ac3f6 (patch)
tree2718e71690825af1f097bbbe38983d505ea9d92c /scripts/dtc/libfdt/fdt_sw.c
parentf36603c7a823308f23d10d443d6cbf6b365c12bd (diff)
downloadu-boot-832bfad7451e2e7bd23c96edff2be050905ac3f6.tar.gz
u-boot-832bfad7451e2e7bd23c96edff2be050905ac3f6.tar.xz
u-boot-832bfad7451e2e7bd23c96edff2be050905ac3f6.zip
libfdt: Fix signedness comparison warnings
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 <andre.przywara@arm.com>
Diffstat (limited to 'scripts/dtc/libfdt/fdt_sw.c')
-rw-r--r--scripts/dtc/libfdt/fdt_sw.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/scripts/dtc/libfdt/fdt_sw.c b/scripts/dtc/libfdt/fdt_sw.c
index a8c924675a..d9e67fa2a6 100644
--- a/scripts/dtc/libfdt/fdt_sw.c
+++ b/scripts/dtc/libfdt/fdt_sw.c
@@ -96,8 +96,8 @@ static inline uint32_t sw_flags(void *fdt)
static void *fdt_grab_space_(void *fdt, size_t len)
{
- int offset = fdt_size_dt_struct(fdt);
- int spaceleft;
+ unsigned int offset = fdt_size_dt_struct(fdt);
+ unsigned int spaceleft;
spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt)
- fdt_size_dt_strings(fdt);
@@ -111,8 +111,8 @@ static void *fdt_grab_space_(void *fdt, size_t len)
int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags)
{
- const size_t hdrsize = FDT_ALIGN(sizeof(struct fdt_header),
- sizeof(struct fdt_reserve_entry));
+ const int hdrsize = FDT_ALIGN(sizeof(struct fdt_header),
+ sizeof(struct fdt_reserve_entry));
void *fdt = buf;
if (bufsize < hdrsize)
@@ -155,13 +155,16 @@ int fdt_resize(void *fdt, void *buf, int bufsize)
FDT_SW_PROBE(fdt);
+ if (bufsize < 0)
+ return -FDT_ERR_NOSPACE;
+
headsize = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
tailsize = fdt_size_dt_strings(fdt);
if (fdt_chk_extra() && (headsize + tailsize) > fdt_totalsize(fdt))
return -FDT_ERR_INTERNAL;
- if ((headsize + tailsize) > bufsize)
+ if ((headsize + tailsize) > (unsigned)bufsize)
return -FDT_ERR_NOSPACE;
oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize;
@@ -249,18 +252,18 @@ int fdt_end_node(void *fdt)
static int fdt_add_string_(void *fdt, const char *s)
{
char *strtab = (char *)fdt + fdt_totalsize(fdt);
- int strtabsize = fdt_size_dt_strings(fdt);
- int len = strlen(s) + 1;
- int struct_top, offset;
+ unsigned int strtabsize = fdt_size_dt_strings(fdt);
+ unsigned int len = strlen(s) + 1;
+ unsigned int struct_top, offset;
- offset = -strtabsize - len;
+ offset = strtabsize + len;
struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
- if (fdt_totalsize(fdt) + offset < struct_top)
+ if (fdt_totalsize(fdt) - offset < struct_top)
return 0; /* no more room :( */
- memcpy(strtab + offset, s, len);
+ memcpy(strtab - offset, s, len);
fdt_set_size_dt_strings(fdt, strtabsize + len);
- return offset;
+ return -offset;
}
/* Must only be used to roll back in case of error */