From 3aa4cfd66bf75b67a2ddaed8454d0483762e69ba Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 29 Nov 2006 16:34:30 +1100 Subject: [PATCH] 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. --- fdt.c | 20 -------------------- fdt_ro.c | 7 ++++++- libfdt.h | 5 ++--- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/fdt.c b/fdt.c index 0de7f68..03f1a0d 100644 --- a/fdt.c +++ b/fdt.c @@ -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; diff --git a/fdt_ro.c b/fdt_ro.c index c2a0e72..bfd8163 100644 --- a/fdt_ro.c +++ b/fdt_ro.c @@ -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; diff --git a/libfdt.h b/libfdt.h index 7f279a6..605aa89 100644 --- a/libfdt.h +++ b/libfdt.h @@ -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,