Skip to content

Commit 10a5a83

Browse files
Dan Carpentergregkh
authored andcommitted
of: dynamic: Fix use after free in of_changeset_add_prop_helper()
[ Upstream commit 80af374 ] If the of_changeset_add_property() function call fails, then this code frees "new_pp" and then dereference it on the next line. Return the error code directly instead. Fixes: c81f6ce ("of: dynamic: Fix memleak when of_pci_add_properties() failed") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/aKgljjhnpa4lVpdx@stanley.mountain Signed-off-by: Rob Herring (Arm) <robh@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent da621fd commit 10a5a83

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/of/dynamic.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,13 +935,15 @@ static int of_changeset_add_prop_helper(struct of_changeset *ocs,
935935
return -ENOMEM;
936936

937937
ret = of_changeset_add_property(ocs, np, new_pp);
938-
if (ret)
938+
if (ret) {
939939
__of_prop_free(new_pp);
940+
return ret;
941+
}
940942

941943
new_pp->next = np->deadprops;
942944
np->deadprops = new_pp;
943945

944-
return ret;
946+
return 0;
945947
}
946948

947949
/**

0 commit comments

Comments
 (0)