mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-10-22 23:13:01 +02:00
of: Add a helper to free property struct
[ Upstream commit 1c5e3d9bf3
]
Freeing a property struct is 3 kfree()'s which is duplicated in multiple
spots. Add a helper, __of_prop_free(), and replace all the open coded
cases in the DT code.
Reviewed-by: Saravana Kannan <saravanak@google.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20240409-dt-cleanup-free-v2-1-5b419a4af38d@kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
Stable-dep-of: 80af3745ca46 ("of: dynamic: Fix use after free in of_changeset_add_prop_helper()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
d3be2b8cff
commit
749137b41e
|
@ -306,15 +306,20 @@ int of_detach_node(struct device_node *np)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(of_detach_node);
|
EXPORT_SYMBOL_GPL(of_detach_node);
|
||||||
|
|
||||||
|
void __of_prop_free(struct property *prop)
|
||||||
|
{
|
||||||
|
kfree(prop->name);
|
||||||
|
kfree(prop->value);
|
||||||
|
kfree(prop);
|
||||||
|
}
|
||||||
|
|
||||||
static void property_list_free(struct property *prop_list)
|
static void property_list_free(struct property *prop_list)
|
||||||
{
|
{
|
||||||
struct property *prop, *next;
|
struct property *prop, *next;
|
||||||
|
|
||||||
for (prop = prop_list; prop != NULL; prop = next) {
|
for (prop = prop_list; prop != NULL; prop = next) {
|
||||||
next = prop->next;
|
next = prop->next;
|
||||||
kfree(prop->name);
|
__of_prop_free(prop);
|
||||||
kfree(prop->value);
|
|
||||||
kfree(prop);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,9 +432,7 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags)
|
||||||
return new;
|
return new;
|
||||||
|
|
||||||
err_free:
|
err_free:
|
||||||
kfree(new->name);
|
__of_prop_free(new);
|
||||||
kfree(new->value);
|
|
||||||
kfree(new);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,9 +474,7 @@ struct device_node *__of_node_dup(const struct device_node *np,
|
||||||
if (!new_pp)
|
if (!new_pp)
|
||||||
goto err_prop;
|
goto err_prop;
|
||||||
if (__of_add_property(node, new_pp)) {
|
if (__of_add_property(node, new_pp)) {
|
||||||
kfree(new_pp->name);
|
__of_prop_free(new_pp);
|
||||||
kfree(new_pp->value);
|
|
||||||
kfree(new_pp);
|
|
||||||
goto err_prop;
|
goto err_prop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -933,11 +934,8 @@ static int of_changeset_add_prop_helper(struct of_changeset *ocs,
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = of_changeset_add_property(ocs, np, new_pp);
|
ret = of_changeset_add_property(ocs, np, new_pp);
|
||||||
if (ret) {
|
if (ret)
|
||||||
kfree(new_pp->name);
|
__of_prop_free(new_pp);
|
||||||
kfree(new_pp->value);
|
|
||||||
kfree(new_pp);
|
|
||||||
}
|
|
||||||
|
|
||||||
new_pp->next = np->deadprops;
|
new_pp->next = np->deadprops;
|
||||||
np->deadprops = new_pp;
|
np->deadprops = new_pp;
|
||||||
|
|
|
@ -123,6 +123,7 @@ extern void *__unflatten_device_tree(const void *blob,
|
||||||
* own the devtree lock or work on detached trees only.
|
* own the devtree lock or work on detached trees only.
|
||||||
*/
|
*/
|
||||||
struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags);
|
struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags);
|
||||||
|
void __of_prop_free(struct property *prop);
|
||||||
struct device_node *__of_node_dup(const struct device_node *np,
|
struct device_node *__of_node_dup(const struct device_node *np,
|
||||||
const char *full_name);
|
const char *full_name);
|
||||||
|
|
||||||
|
|
|
@ -262,9 +262,7 @@ static struct property *dup_and_fixup_symbol_prop(
|
||||||
return new_prop;
|
return new_prop;
|
||||||
|
|
||||||
err_free_new_prop:
|
err_free_new_prop:
|
||||||
kfree(new_prop->name);
|
__of_prop_free(new_prop);
|
||||||
kfree(new_prop->value);
|
|
||||||
kfree(new_prop);
|
|
||||||
err_free_target_path:
|
err_free_target_path:
|
||||||
kfree(target_path);
|
kfree(target_path);
|
||||||
|
|
||||||
|
@ -361,11 +359,8 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
|
||||||
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);
|
||||||
|
|
||||||
if (ret) {
|
if (ret)
|
||||||
kfree(new_prop->name);
|
__of_prop_free(new_prop);
|
||||||
kfree(new_prop->value);
|
|
||||||
kfree(new_prop);
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -800,15 +800,11 @@ static void __init of_unittest_property_copy(void)
|
||||||
|
|
||||||
new = __of_prop_dup(&p1, GFP_KERNEL);
|
new = __of_prop_dup(&p1, GFP_KERNEL);
|
||||||
unittest(new && propcmp(&p1, new), "empty property didn't copy correctly\n");
|
unittest(new && propcmp(&p1, new), "empty property didn't copy correctly\n");
|
||||||
kfree(new->value);
|
__of_prop_free(new);
|
||||||
kfree(new->name);
|
|
||||||
kfree(new);
|
|
||||||
|
|
||||||
new = __of_prop_dup(&p2, GFP_KERNEL);
|
new = __of_prop_dup(&p2, GFP_KERNEL);
|
||||||
unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
|
unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
|
||||||
kfree(new->value);
|
__of_prop_free(new);
|
||||||
kfree(new->name);
|
|
||||||
kfree(new);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3665,9 +3661,7 @@ static __init void of_unittest_overlay_high_level(void)
|
||||||
goto err_unlock;
|
goto err_unlock;
|
||||||
}
|
}
|
||||||
if (__of_add_property(of_symbols, new_prop)) {
|
if (__of_add_property(of_symbols, new_prop)) {
|
||||||
kfree(new_prop->name);
|
__of_prop_free(new_prop);
|
||||||
kfree(new_prop->value);
|
|
||||||
kfree(new_prop);
|
|
||||||
/* "name" auto-generated by unflatten */
|
/* "name" auto-generated by unflatten */
|
||||||
if (!strcmp(prop->name, "name"))
|
if (!strcmp(prop->name, "name"))
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user