Browse Source

dtc: Wrap phandle validity check

In several places we check for a returned phandle value to be valid,
for that it must not be 0 or "-1".

Wrap this check in a static inline function in dtc.h, and use ~0U instead
of -1 on the way, to keep everything in the unsigned realm.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Message-Id: <20210618172030.9684-4-andre.przywara@arm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
Andre Przywara 3 years ago committed by David Gibson
parent
commit
69bed6c241
  1. 10
      checks.c
  2. 5
      dtc.h
  3. 4
      livetree.c

10
checks.c

@ -520,7 +520,7 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,


phandle = propval_cell(prop); phandle = propval_cell(prop);


if ((phandle == 0) || (phandle == -1)) { if (!phandle_is_valid(phandle)) {
FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property", FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property",
phandle, prop->name); phandle, prop->name);
return 0; return 0;
@ -1400,14 +1400,14 @@ static void check_property_phandle_args(struct check *c,
for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) { for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) {
struct node *provider_node; struct node *provider_node;
struct property *cellprop; struct property *cellprop;
int phandle; cell_t phandle;


phandle = propval_cell_n(prop, cell); phandle = propval_cell_n(prop, cell);
/* /*
* Some bindings use a cell value 0 or -1 to skip over optional * Some bindings use a cell value 0 or -1 to skip over optional
* entries when each index position has a specific definition. * entries when each index position has a specific definition.
*/ */
if (phandle == 0 || phandle == -1) { if (!phandle_is_valid(phandle)) {
/* Give up if this is an overlay with external references */ /* Give up if this is an overlay with external references */
if (dti->dtsflags & DTSF_PLUGIN) if (dti->dtsflags & DTSF_PLUGIN)
break; break;
@ -1615,7 +1615,7 @@ static void check_interrupts_property(struct check *c,
prop = get_property(parent, "interrupt-parent"); prop = get_property(parent, "interrupt-parent");
if (prop) { if (prop) {
phandle = propval_cell(prop); phandle = propval_cell(prop);
if ((phandle == 0) || (phandle == -1)) { if (!phandle_is_valid(phandle)) {
/* Give up if this is an overlay with /* Give up if this is an overlay with
* external references */ * external references */
if (dti->dtsflags & DTSF_PLUGIN) if (dti->dtsflags & DTSF_PLUGIN)
@ -1772,7 +1772,7 @@ static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,


phandle = propval_cell(prop); phandle = propval_cell(prop);
/* Give up if this is an overlay with external references */ /* Give up if this is an overlay with external references */
if (phandle == 0 || phandle == -1) if (!phandle_is_valid(phandle))
return NULL; return NULL;


node = get_node_by_phandle(dti->dt, phandle); node = get_node_by_phandle(dti->dt, phandle);

5
dtc.h

@ -51,6 +51,11 @@ extern int annotate; /* annotate .dts with input source location */


typedef uint32_t cell_t; typedef uint32_t cell_t;


static inline bool phandle_is_valid(cell_t phandle)
{
return phandle != 0 && phandle != ~0U;
}

static inline uint16_t dtb_ld16(const void *p) static inline uint16_t dtb_ld16(const void *p)
{ {
const uint8_t *bp = (const uint8_t *)p; const uint8_t *bp = (const uint8_t *)p;

4
livetree.c

@ -559,7 +559,7 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
{ {
struct node *child, *node; struct node *child, *node;


if ((phandle == 0) || (phandle == -1)) { if (!phandle_is_valid(phandle)) {
assert(generate_fixups); assert(generate_fixups);
return NULL; return NULL;
} }
@ -594,7 +594,7 @@ cell_t get_node_phandle(struct node *root, struct node *node)
static cell_t phandle = 1; /* FIXME: ick, static local */ static cell_t phandle = 1; /* FIXME: ick, static local */
struct data d = empty_data; struct data d = empty_data;


if ((node->phandle != 0) && (node->phandle != -1)) if (phandle_is_valid(node->phandle))
return node->phandle; return node->phandle;


while (get_node_by_phandle(root, phandle)) while (get_node_by_phandle(root, phandle))

Loading…
Cancel
Save