of: overlay: add_changeset_property() memory leak
No changeset entries are created for #address-cells and #size-cells
properties, but the duplicated properties are never freed. This
results in a memory leak which is detected by kmemleak:
unreferenced object 0x85887180 (size 64):
backtrace:
kmem_cache_alloc_trace+0x1fb/0x1fc
__of_prop_dup+0x25/0x7c
add_changeset_property+0x17f/0x370
build_changeset_next_level+0x29/0x20c
of_overlay_fdt_apply+0x32b/0x6b4
...
Fixes: 6f75118800
("of: overlay: validate overlay properties #address-cells and #size-cells")
Reported-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Signed-off-by: Frank Rowand <frank.rowand@sony.com>
Tested-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Signed-off-by: Rob Herring <robh@kernel.org>
This commit is contained in:
Родитель
cf7d88fb86
Коммит
637392a850
|
@ -305,7 +305,6 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
|
||||||
{
|
{
|
||||||
struct property *new_prop = NULL, *prop;
|
struct property *new_prop = NULL, *prop;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
bool check_for_non_overlay_node = false;
|
|
||||||
|
|
||||||
if (target->in_livetree)
|
if (target->in_livetree)
|
||||||
if (!of_prop_cmp(overlay_prop->name, "name") ||
|
if (!of_prop_cmp(overlay_prop->name, "name") ||
|
||||||
|
@ -318,6 +317,25 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
|
||||||
else
|
else
|
||||||
prop = NULL;
|
prop = NULL;
|
||||||
|
|
||||||
|
if (prop) {
|
||||||
|
if (!of_prop_cmp(prop->name, "#address-cells")) {
|
||||||
|
if (!of_prop_val_eq(prop, overlay_prop)) {
|
||||||
|
pr_err("ERROR: changing value of #address-cells is not allowed in %pOF\n",
|
||||||
|
target->np);
|
||||||
|
ret = -EINVAL;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
} else if (!of_prop_cmp(prop->name, "#size-cells")) {
|
||||||
|
if (!of_prop_val_eq(prop, overlay_prop)) {
|
||||||
|
pr_err("ERROR: changing value of #size-cells is not allowed in %pOF\n",
|
||||||
|
target->np);
|
||||||
|
ret = -EINVAL;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (is_symbols_prop) {
|
if (is_symbols_prop) {
|
||||||
if (prop)
|
if (prop)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -330,33 +348,18 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (!prop) {
|
if (!prop) {
|
||||||
check_for_non_overlay_node = true;
|
|
||||||
if (!target->in_livetree) {
|
if (!target->in_livetree) {
|
||||||
new_prop->next = target->np->deadprops;
|
new_prop->next = target->np->deadprops;
|
||||||
target->np->deadprops = new_prop;
|
target->np->deadprops = new_prop;
|
||||||
}
|
}
|
||||||
ret = of_changeset_add_property(&ovcs->cset, target->np,
|
ret = of_changeset_add_property(&ovcs->cset, target->np,
|
||||||
new_prop);
|
new_prop);
|
||||||
} else if (!of_prop_cmp(prop->name, "#address-cells")) {
|
|
||||||
if (!of_prop_val_eq(prop, new_prop)) {
|
|
||||||
pr_err("ERROR: changing value of #address-cells is not allowed in %pOF\n",
|
|
||||||
target->np);
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
} else if (!of_prop_cmp(prop->name, "#size-cells")) {
|
|
||||||
if (!of_prop_val_eq(prop, new_prop)) {
|
|
||||||
pr_err("ERROR: changing value of #size-cells is not allowed in %pOF\n",
|
|
||||||
target->np);
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
check_for_non_overlay_node = true;
|
|
||||||
ret = of_changeset_update_property(&ovcs->cset, target->np,
|
ret = of_changeset_update_property(&ovcs->cset, target->np,
|
||||||
new_prop);
|
new_prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_for_non_overlay_node &&
|
if (!of_node_check_flag(target->np, OF_OVERLAY))
|
||||||
!of_node_check_flag(target->np, OF_OVERLAY))
|
|
||||||
pr_err("WARNING: memory leak will occur if overlay removed, property: %pOF/%s\n",
|
pr_err("WARNING: memory leak will occur if overlay removed, property: %pOF/%s\n",
|
||||||
target->np, new_prop->name);
|
target->np, new_prop->name);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче