Changeset 85d1769 in rtems for cpukit/dtc


Ignore:
Timestamp:
Oct 22, 2017, 5:32:15 AM (2 years ago)
Author:
David Gibson <david@…>
Branches:
master
Children:
c4267b1
Parents:
c13e400
git-author:
David Gibson <david@…> (10/22/17 05:32:15)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/19/18 05:01:11)
Message:

libfdt: Clean up header checking functions

Many of the libfdt entry points call some sort of sanity check function
before doing anything else. These need to do slightly different things for
the various classes of functions.

The read-only version is shared with the exported fdt_check_header(), which
limits us a bit in how we can improve it. For that reason split the two
functions apart (though the exported one just calls the ro one for now).

We also rename the functions for more consistency - they're all named
fdt_XX_probe_() where the XX indicates which class of functions they're
for. "probe" is a better "term" than the previous check, since they really
only do minimal validation.

Signed-off-by: David Gibson <david@…>
Tested-by: Alexey Kardashevskiy <aik@…>
Reviewed-by: Alexey Kardashevskiy <aik@…>

Location:
cpukit/dtc/libfdt
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/dtc/libfdt/fdt.c

    rc13e400 r85d1769  
    5656#include "libfdt_internal.h"
    5757
    58 int fdt_check_header(const void *fdt)
     58/*
     59 * Minimal sanity check for a read-only tree. fdt_ro_probe_() checks
     60 * that the given buffer contains what appears to be a flattened
     61 * device tree with sane information in its header.
     62 */
     63int fdt_ro_probe_(const void *fdt)
    5964{
    6065        if (fdt_magic(fdt) == FDT_MAGIC) {
     
    7580}
    7681
     82int fdt_check_header(const void *fdt)
     83{
     84        return fdt_ro_probe_(fdt);
     85}
     86
    7787const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
    7888{
     
    245255int fdt_move(const void *fdt, void *buf, int bufsize)
    246256{
    247         FDT_CHECK_HEADER(fdt);
     257        FDT_RO_PROBE(fdt);
    248258
    249259        if (fdt_totalsize(fdt) > bufsize)
  • cpukit/dtc/libfdt/fdt_ro.c

    rc13e400 r85d1769  
    118118int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
    119119{
    120         FDT_CHECK_HEADER(fdt);
     120        FDT_RO_PROBE(fdt);
    121121        *address = fdt64_to_cpu(fdt_mem_rsv_(fdt, n)->address);
    122122        *size = fdt64_to_cpu(fdt_mem_rsv_(fdt, n)->size);
     
    162162        int depth;
    163163
    164         FDT_CHECK_HEADER(fdt);
     164        FDT_RO_PROBE(fdt);
    165165
    166166        for (depth = 0;
     
    188188        int offset = 0;
    189189
    190         FDT_CHECK_HEADER(fdt);
     190        FDT_RO_PROBE(fdt);
    191191
    192192        /* see if we have an alias */
     
    238238        int err;
    239239
    240         if (((err = fdt_check_header(fdt)) != 0)
     240        if (((err = fdt_ro_probe_(fdt)) != 0)
    241241            || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0))
    242242                        goto fail;
     
    463463        const char *name;
    464464
    465         FDT_CHECK_HEADER(fdt);
     465        FDT_RO_PROBE(fdt);
    466466
    467467        if (buflen < 2)
     
    515515        int supernodeoffset = -FDT_ERR_INTERNAL;
    516516
    517         FDT_CHECK_HEADER(fdt);
     517        FDT_RO_PROBE(fdt);
    518518
    519519        if (supernodedepth < 0)
     
    574574        int len;
    575575
    576         FDT_CHECK_HEADER(fdt);
     576        FDT_RO_PROBE(fdt);
    577577
    578578        /* FIXME: The algorithm here is pretty horrible: we scan each
     
    600600                return -FDT_ERR_BADPHANDLE;
    601601
    602         FDT_CHECK_HEADER(fdt);
     602        FDT_RO_PROBE(fdt);
    603603
    604604        /* FIXME: The algorithm here is pretty horrible: we
     
    753753        int offset, err;
    754754
    755         FDT_CHECK_HEADER(fdt);
     755        FDT_RO_PROBE(fdt);
    756756
    757757        /* FIXME: The algorithm here is pretty horrible: we scan each
  • cpukit/dtc/libfdt/fdt_rw.c

    rc13e400 r85d1769  
    6868}
    6969
    70 static int fdt_rw_check_header_(void *fdt)
    71 {
    72         FDT_CHECK_HEADER(fdt);
     70static int fdt_rw_probe_(void *fdt)
     71{
     72        FDT_RO_PROBE(fdt);
    7373
    7474        if (fdt_version(fdt) < 17)
     
    8383}
    8484
    85 #define FDT_RW_CHECK_HEADER(fdt) \
     85#define FDT_RW_PROBE(fdt) \
    8686        { \
    8787                int err_; \
    88                 if ((err_ = fdt_rw_check_header_(fdt)) != 0) \
     88                if ((err_ = fdt_rw_probe_(fdt)) != 0) \
    8989                        return err_; \
    9090        }
     
    177177        int err;
    178178
    179         FDT_RW_CHECK_HEADER(fdt);
     179        FDT_RW_PROBE(fdt);
    180180
    181181        re = fdt_mem_rsv_w_(fdt, fdt_num_mem_rsv(fdt));
     
    193193        struct fdt_reserve_entry *re = fdt_mem_rsv_w_(fdt, n);
    194194
    195         FDT_RW_CHECK_HEADER(fdt);
     195        FDT_RW_PROBE(fdt);
    196196
    197197        if (n >= fdt_num_mem_rsv(fdt))
     
    253253        int err;
    254254
    255         FDT_RW_CHECK_HEADER(fdt);
     255        FDT_RW_PROBE(fdt);
    256256
    257257        namep = (char *)(uintptr_t)fdt_get_name(fdt, nodeoffset, &oldlen);
     
    276276        int err;
    277277
    278         FDT_RW_CHECK_HEADER(fdt);
     278        FDT_RW_PROBE(fdt);
    279279
    280280        err = fdt_resize_property_(fdt, nodeoffset, name, len, &prop);
     
    309309        int err, oldlen, newlen;
    310310
    311         FDT_RW_CHECK_HEADER(fdt);
     311        FDT_RW_PROBE(fdt);
    312312
    313313        prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
     
    335335        int len, proplen;
    336336
    337         FDT_RW_CHECK_HEADER(fdt);
     337        FDT_RW_PROBE(fdt);
    338338
    339339        prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
     
    355355        fdt32_t *endtag;
    356356
    357         FDT_RW_CHECK_HEADER(fdt);
     357        FDT_RW_PROBE(fdt);
    358358
    359359        offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);
     
    395395        int endoffset;
    396396
    397         FDT_RW_CHECK_HEADER(fdt);
     397        FDT_RW_PROBE(fdt);
    398398
    399399        endoffset = fdt_node_end_offset_(fdt, nodeoffset);
     
    436436        char *tmp;
    437437
    438         FDT_CHECK_HEADER(fdt);
     438        FDT_RO_PROBE(fdt);
    439439
    440440        mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
     
    495495        int mem_rsv_size;
    496496
    497         FDT_RW_CHECK_HEADER(fdt);
     497        FDT_RW_PROBE(fdt);
    498498
    499499        mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
  • cpukit/dtc/libfdt/fdt_sw.c

    rc13e400 r85d1769  
    5656#include "libfdt_internal.h"
    5757
    58 static int fdt_sw_check_header_(void *fdt)
     58static int fdt_sw_probe_(void *fdt)
    5959{
    6060        if (fdt_magic(fdt) != FDT_SW_MAGIC)
     
    6464}
    6565
    66 #define FDT_SW_CHECK_HEADER(fdt) \
     66#define FDT_SW_PROBE(fdt) \
    6767        { \
    6868                int err; \
    69                 if ((err = fdt_sw_check_header_(fdt)) != 0) \
     69                if ((err = fdt_sw_probe_(fdt)) != 0) \
    7070                        return err; \
    7171        }
     
    113113        char *oldtail, *newtail;
    114114
    115         FDT_SW_CHECK_HEADER(fdt);
     115        FDT_SW_PROBE(fdt);
    116116
    117117        headsize = fdt_off_dt_struct(fdt);
     
    145145        int offset;
    146146
    147         FDT_SW_CHECK_HEADER(fdt);
     147        FDT_SW_PROBE(fdt);
    148148
    149149        if (fdt_size_dt_struct(fdt))
     
    173173        int namelen = strlen(name) + 1;
    174174
    175         FDT_SW_CHECK_HEADER(fdt);
     175        FDT_SW_PROBE(fdt);
    176176
    177177        nh = fdt_grab_space_(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen));
     
    188188        fdt32_t *en;
    189189
    190         FDT_SW_CHECK_HEADER(fdt);
     190        FDT_SW_PROBE(fdt);
    191191
    192192        en = fdt_grab_space_(fdt, FDT_TAGSIZE);
     
    226226        int nameoff;
    227227
    228         FDT_SW_CHECK_HEADER(fdt);
     228        FDT_SW_PROBE(fdt);
    229229
    230230        nameoff = fdt_find_add_string_(fdt, name);
     
    263263        int offset, nextoffset;
    264264
    265         FDT_SW_CHECK_HEADER(fdt);
     265        FDT_SW_PROBE(fdt);
    266266
    267267        /* Add terminator */
  • cpukit/dtc/libfdt/libfdt_internal.h

    rc13e400 r85d1769  
    5656#define FDT_TAGALIGN(x)         (FDT_ALIGN((x), FDT_TAGSIZE))
    5757
    58 #define FDT_CHECK_HEADER(fdt) \
     58int fdt_ro_probe_(const void *fdt);
     59#define FDT_RO_PROBE(fdt)                       \
    5960        { \
    6061                int err_; \
    61                 if ((err_ = fdt_check_header(fdt)) != 0) \
     62                if ((err_ = fdt_ro_probe_(fdt)) != 0)   \
    6263                        return err_; \
    6364        }
Note: See TracChangeset for help on using the changeset viewer.