Skip to content

Commit 7a20f91

Browse files
Dan Carpenteropsiff
authored andcommitted
of: dynamic: Fix use after free in of_changeset_add_prop_helper()
[ Upstream commit 80af3745ca465c6c47e833c1902004a7fa944f37 ] 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: c81f6ce16785 ("of: dynamic: Fix memleak when of_pci_add_properties() failed") Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 9e0743eb6dcfd2e7e998d1b3182344a3221c32ee)
1 parent 4d4d23e commit 7a20f91

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
@@ -934,13 +934,15 @@ static int of_changeset_add_prop_helper(struct of_changeset *ocs,
934934
return -ENOMEM;
935935

936936
ret = of_changeset_add_property(ocs, np, new_pp);
937-
if (ret)
937+
if (ret) {
938938
__of_prop_free(new_pp);
939+
return ret;
940+
}
939941

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

943-
return ret;
945+
return 0;
944946
}
945947

946948
/**

0 commit comments

Comments
 (0)