Changeset ec2de39 in rtems for cpukit/dtc


Ignore:
Timestamp:
Jul 19, 2018, 6:19:43 AM (10 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
1554a8c5
Parents:
513daa3
git-author:
Sebastian Huber <sebastian.huber@…> (07/19/18 06:19:43)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/20/18 06:52:36)
Message:

libfdt: fdt_address_cells() and fdt_size_cells()

Add internal fdt_cells() to avoid copy and paste. Test error cases and
default values. Fix typo in fdt_size_cells() documentation comment.

Signed-off-by: Sebastian Huber <sebastian.huber@…>
Signed-off-by: David Gibson <david@…>

File:
1 edited

Legend:

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

    r513daa3 rec2de39  
    22 * libfdt - Flat Device Tree manipulation
    33 * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
     4 * Copyright (C) 2018 embedded brains GmbH
    45 *
    56 * libfdt is dual licensed: you can use it either under the terms of
     
    5657#include "libfdt_internal.h"
    5758
    58 int fdt_address_cells(const void *fdt, int nodeoffset)
     59static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
    5960{
    60         const fdt32_t *ac;
     61        const fdt32_t *c;
    6162        int val;
    6263        int len;
    6364
    64         ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len);
    65         if (!ac)
     65        c = fdt_getprop(fdt, nodeoffset, name, &len);
     66        if (!c)
    6667                return 2;
    6768
    68         if (len != sizeof(*ac))
     69        if (len != sizeof(*c))
    6970                return -FDT_ERR_BADNCELLS;
    7071
    71         val = fdt32_to_cpu(*ac);
     72        val = fdt32_to_cpu(*c);
    7273        if ((val <= 0) || (val > FDT_MAX_NCELLS))
    7374                return -FDT_ERR_BADNCELLS;
     
    7677}
    7778
     79int fdt_address_cells(const void *fdt, int nodeoffset)
     80{
     81        return fdt_cells(fdt, nodeoffset, "#address-cells");
     82}
     83
    7884int fdt_size_cells(const void *fdt, int nodeoffset)
    7985{
    80         const fdt32_t *sc;
    81         int val;
    82         int len;
    83 
    84         sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len);
    85         if (!sc)
    86                 return 2;
    87 
    88         if (len != sizeof(*sc))
    89                 return -FDT_ERR_BADNCELLS;
    90 
    91         val = fdt32_to_cpu(*sc);
    92         if ((val < 0) || (val > FDT_MAX_NCELLS))
    93                 return -FDT_ERR_BADNCELLS;
    94 
    95         return val;
     86        return fdt_cells(fdt, nodeoffset, "#size-cells");
    9687}
Note: See TracChangeset for help on using the changeset viewer.