Browse Source

Fix assorted sparse warnings

This fixes a great many sparse warnings on the fdt and libfdt sources.
These are mostly due to incorrect mixing of endian annotated and native
integer types.

This includes fixing a couple of quasi-bugs where we had endian conversions
the wrong way around (this will have the right effect in practice, but is
certainly conceptually incorrect).

This doesn't make the whole tree sparse clean: there are many warnings in
bison and lex generated code, and there are a handful of other remaining
warnings that are (for now) more trouble than they're worth to fix (and
are not genuine bugs).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
David Gibson 8 years ago
parent
commit
bad5b28049
  1. 4
      checks.c
  2. 2
      convert-dtsv0-lexer.l
  3. 6
      data.c
  4. 5
      dtc.c
  5. 2
      fdtdump.c
  6. 2
      fdtget.c
  7. 2
      fdtput.c
  8. 23
      flattree.c
  9. 21
      libfdt/fdt_overlay.c
  10. 4
      livetree.c
  11. 2
      tests/char_literal.c
  12. 2
      tests/dtbs_equal_ordered.c
  13. 10
      tests/dtbs_equal_unordered.c
  14. 2
      tests/dumptrees.c
  15. 4
      tests/integer-expressions.c
  16. 2
      tests/node_offset_by_prop_value.c
  17. 2
      tests/nopulate.c
  18. 4
      tests/property_iterate.c
  19. 4
      tests/references.c
  20. 6
      tests/sized_cells.c
  21. 4
      tests/subnode_iterate.c
  22. 6
      tests/tests.h
  23. 6
      tests/value-labels.c
  24. 2
      treesource.c
  25. 9
      util.c

4
checks.c

@ -534,13 +534,13 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti, @@ -534,13 +534,13 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
FAIL(c, dti, "Reference to non-existent node or "
"label \"%s\"\n", m->ref);
else /* mark the entry as unresolved */
*((cell_t *)(prop->val.val + m->offset)) =
*((fdt32_t *)(prop->val.val + m->offset)) =
cpu_to_fdt32(0xffffffff);
continue;
}

phandle = get_node_phandle(dt, refnode);
*((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
*((fdt32_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
}
}
}

2
convert-dtsv0-lexer.l

@ -49,7 +49,7 @@ static int saw_hyphen; /* = 0 */ @@ -49,7 +49,7 @@ static int saw_hyphen; /* = 0 */
static unsigned long long last_val;
static char *last_name; /* = NULL */

const struct {
static const struct {
const char *pattern;
int obase, width;
} guess_table[] = {

6
data.c

@ -171,9 +171,9 @@ struct data data_merge(struct data d1, struct data d2) @@ -171,9 +171,9 @@ struct data data_merge(struct data d1, struct data d2)
struct data data_append_integer(struct data d, uint64_t value, int bits)
{
uint8_t value_8;
uint16_t value_16;
uint32_t value_32;
uint64_t value_64;
fdt16_t value_16;
fdt32_t value_32;
fdt64_t value_64;

switch (bits) {
case 8:

5
dtc.c

@ -138,7 +138,7 @@ static const char *guess_type_by_name(const char *fname, const char *fallback) @@ -138,7 +138,7 @@ static const char *guess_type_by_name(const char *fname, const char *fallback)
static const char *guess_input_format(const char *fname, const char *fallback)
{
struct stat statbuf;
uint32_t magic;
fdt32_t magic;
FILE *f;

if (stat(fname, &statbuf) != 0)
@ -159,8 +159,7 @@ static const char *guess_input_format(const char *fname, const char *fallback) @@ -159,8 +159,7 @@ static const char *guess_input_format(const char *fname, const char *fallback)
}
fclose(f);

magic = fdt32_to_cpu(magic);
if (magic == FDT_MAGIC)
if (fdt32_to_cpu(magic) == FDT_MAGIC)
return "dtb";

return guess_type_by_name(fname, fallback);

2
fdtdump.c

@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@

#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
#define PALIGN(p, a) ((void *)(ALIGN((unsigned long)(p), (a))))
#define GET_CELL(p) (p += 4, *((const uint32_t *)(p-4)))
#define GET_CELL(p) (p += 4, *((const fdt32_t *)(p-4)))

static const char *tagname(uint32_t tag)
{

2
fdtget.c

@ -105,7 +105,7 @@ static int show_data(struct display_info *disp, const char *data, int len) @@ -105,7 +105,7 @@ static int show_data(struct display_info *disp, const char *data, int len)
for (i = 0; i < len; i += size, p += size) {
if (i)
printf(" ");
value = size == 4 ? fdt32_to_cpu(*(const uint32_t *)p) :
value = size == 4 ? fdt32_to_cpu(*(const fdt32_t *)p) :
size == 2 ? (*p << 8) | p[1] : *p;
printf(fmt, value);
}

2
fdtput.c

@ -107,7 +107,7 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count, @@ -107,7 +107,7 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count,
if (disp->verbose)
fprintf(stderr, "\tstring: '%s'\n", ptr);
} else {
int *iptr = (int *)ptr;
fdt32_t *iptr = (fdt32_t *)ptr;
sscanf(*arg, fmt, &ival);
if (len == 4)
*iptr = cpu_to_fdt32(ival);

23
flattree.c

@ -179,7 +179,7 @@ static void asm_emit_data(void *e, struct data d) @@ -179,7 +179,7 @@ static void asm_emit_data(void *e, struct data d)
emit_offset_label(f, m->ref, m->offset);

while ((d.len - off) >= sizeof(uint32_t)) {
asm_emit_cell(e, fdt32_to_cpu(*((uint32_t *)(d.val+off))));
asm_emit_cell(e, fdt32_to_cpu(*((fdt32_t *)(d.val+off))));
off += sizeof(uint32_t);
}

@ -608,7 +608,7 @@ static void flat_read_chunk(struct inbuf *inb, void *p, int len) @@ -608,7 +608,7 @@ static void flat_read_chunk(struct inbuf *inb, void *p, int len)

static uint32_t flat_read_word(struct inbuf *inb)
{
uint32_t val;
fdt32_t val;

assert(((inb->ptr - inb->base) % sizeof(val)) == 0);

@ -717,13 +717,15 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb) @@ -717,13 +717,15 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
* First pass, count entries.
*/
while (1) {
uint64_t address, size;

flat_read_chunk(inb, &re, sizeof(re));
re.address = fdt64_to_cpu(re.address);
re.size = fdt64_to_cpu(re.size);
if (re.size == 0)
address = fdt64_to_cpu(re.address);
size = fdt64_to_cpu(re.size);
if (size == 0)
break;

new = build_reserve_entry(re.address, re.size);
new = build_reserve_entry(address, size);
reservelist = add_reserve_entry(reservelist, new);
}

@ -816,6 +818,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, @@ -816,6 +818,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
struct dt_info *dt_from_blob(const char *fname)
{
FILE *f;
fdt32_t magic_buf, totalsize_buf;
uint32_t magic, totalsize, version, size_dt, boot_cpuid_phys;
uint32_t off_dt, off_str, off_mem_rsvmap;
int rc;
@ -832,7 +835,7 @@ struct dt_info *dt_from_blob(const char *fname) @@ -832,7 +835,7 @@ struct dt_info *dt_from_blob(const char *fname)

f = srcfile_relative_open(fname, NULL);

rc = fread(&magic, sizeof(magic), 1, f);
rc = fread(&magic_buf, sizeof(magic_buf), 1, f);
if (ferror(f))
die("Error reading DT blob magic number: %s\n",
strerror(errno));
@ -843,11 +846,11 @@ struct dt_info *dt_from_blob(const char *fname) @@ -843,11 +846,11 @@ struct dt_info *dt_from_blob(const char *fname)
die("Mysterious short read reading magic number\n");
}

magic = fdt32_to_cpu(magic);
magic = fdt32_to_cpu(magic_buf);
if (magic != FDT_MAGIC)
die("Blob has incorrect magic number\n");

rc = fread(&totalsize, sizeof(totalsize), 1, f);
rc = fread(&totalsize_buf, sizeof(totalsize_buf), 1, f);
if (ferror(f))
die("Error reading DT blob size: %s\n", strerror(errno));
if (rc < 1) {
@ -857,7 +860,7 @@ struct dt_info *dt_from_blob(const char *fname) @@ -857,7 +860,7 @@ struct dt_info *dt_from_blob(const char *fname)
die("Mysterious short read reading blob size\n");
}

totalsize = fdt32_to_cpu(totalsize);
totalsize = fdt32_to_cpu(totalsize_buf);
if (totalsize < FDT_V1_SIZE)
die("DT blob size (%d) is too small\n", totalsize);


21
libfdt/fdt_overlay.c

@ -21,14 +21,14 @@ @@ -21,14 +21,14 @@
*/
static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)
{
const uint32_t *val;
const fdt32_t *val;
int len;

val = fdt_getprop(fdto, fragment, "target", &len);
if (!val)
return 0;

if ((len != sizeof(*val)) || (*val == (uint32_t)-1))
if ((len != sizeof(*val)) || (fdt32_to_cpu(*val) == (uint32_t)-1))
return (uint32_t)-1;

return fdt32_to_cpu(*val);
@ -99,7 +99,7 @@ static int overlay_get_target(const void *fdt, const void *fdto, @@ -99,7 +99,7 @@ static int overlay_get_target(const void *fdt, const void *fdto,
static int overlay_phandle_add_offset(void *fdt, int node,
const char *name, uint32_t delta)
{
const uint32_t *val;
const fdt32_t *val;
uint32_t adj_val;
int len;

@ -210,7 +210,7 @@ static int overlay_update_local_node_references(void *fdto, @@ -210,7 +210,7 @@ static int overlay_update_local_node_references(void *fdto,
int ret;

fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) {
const uint32_t *fixup_val;
const fdt32_t *fixup_val;
const char *tree_val;
const char *name;
int fixup_len;
@ -234,7 +234,8 @@ static int overlay_update_local_node_references(void *fdto, @@ -234,7 +234,8 @@ static int overlay_update_local_node_references(void *fdto,
}

for (i = 0; i < (fixup_len / sizeof(uint32_t)); i++) {
uint32_t adj_val, poffset;
fdt32_t adj_val;
uint32_t poffset;

poffset = fdt32_to_cpu(fixup_val[i]);

@ -246,9 +247,7 @@ static int overlay_update_local_node_references(void *fdto, @@ -246,9 +247,7 @@ static int overlay_update_local_node_references(void *fdto,
*/
memcpy(&adj_val, tree_val + poffset, sizeof(adj_val));

adj_val = fdt32_to_cpu(adj_val);
adj_val += delta;
adj_val = cpu_to_fdt32(adj_val);
adj_val = cpu_to_fdt32(fdt32_to_cpu(adj_val) + delta);

ret = fdt_setprop_inplace_namelen_partial(fdto,
tree_node,
@ -356,6 +355,7 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto, @@ -356,6 +355,7 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto,
{
const char *symbol_path;
uint32_t phandle;
fdt32_t phandle_prop;
int symbol_off, fixup_off;
int prop_len;

@ -381,10 +381,11 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto, @@ -381,10 +381,11 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto,
if (fixup_off < 0)
return fixup_off;

phandle = cpu_to_fdt32(phandle);
phandle_prop = cpu_to_fdt32(phandle);
return fdt_setprop_inplace_namelen_partial(fdto, fixup_off,
name, name_len, poffset,
&phandle, sizeof(phandle));
&phandle_prop,
sizeof(phandle_prop));
};

/**

4
livetree.c

@ -393,7 +393,7 @@ struct property *get_property(struct node *node, const char *propname) @@ -393,7 +393,7 @@ struct property *get_property(struct node *node, const char *propname)
cell_t propval_cell(struct property *prop)
{
assert(prop->val.len == sizeof(cell_t));
return fdt32_to_cpu(*((cell_t *)prop->val.val));
return fdt32_to_cpu(*((fdt32_t *)prop->val.val));
}

struct property *get_property_by_label(struct node *tree, const char *label,
@ -902,7 +902,7 @@ static void add_local_fixup_entry(struct dt_info *dti, @@ -902,7 +902,7 @@ static void add_local_fixup_entry(struct dt_info *dti,
struct node *refnode)
{
struct node *wn, *nwn; /* local fixup node, walk node, new */
uint32_t value_32;
fdt32_t value_32;
char **compp;
int i, depth;


2
tests/char_literal.c

@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
int main(int argc, char *argv[])
{
void *fdt;
uint32_t expected_cells[5];
fdt32_t expected_cells[5];

expected_cells[0] = cpu_to_fdt32((unsigned char)TEST_CHAR1);
expected_cells[1] = cpu_to_fdt32((unsigned char)TEST_CHAR2);

2
tests/dtbs_equal_ordered.c

@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
#include "tests.h"
#include "testdata.h"

int notequal; /* = 0 */
static int notequal; /* = 0 */

#define MISMATCH(fmt, ...) \
do { \

10
tests/dtbs_equal_unordered.c

@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
#include "tests.h"
#include "testdata.h"

int notequal; /* = 0 */
static int notequal; /* = 0 */

#define MISMATCH(fmt, ...) \
do { \
@ -59,14 +59,14 @@ static int mem_rsv_cmp(const void *p1, const void *p2) @@ -59,14 +59,14 @@ static int mem_rsv_cmp(const void *p1, const void *p2)
const struct fdt_reserve_entry *re1 = p1;
const struct fdt_reserve_entry *re2 = p2;

if (re1->address < re2->address)
if (fdt64_to_cpu(re1->address) < fdt64_to_cpu(re2->address))
return -1;
else if (re1->address > re2->address)
else if (fdt64_to_cpu(re1->address) > fdt64_to_cpu(re2->address))
return 1;

if (re1->size < re2->size)
if (fdt64_to_cpu(re1->size) < fdt64_to_cpu(re2->size))
return -1;
else if (re1->size > re2->size)
else if (fdt64_to_cpu(re1->size) > fdt64_to_cpu(re2->size))
return 1;

return 0;

2
tests/dumptrees.c

@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@

#include "testdata.h"

struct {
static struct {
void *blob;
const char *filename;
} trees[] = {

4
tests/integer-expressions.c

@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
#include "tests.h"
#include "testdata.h"

struct test_expr {
static struct test_expr {
const char *expr;
uint32_t result;
} expr_table[] = {
@ -70,7 +70,7 @@ struct test_expr { @@ -70,7 +70,7 @@ struct test_expr {
int main(int argc, char *argv[])
{
void *fdt;
const uint32_t *res;
const fdt32_t *res;
int reslen;
int i;


2
tests/node_offset_by_prop_value.c

@ -69,7 +69,7 @@ static void check_search_str(void *fdt, const char *propname, @@ -69,7 +69,7 @@ static void check_search_str(void *fdt, const char *propname,

#define check_search_cell(fdt, propname, propval, ...) \
{ \
uint32_t val = cpu_to_fdt32(propval); \
fdt32_t val = cpu_to_fdt32(propval); \
check_search((fdt), (propname), &val, sizeof(val), \
##__VA_ARGS__); \
}

2
tests/nopulate.c

@ -45,7 +45,7 @@ static int nopulate_struct(char *buf, const char *fdt) @@ -45,7 +45,7 @@ static int nopulate_struct(char *buf, const char *fdt)
nextoffset - offset);
p += nextoffset - offset;

*((uint32_t *)p) = cpu_to_fdt32(FDT_NOP);
*((fdt32_t *)p) = cpu_to_fdt32(FDT_NOP);
p += FDT_TAGSIZE;

} while (tag != FDT_END);

4
tests/property_iterate.c

@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@

static void test_node(void *fdt, int parent_offset)
{
fdt32_t properties;
uint32_t properties;
const fdt32_t *prop;
int offset, property;
int count;
@ -48,7 +48,7 @@ static void test_node(void *fdt, int parent_offset) @@ -48,7 +48,7 @@ static void test_node(void *fdt, int parent_offset)
FAIL("Missing/invalid test-properties property at '%s'",
fdt_get_name(fdt, parent_offset, NULL));
}
properties = cpu_to_fdt32(*prop);
properties = fdt32_to_cpu(*prop);

count = 0;
offset = fdt_first_subnode(fdt, parent_offset);

4
tests/references.c

@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@

static void check_ref(const void *fdt, int node, uint32_t checkref)
{
const uint32_t *p;
const fdt32_t *p;
uint32_t ref;
int len;

@ -58,7 +58,7 @@ static void check_ref(const void *fdt, int node, uint32_t checkref) @@ -58,7 +58,7 @@ static void check_ref(const void *fdt, int node, uint32_t checkref)

static void check_rref(const void *fdt)
{
const uint32_t *p;
const fdt32_t *p;
uint32_t ref;
int len;


6
tests/sized_cells.c

@ -54,9 +54,9 @@ int main(int argc, char *argv[]) @@ -54,9 +54,9 @@ int main(int argc, char *argv[])
TEST_CHAR4,
TEST_CHAR5,
TEST_VALUE_1 >> 24};
uint16_t expected_16[6];
uint32_t expected_32[6];
uint64_t expected_64[6];
fdt16_t expected_16[6];
fdt32_t expected_32[6];
fdt64_t expected_64[6];
int i;

for (i = 0; i < 5; ++i) {

4
tests/subnode_iterate.c

@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@

static void test_node(void *fdt, int parent_offset)
{
fdt32_t subnodes;
uint32_t subnodes;
const fdt32_t *prop;
int offset;
int count;
@ -45,7 +45,7 @@ static void test_node(void *fdt, int parent_offset) @@ -45,7 +45,7 @@ static void test_node(void *fdt, int parent_offset)
FAIL("Missing/invalid subnodes property at '%s'",
fdt_get_name(fdt, parent_offset, NULL));
}
subnodes = cpu_to_fdt32(*prop);
subnodes = fdt32_to_cpu(*prop);

count = 0;
fdt_for_each_subnode(offset, fdt, parent_offset)

6
tests/tests.h

@ -99,7 +99,7 @@ void check_property(void *fdt, int nodeoffset, const char *name, @@ -99,7 +99,7 @@ void check_property(void *fdt, int nodeoffset, const char *name,
int len, const void *val);
#define check_property_cell(fdt, nodeoffset, name, val) \
({ \
uint32_t x = cpu_to_fdt32(val); \
fdt32_t x = cpu_to_fdt32(val); \
check_property(fdt, nodeoffset, name, sizeof(x), &x); \
})

@ -108,12 +108,12 @@ const void *check_getprop(void *fdt, int nodeoffset, const char *name, @@ -108,12 +108,12 @@ const void *check_getprop(void *fdt, int nodeoffset, const char *name,
int len, const void *val);
#define check_getprop_cell(fdt, nodeoffset, name, val) \
({ \
uint32_t x = cpu_to_fdt32(val); \
fdt32_t x = cpu_to_fdt32(val); \
check_getprop(fdt, nodeoffset, name, sizeof(x), &x); \
})
#define check_getprop_64(fdt, nodeoffset, name, val) \
({ \
uint64_t x = cpu_to_fdt64(val); \
fdt64_t x = cpu_to_fdt64(val); \
check_getprop(fdt, nodeoffset, name, sizeof(x), &x); \
})
#define check_getprop_string(fdt, nodeoffset, name, s) \

6
tests/value-labels.c

@ -36,13 +36,13 @@ struct val_label { @@ -36,13 +36,13 @@ struct val_label {
int propoff;
};

struct val_label labels1[] = {
static struct val_label labels1[] = {
{ "start1", 0 },
{ "mid1", 2 },
{ "end1", -1 },
};

struct val_label labels2[] = {
static struct val_label labels2[] = {
{ "start2", 0 },
{ "innerstart2", 0 },
{ "innermid2", 4 },
@ -50,7 +50,7 @@ struct val_label labels2[] = { @@ -50,7 +50,7 @@ struct val_label labels2[] = {
{ "end2", -1 },
};

struct val_label labels3[] = {
static struct val_label labels3[] = {
{ "start3", 0 },
{ "innerstart3", 0 },
{ "innermid3", 1 },

2
treesource.c

@ -137,7 +137,7 @@ static void write_propval_string(FILE *f, struct data val) @@ -137,7 +137,7 @@ static void write_propval_string(FILE *f, struct data val)
static void write_propval_cells(FILE *f, struct data val)
{
void *propend = val.val + val.len;
cell_t *cp = (cell_t *)val.val;
fdt32_t *cp = (fdt32_t *)val.val;
struct marker *m = val.markers;

fprintf(f, "<");

9
util.c

@ -396,7 +396,7 @@ void utilfdt_print_data(const char *data, int len) @@ -396,7 +396,7 @@ void utilfdt_print_data(const char *data, int len)
} while (s < data + len);

} else if ((len % 4) == 0) {
const uint32_t *cell = (const uint32_t *)data;
const fdt32_t *cell = (const fdt32_t *)data;

printf(" = <");
for (i = 0, len /= 4; i < len; i++)
@ -412,14 +412,15 @@ void utilfdt_print_data(const char *data, int len) @@ -412,14 +412,15 @@ void utilfdt_print_data(const char *data, int len)
}
}

void util_version(void)
void NORETURN util_version(void)
{
printf("Version: %s\n", DTC_VERSION);
exit(0);
}

void util_usage(const char *errmsg, const char *synopsis,
const char *short_opts, struct option const long_opts[],
void NORETURN util_usage(const char *errmsg, const char *synopsis,
const char *short_opts,
struct option const long_opts[],
const char * const opts_help[])
{
FILE *fp = errmsg ? stderr : stdout;

Loading…
Cancel
Save