dtc: Enable and fix -Wpointer-arith warnings

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.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2008-07-07 10:10:48 +10:00 committed by Jon Loeliger
parent 76e0622b68
commit 36786db615
13 changed files with 52 additions and 47 deletions

View file

@ -16,7 +16,7 @@ LOCAL_VERSION =
CONFIG_LOCALVERSION = CONFIG_LOCALVERSION =
CPPFLAGS = -I libfdt CPPFLAGS = -I libfdt
CFLAGS = -Wall -g -Os CFLAGS = -Wall -g -Os -Wpointer-arith
BISON = bison BISON = bison
LEX = flex LEX = flex

View file

@ -70,9 +70,9 @@ static void dump_blob(void *blob)
uint32_t off_dt = fdt32_to_cpu(bph->off_dt_struct); uint32_t off_dt = fdt32_to_cpu(bph->off_dt_struct);
uint32_t off_str = fdt32_to_cpu(bph->off_dt_strings); uint32_t off_str = fdt32_to_cpu(bph->off_dt_strings);
struct fdt_reserve_entry *p_rsvmap = struct fdt_reserve_entry *p_rsvmap =
(struct fdt_reserve_entry *)(blob + off_mem_rsvmap); (struct fdt_reserve_entry *)((char *)blob + off_mem_rsvmap);
char *p_struct = blob + off_dt; char *p_struct = (char *)blob + off_dt;
char *p_strings = blob + off_str; char *p_strings = (char *)blob + off_str;
uint32_t version = fdt32_to_cpu(bph->version); uint32_t version = fdt32_to_cpu(bph->version);
uint32_t totalsize = fdt32_to_cpu(bph->totalsize); uint32_t totalsize = fdt32_to_cpu(bph->totalsize);
uint32_t tag; uint32_t tag;

View file

@ -76,7 +76,7 @@ int fdt_check_header(const void *fdt)
const void *fdt_offset_ptr(const void *fdt, int offset, int len) const void *fdt_offset_ptr(const void *fdt, int offset, int len)
{ {
const void *p; const char *p;
if (fdt_version(fdt) >= 0x11) if (fdt_version(fdt) >= 0x11)
if (((offset + len) < offset) if (((offset + len) < offset)

View file

@ -408,10 +408,10 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
&phandle, sizeof(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); int len = strlen(str);
const void *p; const char *p;
while (listlen >= len) { while (listlen >= len) {
if (memcmp(str, strlist, len+1) == 0) if (memcmp(str, strlist, len+1) == 0)

View file

@ -94,13 +94,14 @@ static inline int _blob_data_size(void *fdt)
return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(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)) if (((p + oldlen) < p) || ((p + oldlen) > end))
return -FDT_ERR_BADOFFSET; 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; return -FDT_ERR_NOSPACE;
memmove(p + newlen, p + oldlen, end - p - oldlen); memmove(p + newlen, p + oldlen, end - p - oldlen);
return 0; return 0;
@ -135,7 +136,8 @@ static int _blob_splice_struct(void *fdt, void *p,
static int _blob_splice_string(void *fdt, int newlen) 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; int err;
if ((err = _blob_splice(fdt, p, 0, newlen))) if ((err = _blob_splice(fdt, p, 0, newlen)))
@ -338,7 +340,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE);
memset(nh->name, 0, ALIGN(namelen+1, FDT_TAGSIZE)); memset(nh->name, 0, ALIGN(namelen+1, FDT_TAGSIZE));
memcpy(nh->name, name, namelen); 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); *endtag = cpu_to_fdt32(FDT_END_NODE);
return offset; return offset;
@ -363,7 +365,7 @@ int fdt_del_node(void *fdt, int nodeoffset)
endoffset - nodeoffset, 0); 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_size, int struct_size)
{ {
int mem_rsv_off, struct_off, strings_off; int mem_rsv_off, struct_off, strings_off;
@ -372,17 +374,17 @@ static void _packblocks(const void *fdt, void *buf,
struct_off = mem_rsv_off + mem_rsv_size; struct_off = mem_rsv_off + mem_rsv_size;
strings_off = struct_off + struct_size; strings_off = struct_off + struct_size;
memmove(buf + mem_rsv_off, fdt + fdt_off_mem_rsvmap(fdt), mem_rsv_size); memmove(new + mem_rsv_off, old + fdt_off_mem_rsvmap(old), mem_rsv_size);
fdt_set_off_mem_rsvmap(buf, mem_rsv_off); fdt_set_off_mem_rsvmap(new, mem_rsv_off);
memmove(buf + struct_off, fdt + fdt_off_dt_struct(fdt), struct_size); memmove(new + struct_off, old + fdt_off_dt_struct(old), struct_size);
fdt_set_off_dt_struct(buf, struct_off); fdt_set_off_dt_struct(new, struct_off);
fdt_set_size_dt_struct(buf, struct_size); fdt_set_size_dt_struct(new, struct_size);
memmove(buf + strings_off, fdt + fdt_off_dt_strings(fdt), memmove(new + strings_off, old + fdt_off_dt_strings(old),
fdt_size_dt_strings(fdt)); fdt_size_dt_strings(old));
fdt_set_off_dt_strings(buf, strings_off); fdt_set_off_dt_strings(new, strings_off);
fdt_set_size_dt_strings(buf, fdt_size_dt_strings(fdt)); fdt_set_size_dt_strings(new, fdt_size_dt_strings(old));
} }
int fdt_open_into(const void *fdt, void *buf, int bufsize) int fdt_open_into(const void *fdt, void *buf, int bufsize)
@ -390,7 +392,9 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
int err; int err;
int mem_rsv_size, struct_size; int mem_rsv_size, struct_size;
int newsize; int newsize;
void *tmp; const char *fdtstart = fdt;
const char *fdtend = fdtstart + fdt_totalsize(fdt);
char *tmp;
CHECK_HEADER(fdt); CHECK_HEADER(fdt);
@ -423,12 +427,13 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
if (bufsize < newsize) if (bufsize < newsize)
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
if (((buf + newsize) <= fdt) /* First attempt to build converted tree at beginning of buffer */
|| (buf >= (fdt + fdt_totalsize(fdt)))) { tmp = buf;
tmp = buf; /* But if that overlaps with the old tree... */
} else { if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) {
tmp = (void *)fdt + fdt_totalsize(fdt); /* Try right after the old tree instead */
if ((tmp + newsize) > (buf + bufsize)) tmp = (char *)fdtend;
if ((tmp + newsize) > ((char *)buf + bufsize))
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
} }

View 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)) if ((offset + sizeof(*re)) > fdt_totalsize(fdt))
return -FDT_ERR_NOSPACE; 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->address = cpu_to_fdt64(addr);
re->size = cpu_to_fdt64(size); re->size = cpu_to_fdt64(size);

View file

@ -76,7 +76,7 @@ static void nop_region(void *start, int len)
{ {
uint32_t *p; 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); *p = cpu_to_fdt32(FDT_NOP);
} }

View 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) 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) 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) static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n)
{ {
const struct fdt_reserve_entry *rsv_table = const struct fdt_reserve_entry *rsv_table = (struct fdt_reserve_entry *)
fdt + fdt_off_mem_rsvmap(fdt); ((const char *)fdt + fdt_off_mem_rsvmap(fdt));
return rsv_table + n; return rsv_table + n;
} }

View file

@ -31,10 +31,10 @@
#define CHUNKSIZE 1024 #define CHUNKSIZE 1024
void *load_file(const char *name, int *len) char *load_file(const char *name, int *len)
{ {
FILE *f; FILE *f;
void *buf = NULL; char *buf = NULL;
int bufsize = 0, n; int bufsize = 0, n;
*len = 0; *len = 0;
@ -60,7 +60,8 @@ void *load_file(const char *name, int *len)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
void *fdt, *incbin; void *fdt;
char *incbin;
int len; int len;
test_init(argc, argv); test_init(argc, argv);

View file

@ -31,7 +31,7 @@
#include "testdata.h" #include "testdata.h"
struct bufstate { struct bufstate {
void *buf; char *buf;
int size; int size;
}; };
@ -73,7 +73,7 @@ void add_block(struct bufstate *buf, int version, char block, const void *fdt)
case 'm': case 'm':
/* Memory reserve map */ /* Memory reserve map */
align = 8; align = 8;
src = fdt + fdt_off_mem_rsvmap(fdt); src = (const char *)fdt + fdt_off_mem_rsvmap(fdt);
size = (fdt_num_mem_rsv(fdt) + 1) size = (fdt_num_mem_rsv(fdt) + 1)
* sizeof(struct fdt_reserve_entry); * sizeof(struct fdt_reserve_entry);
break; break;
@ -81,14 +81,14 @@ void add_block(struct bufstate *buf, int version, char block, const void *fdt)
case 't': case 't':
/* Structure block */ /* Structure block */
align = 4; align = 4;
src = fdt + fdt_off_dt_struct(fdt); src = (const char *)fdt + fdt_off_dt_struct(fdt);
size = fdt_size_dt_struct(fdt); size = fdt_size_dt_struct(fdt);
break; break;
case 's': case 's':
/* Strings block */ /* Strings block */
align = 1; align = 1;
src = fdt + fdt_off_dt_strings(fdt); src = (const char *)fdt + fdt_off_dt_strings(fdt);
size = fdt_size_dt_strings(fdt); size = fdt_size_dt_strings(fdt);
break; break;
default: default:

View file

@ -33,7 +33,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
void *fdt, *fdt1, *fdt2, *fdt3; void *fdt, *fdt1, *fdt2, *fdt3;
void *buf; char *buf;
int shuntsize; int shuntsize;
int bufsize; int bufsize;
int err; int err;

View file

@ -30,7 +30,7 @@
#include "tests.h" #include "tests.h"
#include "testdata.h" #include "testdata.h"
int nopulate_struct(char *buf, const void *fdt) int nopulate_struct(char *buf, const char *fdt)
{ {
int offset, nextoffset = 0; int offset, nextoffset = 0;
uint32_t tag; uint32_t tag;
@ -42,7 +42,7 @@ int nopulate_struct(char *buf, const void *fdt)
offset = nextoffset; offset = nextoffset;
tag = fdt_next_tag(fdt, offset, &nextoffset); tag = fdt_next_tag(fdt, offset, &nextoffset);
memcpy(p, fdt + fdt_off_dt_struct(fdt) + offset, memcpy(p, (const char *)fdt + fdt_off_dt_struct(fdt) + offset,
nextoffset - offset); nextoffset - offset);
p += nextoffset - offset; p += nextoffset - offset;
@ -56,8 +56,7 @@ int nopulate_struct(char *buf, const void *fdt)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
void *fdt, *fdt2; char *fdt, *fdt2, *buf;
void *buf;
int newsize, struct_start, struct_end_old, struct_end_new, delta; int newsize, struct_start, struct_end_old, struct_end_new, delta;
const char *inname; const char *inname;
char outname[PATH_MAX]; char outname[PATH_MAX];

View file

@ -200,7 +200,7 @@ void save_blob(const char *filename, void *fdt)
int fd; int fd;
int totalsize; int totalsize;
int offset; int offset;
void *p; char *p;
int ret; int ret;
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);