diff options
author | Frank Rowand <frank.rowand@sony.com> | 2022-05-02 13:17:42 -0500 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2022-05-03 11:53:15 -0500 |
commit | 421f4d14bc037f708a3d11fbb01274b741767bf9 (patch) | |
tree | 0dcc545c1d08ae4eed261f9f25a0a6c8b0ff5d08 /drivers/of/unittest.c | |
parent | 992b0dc5c38a4e79dca17577960c5201275b83f1 (diff) | |
download | lwn-421f4d14bc037f708a3d11fbb01274b741767bf9.tar.gz lwn-421f4d14bc037f708a3d11fbb01274b741767bf9.zip |
of: overlay: do not free changeset when of_overlay_apply returns error
New unittests for overlay notifiers reveal a memory leak in
of_overlay_apply() when a notifier returns an error for action
OF_OVERLAY_POST_APPLY. The pr_err() message is:
OF: ERROR: memory leak, expected refcount 1 instead of 3,
of_node_get()/of_node_put() unbalanced - destroy cset entry: attach
overlay node /testcase-data/overlay-node/test-bus/test-unittest17
Change the error path to no longer call free_overlay_changeset(),
and document that the caller of of_overlay_fdt_apply() may choose
to remove the overlay.
Update the unittest that triggered the error to expect the changed
return values and to call of_overlay_remove().
Signed-off-by: Frank Rowand <frank.rowand@sony.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20220502181742.1402826-4-frowand.list@gmail.com
Diffstat (limited to 'drivers/of/unittest.c')
-rw-r--r-- | drivers/of/unittest.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 6747e8eb7c56..7f6bba18c515 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -2845,7 +2845,7 @@ static void __init of_unittest_overlay_notify(void) EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset pre-apply notifier error -16, target: /testcase-data/overlay-node/test-bus"); - unittest(!ovcs_id, "ovcs_id created for overlay_16\n"); + unittest(ovcs_id, "ovcs_id not created for overlay_16\n"); /* --- overlay 17 --- */ @@ -2856,7 +2856,13 @@ static void __init of_unittest_overlay_notify(void) EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset post-apply notifier error -17, target: /testcase-data/overlay-node/test-bus"); - unittest(!ovcs_id, "ovcs_id created for overlay_17\n"); + unittest(ovcs_id, "ovcs_id not created for overlay_17\n"); + + if (ovcs_id) { + ret = of_overlay_remove(&ovcs_id); + unittest(!ret, + "overlay_17 of_overlay_remove(), ret = %d\n", ret); + } /* --- overlay 18 --- */ |