]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dtc: Enable and fix -Wpointer-arith warnings
authorDavid Gibson <david@gibson.dropbear.id.au>
Mon, 7 Jul 2008 00:10:48 +0000 (10:10 +1000)
committerGerald Van Baren <vanbaren@cideas.com>
Mon, 25 Aug 2008 02:20:49 +0000 (22:20 -0400)
This patch turns on the -Wpointer-arith option in the dtc Makefile,
and fixes the resulting warnings due to using (void *) in pointer
arithmetic.  While convenient, pointer arithmetic on void * is not
portable, so it's better that we avoid it, particularly in libfdt.

Also add necessary definition of uintptr_t needed by David Gibson's
changeset "dtc: Enable and fix -Wpointer-arith warnings" (the definition
comes from stdint.h, which u-boot doesn't have). -- gvb

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
include/libfdt_env.h
libfdt/fdt.c
libfdt/fdt_ro.c
libfdt/fdt_rw.c
libfdt/fdt_sw.c
libfdt/fdt_wip.c
libfdt/libfdt_internal.h

index a7fd2f8d9a6aa43a63808a3327ddfb3521835e1d..671c3a8981ad5071f3ec024fc97649a6ec93a7f4 100644 (file)
@@ -38,4 +38,16 @@ extern struct fdt_header *working_fdt;  /* Pointer to the working fdt */
 #define fdt64_to_cpu(x)                __be64_to_cpu(x)
 #define cpu_to_fdt64(x)                __cpu_to_be64(x)
 
+/*
+ * Types for `void *' pointers.
+ *
+ * Note: libfdt uses this definition from /usr/include/stdint.h.
+ * Define it here rather than pulling in all of stdint.h.
+ */
+#if __WORDSIZE == 64
+typedef unsigned long int       uintptr_t;
+#else
+typedef unsigned int            uintptr_t;
+#endif
+
 #endif /* _LIBFDT_ENV_H */
index cb08ba0a94630cc20b90955423be04886c4546c6..18e8d3c6514d75d0c96f4b8415831e6322cdbd53 100644 (file)
@@ -80,7 +80,7 @@ int fdt_check_header(const void *fdt)
 
 const void *fdt_offset_ptr(const void *fdt, int offset, int len)
 {
-       const void *p;
+       const char *p;
 
        if (fdt_version(fdt) >= 0x11)
                if (((offset + len) < offset)
index 69af7bb843ae4e36ce4a3f89fb1190a52c27d254..8382afd38835c674702889caf0833815c55de38e 100644 (file)
@@ -412,10 +412,10 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
                                             &phandle, sizeof(phandle));
 }
 
-int _stringlist_contains(const void *strlist, int listlen, const char *str)
+int _stringlist_contains(const char *strlist, int listlen, const char *str)
 {
        int len = strlen(str);
-       const void *p;
+       const char *p;
 
        while (listlen >= len) {
                if (memcmp(str, strlist, len+1) == 0)
index 95a5c2c62bee3888d7d13daf726b7f435d378c2a..4a16014a9148ba92e9c6064757c73af884aa0a36 100644 (file)
@@ -98,13 +98,14 @@ static inline int _blob_data_size(void *fdt)
        return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
 }
 
-static int _blob_splice(void *fdt, void *p, int oldlen, int newlen)
+static int _blob_splice(void *fdt, void *splicepoint, int oldlen, int newlen)
 {
-       void *end = fdt + _blob_data_size(fdt);
+       char *p = splicepoint;
+       char *end = (char *)fdt + _blob_data_size(fdt);
 
        if (((p + oldlen) < p) || ((p + oldlen) > end))
                return -FDT_ERR_BADOFFSET;
-       if ((end - oldlen + newlen) > (fdt + fdt_totalsize(fdt)))
+       if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))
                return -FDT_ERR_NOSPACE;
        memmove(p + newlen, p + oldlen, end - p - oldlen);
        return 0;
@@ -139,7 +140,8 @@ static int _blob_splice_struct(void *fdt, void *p,
 
 static int _blob_splice_string(void *fdt, int newlen)
 {
-       void *p = fdt + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
+       void *p = (char *)fdt
+               + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt);
        int err;
 
        if ((err = _blob_splice(fdt, p, 0, newlen)))
@@ -342,7 +344,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
        nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
        memset(nh->name, 0, ALIGN(namelen+1, FDT_TAGSIZE));
        memcpy(nh->name, name, namelen);
-       endtag = (uint32_t *)((void *)nh + nodelen - FDT_TAGSIZE);
+       endtag = (uint32_t *)((char *)nh + nodelen - FDT_TAGSIZE);
        *endtag = cpu_to_fdt32(FDT_END_NODE);
 
        return offset;
@@ -367,7 +369,7 @@ int fdt_del_node(void *fdt, int nodeoffset)
                                   endoffset - nodeoffset, 0);
 }
 
-static void _packblocks(const void *fdt, void *buf,
+static void _packblocks(const char *old, char *new,
                       int mem_rsv_size, int struct_size)
 {
        int mem_rsv_off, struct_off, strings_off;
@@ -376,17 +378,17 @@ static void _packblocks(const void *fdt, void *buf,
        struct_off = mem_rsv_off + mem_rsv_size;
        strings_off = struct_off + struct_size;
 
-       memmove(buf + mem_rsv_off, fdt + fdt_off_mem_rsvmap(fdt), mem_rsv_size);
-       fdt_set_off_mem_rsvmap(buf, mem_rsv_off);
+       memmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size);
+       fdt_set_off_mem_rsvmap(new, mem_rsv_off);
 
-       memmove(buf + struct_off, fdt + fdt_off_dt_struct(fdt), struct_size);
-       fdt_set_off_dt_struct(buf, struct_off);
-       fdt_set_size_dt_struct(buf, struct_size);
+       memmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size);
+       fdt_set_off_dt_struct(new, struct_off);
+       fdt_set_size_dt_struct(new, struct_size);
 
-       memmove(buf + strings_off, fdt + fdt_off_dt_strings(fdt),
-               fdt_size_dt_strings(fdt));
-       fdt_set_off_dt_strings(buf, strings_off);
-       fdt_set_size_dt_strings(buf, fdt_size_dt_strings(fdt));
+       memmove(new + strings_off, old + fdt_off_dt_strings(old),
+               fdt_size_dt_strings(old));
+       fdt_set_off_dt_strings(new, strings_off);
+       fdt_set_size_dt_strings(new, fdt_size_dt_strings(old));
 }
 
 int fdt_open_into(const void *fdt, void *buf, int bufsize)
@@ -394,7 +396,9 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
        int err;
        int mem_rsv_size, struct_size;
        int newsize;
-       void *tmp;
+       const char *fdtstart = fdt;
+       const char *fdtend = fdtstart + fdt_totalsize(fdt);
+       char *tmp;
 
        CHECK_HEADER(fdt);
 
@@ -427,12 +431,13 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
        if (bufsize < newsize)
                return -FDT_ERR_NOSPACE;
 
-       if (((buf + newsize) <= fdt)
-           || (buf >= (fdt + fdt_totalsize(fdt)))) {
-               tmp = buf;
-       } else {
-               tmp = (void *)fdt + fdt_totalsize(fdt);
-               if ((tmp + newsize) > (buf + bufsize))
+       /* First attempt to build converted tree at beginning of buffer */
+       tmp = buf;
+       /* But if that overlaps with the old tree... */
+       if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) {
+               /* Try right after the old tree instead */
+               tmp = (char *)fdtend;
+               if ((tmp + newsize) > ((char *)buf + bufsize))
                        return -FDT_ERR_NOSPACE;
        }
 
index df0987606e3f90ee743847dd340c6b78de00f14a..92f8f0bb39afc907dba4d050abe0fcf8c6ad3c38 100644 (file)
@@ -121,7 +121,7 @@ int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
        if ((offset + sizeof(*re)) > fdt_totalsize(fdt))
                return -FDT_ERR_NOSPACE;
 
-       re = (struct fdt_reserve_entry *)(fdt + offset);
+       re = (struct fdt_reserve_entry *)((char *)fdt + offset);
        re->address = cpu_to_fdt64(addr);
        re->size = cpu_to_fdt64(size);
 
index 24e172495aaeb63b4643ca4785d30f2b4451c682..b33611346ae04662e59559a7152efbff70772755 100644 (file)
@@ -80,7 +80,7 @@ static void nop_region(void *start, int len)
 {
        uint32_t *p;
 
-       for (p = start; (void *)p < (start + len); p++)
+       for (p = start; (char *)p < ((char *)start + len); p++)
                *p = cpu_to_fdt32(FDT_NOP);
 }
 
index f72e70dbe647ac3be205440ca37ea655b22a8a21..2ba30dbe540547b71a75b58fe8536796626577c7 100644 (file)
@@ -72,7 +72,7 @@ int _fdt_node_end_offset(void *fdt, int nodeoffset);
 
 static inline const void *_fdt_offset_ptr(const void *fdt, int offset)
 {
-       return fdt + fdt_off_dt_struct(fdt) + offset;
+       return (const char *)fdt + fdt_off_dt_struct(fdt) + offset;
 }
 
 static inline void *_fdt_offset_ptr_w(void *fdt, int offset)
@@ -82,8 +82,8 @@ static inline void *_fdt_offset_ptr_w(void *fdt, int offset)
 
 static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n)
 {
-       const struct fdt_reserve_entry *rsv_table =
-               fdt + fdt_off_mem_rsvmap(fdt);
+       const struct fdt_reserve_entry *rsv_table = (struct fdt_reserve_entry *)
+               ((const char *)fdt + fdt_off_mem_rsvmap(fdt));
 
        return rsv_table + n;
 }