libfdt: Zero the padding after a property value

fdt_setprop() and fdt_appendprop() size the value to FDT_TAGALIGN(len)
but copy only len bytes, so the padding keeps stale data: the old
value's tail when a property shrinks, or bytes of the following tags
when space is inserted.  The devicetree specification requires the
padding to be zeroed, so clear it.

Signed-off-by: Tharaka Jayasena <9dmpires2k17.tuj@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
Tharaka Jayasena 2026-11-16 19:02:30 +05:30 committed by David Gibson
parent a8702d54c8
commit ce51dcbd84
1 changed files with 3 additions and 0 deletions

View File

@ -288,6 +288,7 @@ int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name,
if (err)
return err;

memset(prop->data + len, 0, FDT_TAGALIGN(len) - len);
*prop_data = prop->data;
return 0;
}
@ -340,12 +341,14 @@ int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
return err;
prop->len = cpu_to_fdt32(newlen);
memcpy(prop->data + oldlen, val, len);
memset(prop->data + newlen, 0, FDT_TAGALIGN(newlen) - newlen);
} else {
err = fdt_add_property_(fdt, nodeoffset, name, strlen(name),
len, &prop);
if (err)
return err;
memcpy(prop->data, val, len);
memset(prop->data + len, 0, FDT_TAGALIGN(len) - len);
}
return 0;
}