Simplify string table access functions

The range sanity checking on the fdt_string_cmp() function causes problems
for the sequential write code (or at least for using RO functions on an
incomplete SW tree).  Plus they didn't really fit with the philosphy for
the RO code of working as widely as possible on weirdly constructed trees.
main
David Gibson 2006-11-29 16:34:30 +11:00
parent 156649d4f6
commit 3aa4cfd66b
3 changed files with 8 additions and 24 deletions

20
fdt.c
View File

@ -34,26 +34,6 @@ void *fdt_offset_ptr(const struct fdt_header *fdt, int offset, int len)
return p;
}

char *fdt_string(const struct fdt_header *fdt, int stroffset)
{
return (char *)fdt + fdt32_to_cpu(fdt->off_dt_strings) + stroffset;
}

int fdt_string_cmp(const struct fdt_header *fdt, int stroffset, const char *s2)
{
const char *s1 = fdt_string(fdt, stroffset);
int len = strlen(s2) + 1;

if (! s1)
return 0;

if ((stroffset + len < stroffset)
|| (stroffset + len > fdt32_to_cpu(fdt->size_dt_strings)))
return -2;

return strcmp(s1, s2);
}

uint32_t _fdt_next_tag(const struct fdt_header *fdt, int offset, int *nextoffset)
{
const uint32_t *tagp, *lenp;

View File

@ -59,6 +59,11 @@ static int offset_streq(const struct fdt_header *fdt, int offset,
return 1;
}

char *fdt_string(const struct fdt_header *fdt, int stroffset)
{
return (char *)fdt + fdt32_to_cpu(fdt->off_dt_strings) + stroffset;
}

int fdt_property_offset(const struct fdt_header *fdt, int nodeoffset,
const char *name)
{
@ -103,7 +108,7 @@ int fdt_property_offset(const struct fdt_header *fdt, int nodeoffset,
if (! prop)
return OFFSET_ERROR(FDT_ERR_BADSTRUCTURE);
namestroff = fdt32_to_cpu(prop->nameoff);
if (fdt_string_cmp(fdt, namestroff, name) == 0)
if (streq(fdt_string(fdt, namestroff), name))
/* Found it! */
return offset;
break;

View File

@ -54,10 +54,9 @@ void *fdt_offset_ptr(const struct fdt_header *fdt, int offset, int checklen);
#define fdt_ptr_error(ptr) \
( (((long)(ptr) < 0) && ((long)(ptr) >= -FDT_ERR_MAX)) ? -(long)(ptr) : 0 )

char *fdt_string(const struct fdt_header *fdt, int stroffset);
int fdt_string_cmp(const struct fdt_header *fdt, int stroffset, const char *s2);

/* Read-only functions */
char *fdt_string(const struct fdt_header *fdt, int stroffset);

int fdt_property_offset(const struct fdt_header *fdt, int nodeoffset,
const char *name);
int fdt_subnode_offset_namelen(const struct fdt_header *fdt, int parentoffset,