libfdt: overlay: Skip phandles not in subnodes

A phandle property in an __overlay__ node has the potential to
break phandle linkage within the base fdt file to which it is
applied. Filter them out to avoid that situation.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
This commit is contained in:
Phil Elwell 2023-05-11 21:34:56 +01:00
parent 3b02a94b48
commit 73f7cc30c3

View file

@ -540,7 +540,8 @@ static int overlay_fixup_phandles(void *fdt, void *fdto)
* Negative error code on failure
*/
static int overlay_apply_node(void *fdt, int target,
void *fdto, int node)
void *fdto, int node,
int depth)
{
int property;
int subnode;
@ -557,6 +558,9 @@ static int overlay_apply_node(void *fdt, int target,
return -FDT_ERR_INTERNAL;
if (prop_len < 0)
return prop_len;
if ((depth == 0) && ((strcmp(name, "phandle") == 0) ||
(strcmp(name, "linux,phandle") == 0)))
continue;
ret = fdt_setprop(fdt, target, name, prop, prop_len);
if (ret)
@ -578,7 +582,7 @@ static int overlay_apply_node(void *fdt, int target,
if (nnode < 0)
return nnode;
ret = overlay_apply_node(fdt, nnode, fdto, subnode);
ret = overlay_apply_node(fdt, nnode, fdto, subnode, depth + 1);
if (ret)
return ret;
}
@ -625,7 +629,7 @@ static int overlay_merge(void *fdt, void *fdto)
if (target < 0)
return target;
ret = overlay_apply_node(fdt, target, fdto, overlay);
ret = overlay_apply_node(fdt, target, fdto, overlay, 0);
if (ret)
return ret;
}